本文整理汇总了Golang中github.com/sarifsystems/sarif/sarif.Message.Reply方法的典型用法代码示例。如果您正苦于以下问题:Golang Message.Reply方法的具体用法?Golang Message.Reply怎么用?Golang Message.Reply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/sarifsystems/sarif/sarif.Message
的用法示例。
在下文中一共展示了Message.Reply方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handleUnknownUserMessage
func (cv *Conversation) handleUnknownUserMessage(msg sarif.Message) {
pl := &MsgErrNatural{
Original: msg.Text,
}
cv.SendToClient(msg.Reply(sarif.CreateMessage("err/natural", pl)))
}
示例2: HandleClientMessage
func (cv *Conversation) HandleClientMessage(msg sarif.Message) {
if msg.Text == ".full" || msg.Text == "/full" {
text, err := json.MarshalIndent(cv.LastMessage, "", " ")
if err != nil {
panic(err)
}
cv.service.Reply(msg, sarif.Message{
Action: "natural/full",
Text: string(text),
})
return
}
// Check if client answers a conversation.
if time.Now().Sub(cv.LastTime) < 5*time.Minute {
if cv.LastMessageAction.IsAction() {
parsed, ok := cv.answer(cv.LastMessageAction.Action, msg.Text)
cv.LastTime = time.Time{}
parsed.Destination = cv.LastMessage.Source
if ok {
cv.PublishForClient(parsed)
}
return
}
}
// Otherwise parse message as normal request.
ctx := &natural.Context{
Text: msg.Text,
Sender: "user",
Recipient: "sarif",
}
res, err := cv.service.Parse(ctx)
if err != nil || len(res.Intents) == 0 {
cv.handleUnknownUserMessage(msg)
return
}
pred := res.Intents[0]
if pred.Type == "exclamatory" {
cv.SendToClient(msg.Reply(sarif.Message{
Action: "natural/phrase",
Text: cv.service.phrases.Answer(msg.Text),
}))
return
}
if pred.Message.Text == "" && pred.Type != "simple" {
pred.Message.Text = msg.Text
}
cv.LastUserTime = time.Now()
cv.LastUserText = msg.Text
cv.LastUserMessage = pred.Message
pred.Message.CorrId = msg.Id
cv.PublishForClient(pred.Message)
}
示例3: handleGeofenceCreate
func (s *Service) handleGeofenceCreate(msg sarif.Message) {
var g Geofence
if err := msg.DecodePayload(&g); err != nil {
s.ReplyBadRequest(msg, err)
return
}
if g.Address != "" {
geo, err := Geocode(g.Address)
if err != nil {
s.ReplyBadRequest(msg, err)
return
}
if len(geo) == 0 {
s.Publish(msg.Reply(MsgAddressNotFound))
return
}
g.BoundingBox = BoundingBox(geo[0].BoundingBox)
}
if g.Name == "" {
g.Name = sarif.GenerateId()
}
g.GeohashMin = EncodeGeohash(g.BoundingBox.LatMin, g.BoundingBox.LngMin, 12)
g.GeohashMax = EncodeGeohash(g.BoundingBox.LatMax, g.BoundingBox.LngMax, 12)
if _, err := s.Store.Put(g.Key(), &g); err != nil {
s.ReplyInternalError(msg, err)
}
reply := sarif.Message{Action: "location/fence/created"}
if err := reply.EncodePayload(g); err != nil {
s.ReplyInternalError(msg, err)
return
}
reply.Text = "Geofence '" + g.Name + "' created."
s.Publish(reply)
}