1
0
mirror of synced 2024-11-22 21:06:06 +03:00
messenger/message.go

99 lines
3.1 KiB
Go
Raw Normal View History

2016-04-13 09:14:23 +03:00
package messenger
2019-03-25 21:48:35 +03:00
import (
"encoding/json"
"time"
)
2016-04-13 09:14:23 +03:00
// Message represents a Facebook messenger message.
2016-04-13 09:14:23 +03:00
type Message struct {
// Sender is who the message was sent from.
Sender Sender `json:"-"`
// Recipient is who the message was sent to.
Recipient Recipient `json:"-"`
// Time is when the message was sent.
Time time.Time `json:"-"`
// Message is mine
IsEcho bool `json:"is_echo,omitempty"`
// Mid is the ID of the message.
Mid string `json:"mid"`
// Seq is order the message was sent in relation to other messages.
Seq int `json:"seq"`
2019-01-02 22:12:22 +03:00
// StickerID is the ID of the sticker user sent.
StickerID int `json:"sticker_id"`
// Text is the textual contents of the message.
Text string `json:"text"`
// Attachments is the information about the attachments which were sent
// with the message.
Attachments []Attachment `json:"attachments"`
// Selected quick reply
QuickReply *QuickReply `json:"quick_reply,omitempty"`
2019-03-25 21:48:35 +03:00
// Entities for NLP
// https://developers.facebook.com/docs/messenger-platform/built-in-nlp/
NLP json.RawMessage `json:"nlp"`
2016-04-13 12:12:23 +03:00
}
// Delivery represents a the event fired when Facebook delivers a message to the
// recipient.
2016-04-13 12:12:23 +03:00
type Delivery struct {
// Mids are the IDs of the messages which were read.
Mids []string `json:"mids"`
// RawWatermark is the timestamp of when the delivery was.
RawWatermark int64 `json:"watermark"`
// Seq is the sequence the message was sent in.
Seq int `json:"seq"`
}
// Read represents a the event fired when a message is read by the
// recipient.
type Read struct {
// RawWatermark is the timestamp before which all messages have been read
// by the user
RawWatermark int64 `json:"watermark"`
// Seq is the sequence the message was sent in.
Seq int `json:"seq"`
2016-04-13 12:36:38 +03:00
}
// PostBack represents postback callback
type PostBack struct {
2016-05-04 11:09:34 +03:00
// Sender is who the message was sent from.
Sender Sender `json:"-"`
// Recipient is who the message was sent to.
Recipient Recipient `json:"-"`
// Time is when the message was sent.
Time time.Time `json:"-"`
2016-05-04 11:09:34 +03:00
// PostBack ID
Payload string `json:"payload"`
// Optional referral info
Referral Referral `json:"referral"`
}
2018-03-10 12:12:35 +03:00
type AccountLinking struct {
// Sender is who the message was sent from.
Sender Sender `json:"-"`
// Recipient is who the message was sent to.
Recipient Recipient `json:"-"`
// Time is when the message was sent.
Time time.Time `json:"-"`
// Status represents the new account linking status.
Status string `json:"status"`
// AuthorizationCode is a pass-through code set during the linking process.
AuthorizationCode string `json:"authorization_code"`
}
// Watermark is the RawWatermark timestamp rendered as a time.Time.
2016-04-13 12:36:38 +03:00
func (d Delivery) Watermark() time.Time {
return time.Unix(d.RawWatermark/int64(time.Microsecond), 0)
2016-04-13 09:14:23 +03:00
}
// Watermark is the RawWatermark timestamp rendered as a time.Time.
func (r Read) Watermark() time.Time {
return time.Unix(r.RawWatermark/int64(time.Microsecond), 0)
}
2019-03-25 21:48:35 +03:00
// GetNLP simply unmarshals the NLP entities to the given struct and returns
// an error if it's not possible
func (m *Message) GetNLP(i interface{}) error {
return json.Unmarshal(m.NLP, &i)
}