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
|
|
|
|
2018-12-30 15:37:18 +03:00
|
|
|
// Message represents a Facebook messenger message.
|
2016-04-13 09:14:23 +03:00
|
|
|
type Message struct {
|
2016-04-14 02:53:55 +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-09-08 10:55:48 +03:00
|
|
|
// Message is mine
|
|
|
|
IsEcho bool `json:"is_echo,omitempty"`
|
2016-04-14 02:53:55 +03:00
|
|
|
// Mid is the ID of the message.
|
2021-02-09 11:14:42 +03:00
|
|
|
Metadata string `json:"metadata"`
|
|
|
|
// Mid is the ID of the message.
|
2016-04-14 02:53:55 +03:00
|
|
|
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"`
|
2016-04-14 02:53:55 +03:00
|
|
|
// 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.
|
2016-04-13 12:46:52 +03:00
|
|
|
Attachments []Attachment `json:"attachments"`
|
2016-09-08 10:55:48 +03:00
|
|
|
// 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"`
|
2021-06-03 21:22:18 +03:00
|
|
|
// Read Instagram message data to which this reply was sent to.
|
|
|
|
Read *IGMessageRead `json:"read,omitempty"`
|
|
|
|
// Reaction represents reaction to Instagram message.
|
|
|
|
Reaction *IGMessageReaction `json:"reaction,omitempty"`
|
|
|
|
// Referral with Instagram product data.
|
|
|
|
Referral *IGMessageReferral `json:"referral,omitempty"`
|
|
|
|
// IsUnsupported is being sent if Instagram message is not supported.
|
|
|
|
IsUnsupported bool `json:"is_unsupported,omitempty"`
|
|
|
|
// IsDeleted is being sent if message was deleted.
|
|
|
|
IsDeleted bool `json:"is_deleted,omitempty"`
|
|
|
|
// ReplyTo the Instagram story or to the message.
|
|
|
|
ReplyTo *IGReplyTo `json:"reply_to"`
|
2016-04-13 12:12:23 +03:00
|
|
|
}
|
|
|
|
|
2016-08-18 02:41:25 +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 {
|
2016-04-14 02:53:55 +03:00
|
|
|
// Mids are the IDs of the messages which were read.
|
|
|
|
Mids []string `json:"mids"`
|
2016-08-18 02:41:25 +03:00
|
|
|
// 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"`
|
|
|
|
}
|
|
|
|
|
2016-10-07 16:28:27 +03:00
|
|
|
// Read represents a the event fired when a message is read by the
|
2016-08-18 02:41:25 +03:00
|
|
|
// recipient.
|
|
|
|
type Read struct {
|
|
|
|
// RawWatermark is the timestamp before which all messages have been read
|
|
|
|
// by the user
|
2016-04-14 02:53:55 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-06-03 21:22:18 +03:00
|
|
|
// IGMessageRead represents data with the read message ID. Present in the Instagram webhook.
|
|
|
|
type IGMessageRead struct {
|
|
|
|
// Mid is a message ID.
|
|
|
|
Mid string `json:"mid"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// IGMessageReaction represents reaction to the Instagram message.
|
|
|
|
type IGMessageReaction struct {
|
|
|
|
// Mid is a message ID.
|
|
|
|
Mid string `json:"mid"`
|
|
|
|
// Action can be {react|unreact}
|
|
|
|
Action string `json:"action"`
|
|
|
|
// Reaction is a reaction name. Optional.
|
|
|
|
Reaction string `json:"reaction,omitempty"`
|
|
|
|
// Emoji is optional.
|
|
|
|
Emoji string `json:"emoji,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// IGMessageProduct represents Instagram product.
|
|
|
|
type IGMessageProduct struct {
|
|
|
|
// ID of the product.
|
|
|
|
ID string `json:"id,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// IGMessageReferral represents Instagram message referral with product ID.
|
|
|
|
type IGMessageReferral struct {
|
|
|
|
// Product data.
|
|
|
|
Product IGMessageProduct `json:"product,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// IGPostback represents Instagram postback webhook data.
|
|
|
|
type IGPostback struct {
|
|
|
|
// Selected icebreaker question or title for the CTA (Generic Template)
|
|
|
|
Title string `json:"title,omitempty"`
|
|
|
|
// Payload is user defined payload.
|
|
|
|
Payload string `json:"payload"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// IGReplyTo represents data of the thing to what reply has been sent.
|
|
|
|
type IGReplyTo struct {
|
|
|
|
// Mid is a message ID to which reply was sent.
|
|
|
|
Mid string `json:"mid"`
|
|
|
|
// Story data.
|
|
|
|
Story *IGReplyToStory `json:"story,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// IGReplyToStory is a story data to which reply has been sent.
|
|
|
|
type IGReplyToStory struct {
|
|
|
|
// URL of the story.
|
|
|
|
URL string `json:"url,omitempty"`
|
|
|
|
// ID of the story.
|
|
|
|
ID string `json:"id,omitempty"`
|
|
|
|
}
|
|
|
|
|
2021-02-17 15:15:29 +03:00
|
|
|
// PostBack represents postback callback.
|
2016-05-03 16:42:25 +03:00
|
|
|
type PostBack struct {
|
2016-05-04 11:09:34 +03:00
|
|
|
// Sender is who the message was sent from.
|
2016-05-03 16:42:25 +03:00
|
|
|
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:"-"`
|
2021-11-02 15:11:36 +03:00
|
|
|
// PostBack Payload
|
|
|
|
Payload PostBackPayload `json:"payload"`
|
2017-02-17 05:29:12 +03:00
|
|
|
// Optional referral info
|
|
|
|
Referral Referral `json:"referral"`
|
2016-05-03 16:42:25 +03:00
|
|
|
}
|
|
|
|
|
2021-11-02 15:11:36 +03:00
|
|
|
// PostBackPayload represents payload data in PostBack
|
|
|
|
type PostBackPayload struct {
|
|
|
|
Title string `json:"title"`
|
|
|
|
Payload string `json:"payload"`
|
|
|
|
Mid string `json:"mid"`
|
|
|
|
}
|
|
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
2016-04-14 02:53:55 +03:00
|
|
|
// Watermark is the RawWatermark timestamp rendered as a time.Time.
|
2016-04-13 12:36:38 +03:00
|
|
|
func (d Delivery) Watermark() time.Time {
|
2016-10-04 04:44:18 +03:00
|
|
|
return time.Unix(d.RawWatermark/int64(time.Microsecond), 0)
|
2016-04-13 09:14:23 +03:00
|
|
|
}
|
2016-08-18 02:41:25 +03:00
|
|
|
|
|
|
|
// Watermark is the RawWatermark timestamp rendered as a time.Time.
|
|
|
|
func (r Read) Watermark() time.Time {
|
2016-10-04 04:44:18 +03:00
|
|
|
return time.Unix(r.RawWatermark/int64(time.Microsecond), 0)
|
2016-08-18 02:41:25 +03:00
|
|
|
}
|
2019-03-25 21:48:35 +03:00
|
|
|
|
|
|
|
// GetNLP simply unmarshals the NLP entities to the given struct and returns
|
2021-02-17 15:15:29 +03:00
|
|
|
// an error if it's not possible.
|
2019-03-25 21:48:35 +03:00
|
|
|
func (m *Message) GetNLP(i interface{}) error {
|
|
|
|
return json.Unmarshal(m.NLP, &i)
|
|
|
|
}
|