-
Notifications
You must be signed in to change notification settings - Fork 27
/
events.go
122 lines (107 loc) · 4.45 KB
/
events.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package messenger
import "net/http"
type upstreamEvent struct {
Object string `json:"object"`
Entries []*MessageEvent `json:"entry"`
}
// Event represents a Webhook postback event.
// https://developers.facebook.com/docs/messenger-platform/webhook-reference#format
type Event struct {
ID string `json:"id"`
Time int64 `json:"time"`
Request *http.Request `json:"-"`
}
// MessageOpts contains information common to all message events.
// https://developers.facebook.com/docs/messenger-platform/webhook-reference#format
type MessageOpts struct {
Sender struct {
ID string `json:"id"`
} `json:"sender"`
Recipient struct {
ID string `json:"id"`
} `json:"recipient"`
Timestamp int64 `json:"timestamp"`
}
// MessageEvent encapsulates common info plus the specific type of callback
// being received.
// https://developers.facebook.com/docs/messenger-platform/webhook-reference#format
type MessageEvent struct {
Event
Messaging []struct {
MessageOpts
Message *MessageEcho `json:"message,omitempty"`
Delivery *Delivery `json:"delivery,omitempty"`
Postback *Postback `json:"postback,omitempty"`
Optin *Optin `json:"optin,omitempty"`
Read *Read `json:"read,omitempty"`
Referral *Referral `json:"referral,omitempty"`
PassThreadControl *PassThreadControl `json:"pass_thread_control,omitempty"`
TakeThreadControl *TakeThreadControl `json:"take_thread_control,omitempty"`
} `json:"messaging"`
}
// ReceivedMessage contains message specific information included with an echo
// callback.
// https://developers.facebook.com/docs/messenger-platform/webhook-reference/message-echo
type ReceivedMessage struct {
ID string `json:"mid"`
Text string `json:"text,omitempty"`
Attachments []*Attachment `json:"attachments,omitempty"`
Seq int `json:"seq"`
QuickReply *QuickReplyPayload `json:"quick_reply,omitempty"`
IsEcho bool `json:"is_echo,omitempty"`
Metadata *string `json:"metadata,omitempty"`
}
// QuickReplyPayload contains content specific to a quick reply.
// https://developers.facebook.com/docs/messenger-platform/webhook-reference/message
type QuickReplyPayload struct {
Payload string
}
// Delivery contains information specific to a message delivered callback.
// https://developers.facebook.com/docs/messenger-platform/webhook-reference/message-delivered
type Delivery struct {
MessageIDS []string `json:"mids"`
Watermark int64 `json:"watermark"`
Seq int `json:"seq"`
}
// Postback contains content specific to a postback.
// https://developers.facebook.com/docs/messenger-platform/webhook-reference/message
type Postback struct {
Payload string `json:"payload"`
Referral *Referral `json:"referral,omitempty"`
}
// Referral contains content specific to a referal.
// https://developers.facebook.com/docs/messenger-platform/webhook-reference/referal
type Referral struct {
Ref string`json:"ref,omitempty"`
Source string`json:"source,omitempty"`
Type string`json:"type,omitempty"`
}
// The Pass Thread Control API of the handover protocol is used to pass control of a conversation from one app to another.
// https://developers.facebook.com/docs/messenger-platform/handover-protocol/take-thread-control
type PassThreadControl struct {
NewOwnerAppID int64 `json:"new_owner_app_id,omitempty"`
Metadata string`json:"metadata,omitempty"`
}
// Take Thread Control API allows the app with the Primary Receiver role to take control of the conversation
// https://developers.facebook.com/docs/messenger-platform/handover-protocol/pass-thread-control
type TakeThreadControl struct {
PreviousOwnerAppID int64 `json:"previous_owner_app_id,omitempty"`
Metadata string`json:"metadata,omitempty"`
}
// Optin contains information specific to Opt-In callbacks.
// https://developers.facebook.com/docs/messenger-platform/webhook-reference/optins
type Optin struct {
Ref string `json:"ref"`
}
// Read contains data specific to message read callbacks.
// https://developers.facebook.com/docs/messenger-platform/webhook-reference/message-read
type Read struct {
Watermark int64 `json:"watermark"`
Seq int `json:"seq"`
}
// MessageEcho contains information specific to an echo callback.
// https://developers.facebook.com/docs/messenger-platform/webhook-reference/message-echo
type MessageEcho struct {
ReceivedMessage
AppID int64 `json:"app_id,omitempty"`
}