alicezetion 1.5.7 → 1.5.9
Sign up to get free protection for your applications and to get access to all the features.
- package/.cache/replit/__replit_disk_meta.json +1 -1
- package/.cache/replit/nix/env.json +1 -1
- package/index.js +489 -526
- package/leiamnash/addExternalModule.js +15 -19
- package/leiamnash/addUserToGroup.js +77 -113
- package/leiamnash/changeAdminStatus.js +47 -79
- package/leiamnash/changeArchivedStatus.js +41 -55
- package/leiamnash/changeBio.js +64 -77
- package/leiamnash/changeBlockedStatus.js +36 -47
- package/leiamnash/changeGroupImage.js +105 -129
- package/leiamnash/changeNickname.js +43 -59
- package/leiamnash/changeThreadColor.js +61 -71
- package/leiamnash/changeThreadEmoji.js +41 -55
- package/leiamnash/chat.js +324 -459
- package/leiamnash/createNewGroup.js +70 -86
- package/leiamnash/createPoll.js +59 -71
- package/leiamnash/deleteMessage.js +44 -56
- package/leiamnash/deleteThread.js +42 -56
- package/leiamnash/forwardAttachment.js +47 -60
- package/leiamnash/forwardMessage.js +0 -0
- package/leiamnash/getCurrentUserID.js +7 -7
- package/leiamnash/getEmojiUrl.js +27 -29
- package/leiamnash/getFriendsList.js +73 -84
- package/leiamnash/getThreadHistory.js +537 -645
- package/leiamnash/getThreadHistoryDeprecated.js +71 -93
- package/leiamnash/getThreadInfo.js +171 -206
- package/leiamnash/getThreadInfoDeprecated.js +56 -80
- package/leiamnash/getThreadList.js +213 -238
- package/leiamnash/getThreadListDeprecated.js +46 -75
- package/leiamnash/getThreadPictures.js +59 -79
- package/leiamnash/getUserID.js +61 -66
- package/leiamnash/getUserInfo.js +66 -72
- package/leiamnash/handleFriendRequest.js +46 -61
- package/leiamnash/handleMessageRequest.js +47 -65
- package/leiamnash/httpGet.js +47 -52
- package/leiamnash/httpPost.js +47 -52
- package/leiamnash/listen.js +553 -0
- package/leiamnash/listenMqtt-Test.js +687 -0
- package/leiamnash/listenMqtt.js +685 -789
- package/leiamnash/logout.js +68 -75
- package/leiamnash/markAsDelivered.js +47 -58
- package/leiamnash/markAsRead.js +70 -80
- package/leiamnash/markAsReadAll.js +39 -49
- package/leiamnash/markAsSeen.js +48 -59
- package/leiamnash/muteThread.js +45 -52
- package/leiamnash/removeUserFromGroup.js +45 -79
- package/leiamnash/resolvePhotoUrl.js +36 -45
- package/leiamnash/searchForThread.js +42 -53
- package/leiamnash/sendTypingIndicator.js +70 -103
- package/leiamnash/setMessageReaction.js +103 -117
- package/leiamnash/setPostReaction.js +63 -76
- package/leiamnash/setTitle.js +70 -86
- package/leiamnash/threadColors.js +41 -57
- package/leiamnash/unfriend.js +42 -52
- package/leiamnash/unsendMessage.js +39 -49
- package/package.json +73 -71
- package/utils.js +1198 -1356
@@ -1,645 +1,537 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var utils = require("../utils");
|
4
|
-
var log = require("npmlog");
|
5
|
-
|
6
|
-
function formatAttachmentsGraphQLResponse(attachment) {
|
7
|
-
switch (attachment.__typename) {
|
8
|
-
case "MessageImage":
|
9
|
-
return {
|
10
|
-
type: "photo",
|
11
|
-
ID: attachment.legacy_attachment_id,
|
12
|
-
filename: attachment.filename,
|
13
|
-
thumbnailUrl: attachment.thumbnail.uri,
|
14
|
-
|
15
|
-
previewUrl: attachment.preview.uri,
|
16
|
-
previewWidth: attachment.preview.width,
|
17
|
-
previewHeight: attachment.preview.height,
|
18
|
-
|
19
|
-
largePreviewUrl: attachment.large_preview.uri,
|
20
|
-
largePreviewHeight: attachment.large_preview.height,
|
21
|
-
largePreviewWidth: attachment.large_preview.width,
|
22
|
-
|
23
|
-
// You have to query for the real image. See below.
|
24
|
-
url: attachment.large_preview.uri, // @Legacy
|
25
|
-
width: attachment.large_preview.width, // @Legacy
|
26
|
-
height: attachment.large_preview.height, // @Legacy
|
27
|
-
name: attachment.filename, // @Legacy
|
28
|
-
|
29
|
-
// @Undocumented
|
30
|
-
attributionApp: attachment.attribution_app
|
31
|
-
? {
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
: null
|
37
|
-
|
38
|
-
// @TODO No idea what this is, should we expose it?
|
39
|
-
// Ben - July 15th 2017
|
40
|
-
// renderAsSticker: attachment.render_as_sticker,
|
41
|
-
|
42
|
-
// This is _not_ the real URI, this is still just a large preview.
|
43
|
-
// To get the URL we'll need to support a POST query to
|
44
|
-
//
|
45
|
-
// https://www.facebook.com/webgraphql/query/
|
46
|
-
//
|
47
|
-
// With the following query params:
|
48
|
-
//
|
49
|
-
// query_id:728987990612546
|
50
|
-
// variables:{"id":"100009069356507","photoID":"10213724771692996"}
|
51
|
-
// dpr:1
|
52
|
-
//
|
53
|
-
// No special form though.
|
54
|
-
};
|
55
|
-
case "MessageAnimatedImage":
|
56
|
-
return {
|
57
|
-
type: "animated_image",
|
58
|
-
ID: attachment.legacy_attachment_id,
|
59
|
-
filename: attachment.filename,
|
60
|
-
|
61
|
-
previewUrl: attachment.preview_image.uri,
|
62
|
-
previewWidth: attachment.preview_image.width,
|
63
|
-
previewHeight: attachment.preview_image.height,
|
64
|
-
|
65
|
-
url: attachment.animated_image.uri,
|
66
|
-
width: attachment.animated_image.width,
|
67
|
-
height: attachment.animated_image.height,
|
68
|
-
|
69
|
-
thumbnailUrl: attachment.preview_image.uri, // @Legacy
|
70
|
-
name: attachment.filename, // @Legacy
|
71
|
-
facebookUrl: attachment.animated_image.uri, // @Legacy
|
72
|
-
rawGifImage: attachment.animated_image.uri, // @Legacy
|
73
|
-
animatedGifUrl: attachment.animated_image.uri, // @Legacy
|
74
|
-
animatedGifPreviewUrl: attachment.preview_image.uri, // @Legacy
|
75
|
-
animatedWebpUrl: attachment.animated_image.uri, // @Legacy
|
76
|
-
animatedWebpPreviewUrl: attachment.preview_image.uri, // @Legacy
|
77
|
-
|
78
|
-
// @Undocumented
|
79
|
-
attributionApp: attachment.attribution_app
|
80
|
-
? {
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
: null
|
86
|
-
};
|
87
|
-
case "MessageVideo":
|
88
|
-
return {
|
89
|
-
type: "video",
|
90
|
-
filename: attachment.filename,
|
91
|
-
ID: attachment.legacy_attachment_id,
|
92
|
-
|
93
|
-
thumbnailUrl: attachment.large_image.uri, // @Legacy
|
94
|
-
|
95
|
-
previewUrl: attachment.large_image.uri,
|
96
|
-
previewWidth: attachment.large_image.width,
|
97
|
-
previewHeight: attachment.large_image.height,
|
98
|
-
|
99
|
-
url: attachment.playable_url,
|
100
|
-
width: attachment.original_dimensions.x,
|
101
|
-
height: attachment.original_dimensions.y,
|
102
|
-
|
103
|
-
duration: attachment.playable_duration_in_ms,
|
104
|
-
videoType: attachment.video_type.toLowerCase()
|
105
|
-
};
|
106
|
-
case "MessageFile":
|
107
|
-
return {
|
108
|
-
type: "file",
|
109
|
-
filename: attachment.filename,
|
110
|
-
ID: attachment.message_file_fbid,
|
111
|
-
|
112
|
-
url: attachment.url,
|
113
|
-
isMalicious: attachment.is_malicious,
|
114
|
-
contentType: attachment.content_type,
|
115
|
-
|
116
|
-
name: attachment.filename, // @Legacy
|
117
|
-
mimeType: "", // @Legacy
|
118
|
-
fileSize: -1 // @Legacy
|
119
|
-
};
|
120
|
-
case "MessageAudio":
|
121
|
-
return {
|
122
|
-
type: "audio",
|
123
|
-
filename: attachment.filename,
|
124
|
-
ID: attachment.url_shimhash, // Not fowardable
|
125
|
-
|
126
|
-
audioType: attachment.audio_type,
|
127
|
-
duration: attachment.playable_duration_in_ms,
|
128
|
-
url: attachment.playable_url,
|
129
|
-
|
130
|
-
isVoiceMail: attachment.is_voicemail
|
131
|
-
};
|
132
|
-
default:
|
133
|
-
return {
|
134
|
-
error: "Don't know about attachment type " + attachment.__typename
|
135
|
-
};
|
136
|
-
}
|
137
|
-
}
|
138
|
-
|
139
|
-
function formatExtensibleAttachment(attachment) {
|
140
|
-
if (attachment.story_attachment) {
|
141
|
-
return {
|
142
|
-
type: "share",
|
143
|
-
ID: attachment.legacy_attachment_id,
|
144
|
-
url: attachment.story_attachment.url,
|
145
|
-
|
146
|
-
title: attachment.story_attachment.title_with_entities.text,
|
147
|
-
description:
|
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
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
isGroup: messageThread.thread_type === "GROUP",
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
logMessageType: "
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
};
|
477
|
-
|
478
|
-
return {
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
// @Legacy
|
539
|
-
logMessageType: "other"
|
540
|
-
};
|
541
|
-
case "VoiceCallMessage":
|
542
|
-
return {
|
543
|
-
type: "event",
|
544
|
-
messageID: d.message_id,
|
545
|
-
threadID: threadID,
|
546
|
-
isGroup: messageThread.thread_type === "GROUP",
|
547
|
-
senderID: d.message_sender.id,
|
548
|
-
timestamp: d.timestamp_precise,
|
549
|
-
eventType: "voice_call",
|
550
|
-
snippet: d.snippet,
|
551
|
-
|
552
|
-
// @Legacy
|
553
|
-
logMessageType: "other"
|
554
|
-
};
|
555
|
-
case "GenericAdminTextMessage":
|
556
|
-
return {
|
557
|
-
type: "event",
|
558
|
-
messageID: d.message_id,
|
559
|
-
threadID: threadID,
|
560
|
-
isGroup: messageThread.thread_type === "GROUP",
|
561
|
-
senderID: d.message_sender.id,
|
562
|
-
timestamp: d.timestamp_precise,
|
563
|
-
snippet: d.snippet,
|
564
|
-
eventType: d.extensible_message_admin_text_type.toLowerCase(),
|
565
|
-
eventData: formatEventData(d.extensible_message_admin_text),
|
566
|
-
|
567
|
-
// @Legacy
|
568
|
-
logMessageType: utils.getAdminTextMessageType(
|
569
|
-
d.extensible_message_admin_text_type
|
570
|
-
),
|
571
|
-
logMessageData: d.extensible_message_admin_text // Maybe different?
|
572
|
-
};
|
573
|
-
default:
|
574
|
-
return { error: "Don't know about message type " + d.__typename };
|
575
|
-
}
|
576
|
-
});
|
577
|
-
return messages;
|
578
|
-
}
|
579
|
-
|
580
|
-
module.exports = function(defaultFuncs, api, ctx) {
|
581
|
-
return function getThreadHistoryGraphQL(
|
582
|
-
threadID,
|
583
|
-
amount,
|
584
|
-
timestamp,
|
585
|
-
callback
|
586
|
-
) {
|
587
|
-
var resolveFunc = function(){};
|
588
|
-
var rejectFunc = function(){};
|
589
|
-
var returnPromise = new Promise(function (resolve, reject) {
|
590
|
-
resolveFunc = resolve;
|
591
|
-
rejectFunc = reject;
|
592
|
-
});
|
593
|
-
|
594
|
-
if (!callback) {
|
595
|
-
callback = function (err, data) {
|
596
|
-
if (err) {
|
597
|
-
return rejectFunc(err);
|
598
|
-
}
|
599
|
-
resolveFunc(data);
|
600
|
-
};
|
601
|
-
}
|
602
|
-
|
603
|
-
// `queries` has to be a string. I couldn't tell from the dev console. This
|
604
|
-
// took me a really long time to figure out. I deserve a cookie for this.
|
605
|
-
var form = {
|
606
|
-
"av": ctx.globalOptions.pageID,
|
607
|
-
queries: JSON.stringify({
|
608
|
-
o0: {
|
609
|
-
// This doc_id was valid on February 2nd 2017.
|
610
|
-
doc_id: "1498317363570230",
|
611
|
-
query_params: {
|
612
|
-
id: threadID,
|
613
|
-
message_limit: amount,
|
614
|
-
load_messages: 1,
|
615
|
-
load_read_receipts: false,
|
616
|
-
before: timestamp
|
617
|
-
}
|
618
|
-
}
|
619
|
-
})
|
620
|
-
};
|
621
|
-
|
622
|
-
defaultFuncs
|
623
|
-
.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
|
624
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
625
|
-
.then(function(resData) {
|
626
|
-
if (resData.error) {
|
627
|
-
throw resData;
|
628
|
-
}
|
629
|
-
// This returns us an array of things. The last one is the success /
|
630
|
-
// failure one.
|
631
|
-
// @TODO What do we do in this case?
|
632
|
-
if (resData[resData.length - 1].error_results !== 0) {
|
633
|
-
throw new Error("There was an error_result.");
|
634
|
-
}
|
635
|
-
|
636
|
-
callback(null, formatMessagesGraphQLResponse(resData[0]));
|
637
|
-
})
|
638
|
-
.catch(function(err) {
|
639
|
-
log.error("getThreadHistoryGraphQL", err);
|
640
|
-
return callback(err);
|
641
|
-
});
|
642
|
-
|
643
|
-
return returnPromise;
|
644
|
-
};
|
645
|
-
};
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var utils = require("../utils");
|
4
|
+
var log = require("npmlog");
|
5
|
+
|
6
|
+
function formatAttachmentsGraphQLResponse(attachment) {
|
7
|
+
switch (attachment.__typename) {
|
8
|
+
case "MessageImage":
|
9
|
+
return {
|
10
|
+
type: "photo",
|
11
|
+
ID: attachment.legacy_attachment_id,
|
12
|
+
filename: attachment.filename,
|
13
|
+
thumbnailUrl: attachment.thumbnail.uri,
|
14
|
+
|
15
|
+
previewUrl: attachment.preview.uri,
|
16
|
+
previewWidth: attachment.preview.width,
|
17
|
+
previewHeight: attachment.preview.height,
|
18
|
+
|
19
|
+
largePreviewUrl: attachment.large_preview.uri,
|
20
|
+
largePreviewHeight: attachment.large_preview.height,
|
21
|
+
largePreviewWidth: attachment.large_preview.width,
|
22
|
+
|
23
|
+
// You have to query for the real image. See below.
|
24
|
+
url: attachment.large_preview.uri, // @Legacy
|
25
|
+
width: attachment.large_preview.width, // @Legacy
|
26
|
+
height: attachment.large_preview.height, // @Legacy
|
27
|
+
name: attachment.filename, // @Legacy
|
28
|
+
|
29
|
+
// @Undocumented
|
30
|
+
attributionApp: attachment.attribution_app
|
31
|
+
? {
|
32
|
+
attributionAppID: attachment.attribution_app.id,
|
33
|
+
name: attachment.attribution_app.name,
|
34
|
+
logo: attachment.attribution_app.square_logo
|
35
|
+
}
|
36
|
+
: null
|
37
|
+
|
38
|
+
// @TODO No idea what this is, should we expose it?
|
39
|
+
// Ben - July 15th 2017
|
40
|
+
// renderAsSticker: attachment.render_as_sticker,
|
41
|
+
|
42
|
+
// This is _not_ the real URI, this is still just a large preview.
|
43
|
+
// To get the URL we'll need to support a POST query to
|
44
|
+
//
|
45
|
+
// https://www.facebook.com/webgraphql/query/
|
46
|
+
//
|
47
|
+
// With the following query params:
|
48
|
+
//
|
49
|
+
// query_id:728987990612546
|
50
|
+
// variables:{"id":"100009069356507","photoID":"10213724771692996"}
|
51
|
+
// dpr:1
|
52
|
+
//
|
53
|
+
// No special form though.
|
54
|
+
};
|
55
|
+
case "MessageAnimatedImage":
|
56
|
+
return {
|
57
|
+
type: "animated_image",
|
58
|
+
ID: attachment.legacy_attachment_id,
|
59
|
+
filename: attachment.filename,
|
60
|
+
|
61
|
+
previewUrl: attachment.preview_image.uri,
|
62
|
+
previewWidth: attachment.preview_image.width,
|
63
|
+
previewHeight: attachment.preview_image.height,
|
64
|
+
|
65
|
+
url: attachment.animated_image.uri,
|
66
|
+
width: attachment.animated_image.width,
|
67
|
+
height: attachment.animated_image.height,
|
68
|
+
|
69
|
+
thumbnailUrl: attachment.preview_image.uri, // @Legacy
|
70
|
+
name: attachment.filename, // @Legacy
|
71
|
+
facebookUrl: attachment.animated_image.uri, // @Legacy
|
72
|
+
rawGifImage: attachment.animated_image.uri, // @Legacy
|
73
|
+
animatedGifUrl: attachment.animated_image.uri, // @Legacy
|
74
|
+
animatedGifPreviewUrl: attachment.preview_image.uri, // @Legacy
|
75
|
+
animatedWebpUrl: attachment.animated_image.uri, // @Legacy
|
76
|
+
animatedWebpPreviewUrl: attachment.preview_image.uri, // @Legacy
|
77
|
+
|
78
|
+
// @Undocumented
|
79
|
+
attributionApp: attachment.attribution_app
|
80
|
+
? {
|
81
|
+
attributionAppID: attachment.attribution_app.id,
|
82
|
+
name: attachment.attribution_app.name,
|
83
|
+
logo: attachment.attribution_app.square_logo
|
84
|
+
}
|
85
|
+
: null
|
86
|
+
};
|
87
|
+
case "MessageVideo":
|
88
|
+
return {
|
89
|
+
type: "video",
|
90
|
+
filename: attachment.filename,
|
91
|
+
ID: attachment.legacy_attachment_id,
|
92
|
+
|
93
|
+
thumbnailUrl: attachment.large_image.uri, // @Legacy
|
94
|
+
|
95
|
+
previewUrl: attachment.large_image.uri,
|
96
|
+
previewWidth: attachment.large_image.width,
|
97
|
+
previewHeight: attachment.large_image.height,
|
98
|
+
|
99
|
+
url: attachment.playable_url,
|
100
|
+
width: attachment.original_dimensions.x,
|
101
|
+
height: attachment.original_dimensions.y,
|
102
|
+
|
103
|
+
duration: attachment.playable_duration_in_ms,
|
104
|
+
videoType: attachment.video_type.toLowerCase()
|
105
|
+
};
|
106
|
+
case "MessageFile":
|
107
|
+
return {
|
108
|
+
type: "file",
|
109
|
+
filename: attachment.filename,
|
110
|
+
ID: attachment.message_file_fbid,
|
111
|
+
|
112
|
+
url: attachment.url,
|
113
|
+
isMalicious: attachment.is_malicious,
|
114
|
+
contentType: attachment.content_type,
|
115
|
+
|
116
|
+
name: attachment.filename, // @Legacy
|
117
|
+
mimeType: "", // @Legacy
|
118
|
+
fileSize: -1 // @Legacy
|
119
|
+
};
|
120
|
+
case "MessageAudio":
|
121
|
+
return {
|
122
|
+
type: "audio",
|
123
|
+
filename: attachment.filename,
|
124
|
+
ID: attachment.url_shimhash, // Not fowardable
|
125
|
+
|
126
|
+
audioType: attachment.audio_type,
|
127
|
+
duration: attachment.playable_duration_in_ms,
|
128
|
+
url: attachment.playable_url,
|
129
|
+
|
130
|
+
isVoiceMail: attachment.is_voicemail
|
131
|
+
};
|
132
|
+
default:
|
133
|
+
return {
|
134
|
+
error: "Don't know about attachment type " + attachment.__typename
|
135
|
+
};
|
136
|
+
}
|
137
|
+
}
|
138
|
+
|
139
|
+
function formatExtensibleAttachment(attachment) {
|
140
|
+
if (attachment.story_attachment) {
|
141
|
+
return {
|
142
|
+
type: "share",
|
143
|
+
ID: attachment.legacy_attachment_id,
|
144
|
+
url: attachment.story_attachment.url,
|
145
|
+
|
146
|
+
title: attachment.story_attachment.title_with_entities.text,
|
147
|
+
description: attachment.story_attachment.description && attachment.story_attachment.description.text,
|
148
|
+
source: attachment.story_attachment.source == null ? null : attachment.story_attachment.source.text,
|
149
|
+
|
150
|
+
image: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.animated_image == null && attachment.story_attachment.media.image == null ? null : (attachment.story_attachment.media.animated_image || attachment.story_attachment.media.image).uri,
|
151
|
+
width: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.animated_image == null && attachment.story_attachment.media.image == null ? null : (attachment.story_attachment.media.animated_image || attachment.story_attachment.media.image).width,
|
152
|
+
height: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.animated_image == null && attachment.story_attachment.media.image == null ? null : (attachment.story_attachment.media.animated_image || attachment.story_attachment.media.image).height,
|
153
|
+
playable: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.is_playable,
|
154
|
+
duration: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.playable_duration_in_ms,
|
155
|
+
playableUrl: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.playable_url,
|
156
|
+
|
157
|
+
subattachments: attachment.story_attachment.subattachments,
|
158
|
+
|
159
|
+
// Format example:
|
160
|
+
//
|
161
|
+
// [{
|
162
|
+
// key: "width",
|
163
|
+
// value: { text: "1280" }
|
164
|
+
// }]
|
165
|
+
//
|
166
|
+
// That we turn into:
|
167
|
+
//
|
168
|
+
// {
|
169
|
+
// width: "1280"
|
170
|
+
// }
|
171
|
+
//
|
172
|
+
properties: attachment.story_attachment.properties.reduce(function (obj, cur) {
|
173
|
+
obj[cur.key] = cur.value.text;
|
174
|
+
return obj;
|
175
|
+
}, {}),
|
176
|
+
|
177
|
+
// Deprecated fields
|
178
|
+
animatedImageSize: "", // @Legacy
|
179
|
+
facebookUrl: "", // @Legacy
|
180
|
+
styleList: "", // @Legacy
|
181
|
+
target: "", // @Legacy
|
182
|
+
thumbnailUrl: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.animated_image == null && attachment.story_attachment.media.image == null ? null : (attachment.story_attachment.media.animated_image || attachment.story_attachment.media.image).uri, // @Legacy
|
183
|
+
thumbnailWidth: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.animated_image == null && attachment.story_attachment.media.image == null ? null : (attachment.story_attachment.media.animated_image || attachment.story_attachment.media.image).width, // @Legacy
|
184
|
+
thumbnailHeight: attachment.story_attachment.media == null ? null : attachment.story_attachment.media.animated_image == null && attachment.story_attachment.media.image == null ? null : (attachment.story_attachment.media.animated_image || attachment.story_attachment.media.image).height // @Legacy
|
185
|
+
};
|
186
|
+
}
|
187
|
+
else return { error: "Don't know what to do with extensible_attachment." };
|
188
|
+
}
|
189
|
+
|
190
|
+
function formatReactionsGraphQL(reaction) {
|
191
|
+
return {
|
192
|
+
reaction: reaction.reaction,
|
193
|
+
userID: reaction.user.id
|
194
|
+
};
|
195
|
+
}
|
196
|
+
|
197
|
+
function formatEventData(event) {
|
198
|
+
if (event == null) return {}
|
199
|
+
|
200
|
+
switch (event.__typename) {
|
201
|
+
case "ThemeColorExtensibleMessageAdminText":
|
202
|
+
return { color: event.theme_color };
|
203
|
+
case "ThreadNicknameExtensibleMessageAdminText":
|
204
|
+
return {
|
205
|
+
nickname: event.nickname,
|
206
|
+
participantID: event.participant_id
|
207
|
+
};
|
208
|
+
case "ThreadIconExtensibleMessageAdminText":
|
209
|
+
return { threadIcon: event.thread_icon };
|
210
|
+
case "InstantGameUpdateExtensibleMessageAdminText":
|
211
|
+
return {
|
212
|
+
gameID: (event.game == null ? null : event.game.id),
|
213
|
+
update_type: event.update_type,
|
214
|
+
collapsed_text: event.collapsed_text,
|
215
|
+
expanded_text: event.expanded_text,
|
216
|
+
instant_game_update_data: event.instant_game_update_data
|
217
|
+
};
|
218
|
+
case "GameScoreExtensibleMessageAdminText":
|
219
|
+
return { game_type: event.game_type };
|
220
|
+
case "RtcCallLogExtensibleMessageAdminText":
|
221
|
+
return {
|
222
|
+
event: event.event,
|
223
|
+
is_video_call: event.is_video_call,
|
224
|
+
server_info_data: event.server_info_data
|
225
|
+
};
|
226
|
+
case "GroupPollExtensibleMessageAdminText":
|
227
|
+
return {
|
228
|
+
event_type: event.event_type,
|
229
|
+
total_count: event.total_count,
|
230
|
+
question: event.question
|
231
|
+
};
|
232
|
+
case "AcceptPendingThreadExtensibleMessageAdminText":
|
233
|
+
return {
|
234
|
+
accepter_id: event.accepter_id,
|
235
|
+
requester_id: event.requester_id
|
236
|
+
};
|
237
|
+
case "ConfirmFriendRequestExtensibleMessageAdminText":
|
238
|
+
return {
|
239
|
+
friend_request_recipient: event.friend_request_recipient,
|
240
|
+
friend_request_sender: event.friend_request_sender
|
241
|
+
};
|
242
|
+
case "AddContactExtensibleMessageAdminText":
|
243
|
+
return {
|
244
|
+
contact_added_id: event.contact_added_id,
|
245
|
+
contact_adder_id: event.contact_adder_id
|
246
|
+
};
|
247
|
+
case "AdExtensibleMessageAdminText":
|
248
|
+
return {
|
249
|
+
ad_client_token: event.ad_client_token,
|
250
|
+
ad_id: event.ad_id,
|
251
|
+
ad_preferences_link: event.ad_preferences_link,
|
252
|
+
ad_properties: event.ad_properties
|
253
|
+
};
|
254
|
+
// never data
|
255
|
+
case "ParticipantJoinedGroupCallExtensibleMessageAdminText":
|
256
|
+
case "ThreadEphemeralTtlModeExtensibleMessageAdminText":
|
257
|
+
case "StartedSharingVideoExtensibleMessageAdminText":
|
258
|
+
case "LightweightEventCreateExtensibleMessageAdminText":
|
259
|
+
case "LightweightEventNotifyExtensibleMessageAdminText":
|
260
|
+
case "LightweightEventNotifyBeforeEventExtensibleMessageAdminText":
|
261
|
+
case "LightweightEventUpdateTitleExtensibleMessageAdminText":
|
262
|
+
case "LightweightEventUpdateTimeExtensibleMessageAdminText":
|
263
|
+
case "LightweightEventUpdateLocationExtensibleMessageAdminText":
|
264
|
+
case "LightweightEventDeleteExtensibleMessageAdminText":
|
265
|
+
return {};
|
266
|
+
default:
|
267
|
+
return { error: "Don't know what to with event data type " + event.__typename };
|
268
|
+
}
|
269
|
+
}
|
270
|
+
|
271
|
+
function formatMessagesGraphQLResponse(data) {
|
272
|
+
var messageThread = data.o0.data.message_thread;
|
273
|
+
var threadID = messageThread.thread_key.thread_fbid ? messageThread.thread_key.thread_fbid : messageThread.thread_key.other_user_id;
|
274
|
+
|
275
|
+
var messages = messageThread.messages.nodes.map(function (d) {
|
276
|
+
switch (d.__typename) {
|
277
|
+
case "UserMessage":
|
278
|
+
// Give priority to stickers. They're seen as normal messages but we've
|
279
|
+
// been considering them as attachments.
|
280
|
+
var maybeStickerAttachment;
|
281
|
+
if (d.sticker) {
|
282
|
+
maybeStickerAttachment = [
|
283
|
+
{
|
284
|
+
type: "sticker",
|
285
|
+
ID: d.sticker.id,
|
286
|
+
url: d.sticker.url,
|
287
|
+
|
288
|
+
packID: d.sticker.pack.id,
|
289
|
+
spriteUrl: d.sticker.sprite_image,
|
290
|
+
spriteUrl2x: d.sticker.sprite_image_2x,
|
291
|
+
width: d.sticker.width,
|
292
|
+
height: d.sticker.height,
|
293
|
+
|
294
|
+
caption: d.snippet, // Not sure what the heck caption was.
|
295
|
+
description: d.sticker.label, // Not sure about this one either.
|
296
|
+
|
297
|
+
frameCount: d.sticker.frame_count,
|
298
|
+
frameRate: d.sticker.frame_rate,
|
299
|
+
framesPerRow: d.sticker.frames_per_row,
|
300
|
+
framesPerCol: d.sticker.frames_per_col,
|
301
|
+
|
302
|
+
stickerID: d.sticker.id, // @Legacy
|
303
|
+
spriteURI: d.sticker.sprite_image, // @Legacy
|
304
|
+
spriteURI2x: d.sticker.sprite_image_2x // @Legacy
|
305
|
+
}
|
306
|
+
];
|
307
|
+
}
|
308
|
+
|
309
|
+
var mentionsObj = {};
|
310
|
+
if (d.message !== null) {
|
311
|
+
d.message.ranges.forEach(e => mentionsObj[e.entity.id] = d.message.text.substr(e.offset, e.length));
|
312
|
+
}
|
313
|
+
|
314
|
+
return {
|
315
|
+
type: "message",
|
316
|
+
attachments: maybeStickerAttachment
|
317
|
+
? maybeStickerAttachment
|
318
|
+
: d.blob_attachments && d.blob_attachments.length > 0
|
319
|
+
? d.blob_attachments.map(formatAttachmentsGraphQLResponse)
|
320
|
+
: d.extensible_attachment
|
321
|
+
? [formatExtensibleAttachment(d.extensible_attachment)]
|
322
|
+
: [],
|
323
|
+
body: d.message !== null ? d.message.text : '',
|
324
|
+
isGroup: messageThread.thread_type === "GROUP",
|
325
|
+
messageID: d.message_id,
|
326
|
+
senderID: d.message_sender.id,
|
327
|
+
threadID: threadID,
|
328
|
+
timestamp: d.timestamp_precise,
|
329
|
+
|
330
|
+
mentions: mentionsObj,
|
331
|
+
isUnread: d.unread,
|
332
|
+
|
333
|
+
// New
|
334
|
+
messageReactions: d.message_reactions ? d.message_reactions.map(formatReactionsGraphQL) : null,
|
335
|
+
isSponsored: d.is_sponsored,
|
336
|
+
snippet: d.snippet
|
337
|
+
};
|
338
|
+
case "ThreadNameMessage":
|
339
|
+
return {
|
340
|
+
type: "event",
|
341
|
+
messageID: d.message_id,
|
342
|
+
threadID: threadID,
|
343
|
+
isGroup: messageThread.thread_type === "GROUP",
|
344
|
+
senderID: d.message_sender.id,
|
345
|
+
timestamp: d.timestamp_precise,
|
346
|
+
eventType: "change_thread_name",
|
347
|
+
snippet: d.snippet,
|
348
|
+
eventData: { threadName: d.thread_name },
|
349
|
+
|
350
|
+
// @Legacy
|
351
|
+
author: d.message_sender.id,
|
352
|
+
logMessageType: "log:thread-name",
|
353
|
+
logMessageData: { name: d.thread_name }
|
354
|
+
};
|
355
|
+
case "ThreadImageMessage":
|
356
|
+
return {
|
357
|
+
type: "event",
|
358
|
+
messageID: d.message_id,
|
359
|
+
threadID: threadID,
|
360
|
+
isGroup: messageThread.thread_type === "GROUP",
|
361
|
+
senderID: d.message_sender.id,
|
362
|
+
timestamp: d.timestamp_precise,
|
363
|
+
eventType: "change_thread_image",
|
364
|
+
snippet: d.snippet,
|
365
|
+
eventData: d.image_with_metadata == null
|
366
|
+
? {} /* removed image */
|
367
|
+
: {
|
368
|
+
/* image added */
|
369
|
+
threadImage: {
|
370
|
+
attachmentID: d.image_with_metadata.legacy_attachment_id,
|
371
|
+
width: d.image_with_metadata.original_dimensions.x,
|
372
|
+
height: d.image_with_metadata.original_dimensions.y,
|
373
|
+
url: d.image_with_metadata.preview.uri
|
374
|
+
}
|
375
|
+
},
|
376
|
+
|
377
|
+
// @Legacy
|
378
|
+
logMessageType: "log:thread-icon",
|
379
|
+
logMessageData: { thread_icon: d.image_with_metadata ? d.image_with_metadata.preview.uri : null }
|
380
|
+
};
|
381
|
+
case "ParticipantLeftMessage":
|
382
|
+
return {
|
383
|
+
type: "event",
|
384
|
+
messageID: d.message_id,
|
385
|
+
threadID: threadID,
|
386
|
+
isGroup: messageThread.thread_type === "GROUP",
|
387
|
+
senderID: d.message_sender.id,
|
388
|
+
timestamp: d.timestamp_precise,
|
389
|
+
eventType: "remove_participants",
|
390
|
+
snippet: d.snippet,
|
391
|
+
eventData: {
|
392
|
+
// Array of IDs.
|
393
|
+
participantsRemoved: d.participants_removed.map(function (p) {
|
394
|
+
return p.id;
|
395
|
+
})
|
396
|
+
},
|
397
|
+
|
398
|
+
// @Legacy
|
399
|
+
logMessageType: "log:unsubscribe",
|
400
|
+
logMessageData: {
|
401
|
+
leftParticipantFbId: d.participants_removed.map(function (p) {
|
402
|
+
return p.id;
|
403
|
+
})
|
404
|
+
}
|
405
|
+
};
|
406
|
+
case "ParticipantsAddedMessage":
|
407
|
+
return {
|
408
|
+
type: "event",
|
409
|
+
messageID: d.message_id,
|
410
|
+
threadID: threadID,
|
411
|
+
isGroup: messageThread.thread_type === "GROUP",
|
412
|
+
senderID: d.message_sender.id,
|
413
|
+
timestamp: d.timestamp_precise,
|
414
|
+
eventType: "add_participants",
|
415
|
+
snippet: d.snippet,
|
416
|
+
eventData: {
|
417
|
+
// Array of IDs.
|
418
|
+
participantsAdded: d.participants_added.map(function (p) {
|
419
|
+
return p.id;
|
420
|
+
})
|
421
|
+
},
|
422
|
+
|
423
|
+
// @Legacy
|
424
|
+
logMessageType: "log:subscribe",
|
425
|
+
logMessageData: {
|
426
|
+
addedParticipants: d.participants_added.map(function (p) {
|
427
|
+
return p.id;
|
428
|
+
})
|
429
|
+
}
|
430
|
+
};
|
431
|
+
case "VideoCallMessage":
|
432
|
+
return {
|
433
|
+
type: "event",
|
434
|
+
messageID: d.message_id,
|
435
|
+
threadID: threadID,
|
436
|
+
isGroup: messageThread.thread_type === "GROUP",
|
437
|
+
senderID: d.message_sender.id,
|
438
|
+
timestamp: d.timestamp_precise,
|
439
|
+
eventType: "video_call",
|
440
|
+
snippet: d.snippet,
|
441
|
+
|
442
|
+
// @Legacy
|
443
|
+
logMessageType: "other"
|
444
|
+
};
|
445
|
+
case "VoiceCallMessage":
|
446
|
+
return {
|
447
|
+
type: "event",
|
448
|
+
messageID: d.message_id,
|
449
|
+
threadID: threadID,
|
450
|
+
isGroup: messageThread.thread_type === "GROUP",
|
451
|
+
senderID: d.message_sender.id,
|
452
|
+
timestamp: d.timestamp_precise,
|
453
|
+
eventType: "voice_call",
|
454
|
+
snippet: d.snippet,
|
455
|
+
|
456
|
+
// @Legacy
|
457
|
+
logMessageType: "other"
|
458
|
+
};
|
459
|
+
case "GenericAdminTextMessage":
|
460
|
+
return {
|
461
|
+
type: "event",
|
462
|
+
messageID: d.message_id,
|
463
|
+
threadID: threadID,
|
464
|
+
isGroup: messageThread.thread_type === "GROUP",
|
465
|
+
senderID: d.message_sender.id,
|
466
|
+
timestamp: d.timestamp_precise,
|
467
|
+
snippet: d.snippet,
|
468
|
+
eventType: d.extensible_message_admin_text_type.toLowerCase(),
|
469
|
+
eventData: formatEventData(d.extensible_message_admin_text),
|
470
|
+
|
471
|
+
// @Legacy
|
472
|
+
logMessageType: utils.getAdminTextMessageType(
|
473
|
+
d.extensible_message_admin_text_type
|
474
|
+
),
|
475
|
+
logMessageData: d.extensible_message_admin_text // Maybe different?
|
476
|
+
};
|
477
|
+
default:
|
478
|
+
return { error: "Don't know about message type " + d.__typename };
|
479
|
+
}
|
480
|
+
});
|
481
|
+
return messages;
|
482
|
+
}
|
483
|
+
|
484
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
485
|
+
return function getThreadHistoryGraphQL(threadID, amount, timestamp, callback) {
|
486
|
+
var resolveFunc = function () { };
|
487
|
+
var rejectFunc = function () { };
|
488
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
489
|
+
resolveFunc = resolve;
|
490
|
+
rejectFunc = reject;
|
491
|
+
});
|
492
|
+
|
493
|
+
if (!callback) {
|
494
|
+
callback = function (err, data) {
|
495
|
+
if (err) return rejectFunc(err);
|
496
|
+
resolveFunc(data);
|
497
|
+
};
|
498
|
+
}
|
499
|
+
|
500
|
+
// `queries` has to be a string. I couldn't tell from the dev console. This
|
501
|
+
// took me a really long time to figure out. I deserve a cookie for this.
|
502
|
+
var form = {
|
503
|
+
"av": ctx.globalOptions.pageID,
|
504
|
+
queries: JSON.stringify({
|
505
|
+
o0: {
|
506
|
+
// This doc_id was valid on February 2nd 2017.
|
507
|
+
doc_id: "1498317363570230",
|
508
|
+
query_params: {
|
509
|
+
id: threadID,
|
510
|
+
message_limit: amount,
|
511
|
+
load_messages: 1,
|
512
|
+
load_read_receipts: false,
|
513
|
+
before: timestamp
|
514
|
+
}
|
515
|
+
}
|
516
|
+
})
|
517
|
+
};
|
518
|
+
|
519
|
+
defaultFuncs
|
520
|
+
.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
|
521
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
522
|
+
.then(function (resData) {
|
523
|
+
if (resData.error) throw resData;
|
524
|
+
// This returns us an array of things. The last one is the success /
|
525
|
+
// failure one.
|
526
|
+
// @TODO What do we do in this case?
|
527
|
+
if (resData[resData.length - 1].error_results !== 0) throw new Error("There was an error_result.");
|
528
|
+
callback(null, formatMessagesGraphQLResponse(resData[0]));
|
529
|
+
})
|
530
|
+
.catch(function (err) {
|
531
|
+
log.error("getThreadHistoryGraphQL", err);
|
532
|
+
return callback(err);
|
533
|
+
});
|
534
|
+
|
535
|
+
return returnPromise;
|
536
|
+
};
|
537
|
+
};
|