-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathoutgoing.go
306 lines (244 loc) · 6.3 KB
/
outgoing.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
package fbbot
// TODO: Audio message = Text + audio
// https://developers.facebook.com/docs/messenger-platform/send-api-reference/audio-attachment
// TODO: File message = Text + file
// https://developers.facebook.com/docs/messenger-platform/send-api-reference/audio-attachment
// TODO: Video message = Text + Video
// https://developers.facebook.com/docs/messenger-platform/send-api-reference/video-attachment
// TextMessage contains only text
type TextMessage struct {
// Text is text content of the message
// must be UTF-8, 320 character limit
// required
Text string
Noti string
}
func NewTextMessage(text string) *TextMessage {
var t TextMessage
t.Text = text
t.Noti = NotiRegular
return &t
}
// ButtonMessage contains text and buttons
type ButtonMessage struct {
// // Text is text content of the message
// // must be UTF-8, 320 character limit
// // not required
// Text string
// // MainText is text that appears in main body
// // required
// MainText string
Text string
Noti string
Buttons []Button
}
func NewButtonMessage() *ButtonMessage {
var b ButtonMessage
b.Noti = NotiRegular
return &b
}
func (m *ButtonMessage) AddWebURLButton(title, URL string) {
b := NewWebURLButton(title, URL)
m.Buttons = append(m.Buttons, b)
}
func (m *ButtonMessage) AddPostbackButton(title, payload string) {
b := NewPostbackButton(title, payload)
m.Buttons = append(m.Buttons, b)
}
// TODO
// func (m *ButtonMessage) AddButton(b Button) {}
// func (m *ButtonMessage) AddButtons(bs []Button) {}
// Button
type Button struct {
Type string `json:"type"` // web_url or postback
Title string `json:"title,omitempty"`
URL string `json:"url,omitempty"`
Payload string `json:"payload,omitempty"`
}
func NewWebURLButton(title, URL string) Button {
return Button{
Type: "web_url",
Title: title,
URL: URL,
}
}
func NewPostbackButton(title, payload string) Button {
return Button{
Type: "postback",
Title: title,
Payload: payload,
}
}
// GenericMessage could contain text, image, title, subtitle, description and buttons.
// Can support multiple bubbles per message and display them as a horizontal list.
type GenericMessage struct {
// Text is text content of the message
// must be UTF-8, 320 character limit
// not required
Text string // TODO: ? nothing to do with this field?
Noti string
Bubbles []Bubble
}
func NewGenericMessage() *GenericMessage {
var g GenericMessage
g.Noti = NotiRegular
return &g
}
// Bubble represents ...
type Bubble struct {
// Title is title of the bubble
// required
Title string `json:"title"`
// SubTitle is buble subtitle
// not required
SubTitle string `json:"subtitle"`
// ItemURL is URL opened when bubble is tapped
// not required
ItemURL string `json:"item_url"`
// ImageURL is URL of bubble image
// not required
ImageURL string `json:"image_url"`
// Buttons are buttons that appear as call-to-actions
// not required
Buttons []Button `json:"buttons"`
}
// TODO: Send image from file: https://developers.facebook.com/docs/messenger-platform/send-api-reference/image-attachment
// ImageMessage contains text and image
// Supported formats are jpg, png and gif.
type ImageMessage struct {
Type string `json:"type"`
Noti string
// URL is URL of the image
// required
URL string
}
func NewImageMessage() *ImageMessage {
var i ImageMessage
i.Type = "image"
i.Noti = NotiRegular
return &i
}
type ReceiptMessage struct {
// Text is text content of the message
// must be UTF-8, 320 character limit
// not required
Text string
Noti string
// RecipientName is recipient name
// required
RecipientName string
// OrderNumber is order number
// must be unique
// required
OrderNumber string
// Currency is currency for the order
// required
Currency string
// PaymentMethod Payment method details. This can be a custom string. Ex: 'Visa 1234'
// required
PaymentMethod string
// Timestamp is timestamp of order
// not required
Timestamp string
// OrderURL is URL of order
// not required
OrderURL string
// Items are items in order
// required
Items []Item
// Shipping address
// not required
Address Address
// Summary is Payment summary
// required
Summary Summary
// Adjustments is Payment adjustments
// not required
Adjustments []Adjustment
}
func NewReceiptMessage() *ReceiptMessage {
var r ReceiptMessage
r.Noti = NotiRegular
return &r
}
// Item is item in order
type Item struct {
// Title is item title
// required
Title string
// Subtile of item
// not required
Subtitle string
// Quantity of item
// not required
Quantity float64
// Price of item
// not required
Price float64
// Currency of item
// not required
Currency string
// ImageURL is image URL of item
// not required
ImageURL string
}
// Shipping address
type Address struct {
// Street1 Street Address, line 1
Street1 string
// Street2 Street Address, line 2
Street2 string
// City
City string
// PostalCode Postal code
PostalCode string
// State is state abbrevation
State string
// Country is Two-letter country abbreviation
Country string
}
// Summary is Payment summary
type Summary struct {
// Subtotal
// not required
Subtotal float64
// ShippingCost is cost of shipping
// not required
ShippingCost float64
// TotalTax is total tax
// not required
TotalTax float64
// TotalCost is total cost
// required
TotalCost float64
}
// Adjustment is payment adjustment.
// Allows a way to insert adjusted pricing (e.g., sales).
type Adjustment struct {
// Name is name of adjustment
Name string
// Amount is adjusted amount
Amout float64
}
type QuickRepliesMessage struct {
Text string `json:"text"`
Items []QuickRepliesItem `json:"quick_replies"`
}
type QuickRepliesItem struct {
ContentType string `json:"content_type"` // 'text' or 'location'
Title string `json:"title,omitempty"` // empty when ContentType='location'
Payload string `json:"payload,omitempty"` // empty when ContentType='location'
ImageURL string `json:"image_url,omitempty"` // optional, empty when ContentType='location'
}
func NewQuickRepliesText(title string, payload string) QuickRepliesItem {
return QuickRepliesItem{
ContentType: "text",
Title: title,
Payload: payload,
}
}
func NewQuickRepliesLocation() QuickRepliesItem {
return QuickRepliesItem{
ContentType: "location",
}
}