-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathincoming_update_fixtures.js
More file actions
265 lines (249 loc) · 4.98 KB
/
incoming_update_fixtures.js
File metadata and controls
265 lines (249 loc) · 4.98 KB
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
'use strict';
const attachments = require('./attachment_fixtures');
/**
* This file defines what incoming updates look like once they've been
* formated by a Bot class.
* It can be used to:
* 1) Test that your __formatUupdate() method is working as expected
* 2) Test that your middleware is doing what you expect it to with a typical update
*
* If writing botClasses, you might need to heavily use or edit these objects to make
* sure the ids match each other etc
*
* !!! They all come as functions, as this assures you that new objects are
* created every time you have a need to have one.
*/
const textUpdate = rawUpdate => ({
raw: rawUpdate,
sender: {
id: 'user_id',
},
recipient: {
id: 'bot_id',
},
timestamp: 1458692752478,
message: {
mid: 'mid.1457764197618:41d102a3e1ae206a38',
seq: 1,
text: 'Hello World!',
},
});
const quickReplyUpdate = rawUpdate => ({
raw: rawUpdate,
sender: {
id: 'user_id',
},
recipient: {
id: 'bot_id',
},
timestamp: 1458692752478,
message: {
mid: 'mid.1457764197618:41d102a3e1ae206a38',
seq: 1,
text: 'Hello World!', // the text that is directly in the quick reply button
quick_reply: {
payload: 'Hello World!', // change that to a developer defined payload if need be
},
},
});
const audioUpdate = rawUpdate => ({
raw: rawUpdate,
sender: {
id: 'user_id',
},
recipient: {
id: 'bot_id',
},
timestamp: 1458692752478,
message: {
mid: 'mid.1457764197618:41d102a3e1ae206a38',
seq: 1,
attachments: [
attachments.audioAttachment(),
],
},
});
const fileUpdate = rawUpdate => ({
raw: rawUpdate,
sender: {
id: 'user_id',
},
recipient: {
id: 'bot_id',
},
timestamp: 1458692752478,
message: {
mid: 'mid.1457764197618:41d102a3e1ae206a38',
seq: 1,
attachments: [
attachments.fileAttachment(),
],
},
});
const imageUpdate = rawUpdate => ({
raw: rawUpdate,
sender: {
id: 'user_id',
},
recipient: {
id: 'bot_id',
},
timestamp: 1458692752478,
message: {
mid: 'mid.1457764197618:41d102a3e1ae206a38',
seq: 1,
attachments: [
attachments.imageAttachment(),
],
},
});
const imageWithTextUpdate = rawUpdate => ({
raw: rawUpdate,
sender: {
id: 'user_id',
},
recipient: {
id: 'bot_id',
},
timestamp: 1458692752478,
message: {
mid: 'mid.1457764197618:41d102a3e1ae206a38',
seq: 1,
text: 'Hello World!',
attachments: [
attachments.imageAttachment(),
],
},
});
const videoUpdate = rawUpdate => ({
raw: rawUpdate,
sender: {
id: 'user_id',
},
recipient: {
id: 'bot_id',
},
timestamp: 1458692752478,
message: {
mid: 'mid.1457764197618:41d102a3e1ae206a38',
seq: 1,
attachments: [
attachments.videoAttachment(),
],
},
});
const payloadUpdate = rawUpdate => ({
raw: rawUpdate,
sender: {
id: 'user_id',
},
recipient: {
id: 'bot_id',
},
timestamp: 1458692752478,
message: {
mid: 'mid.1457764197618:41d102a3e1ae206a38',
seq: 1,
attachments: [
attachments.payloadAttachment(),
],
},
});
const multiAttachmentsUpdate = rawUpdate => ({
raw: rawUpdate,
sender: {
id: 'user_id',
},
recipient: {
id: 'bot_id',
},
timestamp: 1458692752478,
message: {
mid: 'mid.1457764197618:41d102a3e1ae206a38',
seq: 1,
attachments: [
attachments.imageAttachment(),
attachments.imageAttachment(),
attachments.videoAttachment(),
],
},
});
const messageDeliveredUpdate = rawUpdate => ({
raw: rawUpdate,
sender: {
id: 'user_id',
},
recipient: {
id: 'bot_id',
},
delivery: {
mids: [
'mid.1457764197618:41d102a3e1ae206a38',
],
watermark: 1458692752477,
seq: 1,
},
});
// message delivered update doesn't always necessarily contain
// the mids array
const messageDeliveredWithoutMidsUpdate = rawUpdate => ({
raw: rawUpdate,
sender: {
id: 'user_id',
},
recipient: {
id: 'bot_id',
},
delivery: {
watermark: 1458692752470,
seq: 1,
},
});
const messageReadUpdate = rawUpdate => ({
raw: rawUpdate,
sender: {
id: 'user_id',
},
recipient: {
id: 'bot_id',
},
timestamp: 1458692752480,
read: {
watermark: 1458692752470,
seq: 1,
},
});
const echoUpdate = (rawUpdate, showMetadata) => ({
raw: rawUpdate,
sender: {
id: 'user_id',
},
recipient: {
id: 'bot_id',
},
timestamp: 1458692752478,
message: {
is_echo: true,
app_id: 'some_app_id',
// Custom string passed to the Send API as the metadata field
metadata: showMetadata ? 'DEVELOPER_DEFINED_METADATA_STRING' : undefined,
mid: 'mid.1457764197618:41d102a3e1ae206a38',
seq: 1,
text: 'Hello World!',
},
});
module.exports = {
textUpdate,
quickReplyUpdate,
audioUpdate,
fileUpdate,
imageUpdate,
imageWithTextUpdate,
payloadUpdate,
videoUpdate,
multiAttachmentsUpdate,
messageDeliveredUpdate,
messageDeliveredWithoutMidsUpdate,
messageReadUpdate,
echoUpdate,
};