alicezetion 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. package/.cache/replit/__replit_disk_meta.json +1 -1
  2. package/.cache/replit/nix/env.json +1 -1
  3. package/alice/addExternalModule.js +19 -19
  4. package/alice/addUserToGroup.js +113 -113
  5. package/alice/changeAdminStatus.js +79 -79
  6. package/alice/changeArchivedStatus.js +55 -55
  7. package/alice/changeBio.js +77 -77
  8. package/alice/changeBlockedStatus.js +47 -47
  9. package/alice/changeGroupImage.js +129 -129
  10. package/alice/changeNickname.js +59 -59
  11. package/alice/changeThreadColor.js +71 -71
  12. package/alice/changeThreadEmoji.js +55 -55
  13. package/alice/{sendMessage.js → chat.js} +459 -459
  14. package/alice/createNewGroup.js +86 -86
  15. package/alice/createPoll.js +71 -71
  16. package/alice/deleteMessage.js +56 -56
  17. package/alice/deleteThread.js +56 -56
  18. package/alice/forwardAttachment.js +60 -60
  19. package/alice/getCurrentUserID.js +7 -7
  20. package/alice/getEmojiUrl.js +29 -29
  21. package/alice/getFriendsList.js +84 -84
  22. package/alice/getThreadHistory.js +645 -645
  23. package/alice/getThreadHistoryDeprecated.js +93 -93
  24. package/alice/getThreadInfo.js +206 -206
  25. package/alice/getThreadInfoDeprecated.js +80 -80
  26. package/alice/getThreadList.js +238 -238
  27. package/alice/getThreadListDeprecated.js +75 -75
  28. package/alice/getThreadPictures.js +79 -79
  29. package/alice/getUserID.js +66 -66
  30. package/alice/getUserInfo.js +72 -72
  31. package/alice/handleFriendRequest.js +61 -61
  32. package/alice/handleMessageRequest.js +65 -65
  33. package/alice/httpGet.js +52 -52
  34. package/alice/httpPost.js +52 -52
  35. package/alice/listenMqtt.js +789 -789
  36. package/alice/logout.js +75 -75
  37. package/alice/markAsDelivered.js +58 -58
  38. package/alice/markAsRead.js +80 -80
  39. package/alice/markAsSeen.js +59 -59
  40. package/alice/muteThread.js +52 -52
  41. package/alice/{setMessageReaction.js → react.js} +117 -117
  42. package/alice/removeUserFromGroup.js +79 -79
  43. package/alice/resolvePhotoUrl.js +45 -45
  44. package/alice/searchForThread.js +53 -53
  45. package/alice/{markAsReadAll.js → seen.js} +49 -49
  46. package/alice/sendTypingIndicator.js +103 -103
  47. package/alice/setPostReaction.js +76 -76
  48. package/alice/setTitle.js +86 -86
  49. package/alice/threadColors.js +57 -57
  50. package/alice/unfriend.js +52 -52
  51. package/alice/unsendMessage.js +49 -49
  52. package/index.js +604 -604
  53. package/package.json +74 -77
  54. package/test/data/shareAttach.js +146 -0
  55. package/test/data/something.mov +0 -0
  56. package/test/data/test.png +0 -0
  57. package/test/data/test.txt +7 -0
  58. package/test/example-config.json +18 -0
  59. package/test/test-page.js +140 -0
  60. package/test/test.js +385 -0
  61. package/utils.js +1357 -1359
  62. package/.travis.yml +0 -6
@@ -1,93 +1,93 @@
1
- "use strict";
2
-
3
- var utils = require("../utils");
4
- var log = require("npmlog");
5
-
6
- module.exports = function(defaultFuncs, api, ctx) {
7
- return function getThreadHistory(threadID, amount, timestamp, callback) {
8
- var resolveFunc = function(){};
9
- var rejectFunc = function(){};
10
- var returnPromise = new Promise(function (resolve, reject) {
11
- resolveFunc = resolve;
12
- rejectFunc = reject;
13
- });
14
-
15
- if (!callback) {
16
- callback = function (err, friendList) {
17
- if (err) {
18
- return rejectFunc(err);
19
- }
20
- resolveFunc(friendList);
21
- };
22
- }
23
-
24
- if (!callback) {
25
- throw { error: "getThreadHistory: need callback" };
26
- }
27
-
28
- var form = {
29
- client: "mercury"
30
- };
31
-
32
- api.getUserInfo(threadID, function(err, res) {
33
- if (err) {
34
- return callback(err);
35
- }
36
- var key = Object.keys(res).length > 0 ? "user_ids" : "thread_fbids";
37
- form["messages[" + key + "][" + threadID + "][offset]"] = 0;
38
- form["messages[" + key + "][" + threadID + "][timestamp]"] = timestamp;
39
- form["messages[" + key + "][" + threadID + "][limit]"] = amount;
40
-
41
- if (ctx.globalOptions.pageID)
42
- form.request_user_id = ctx.globalOptions.pageID;
43
-
44
- defaultFuncs
45
- .post(
46
- "https://www.facebook.com/ajax/mercury/thread_info.php",
47
- ctx.jar,
48
- form
49
- )
50
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
51
- .then(function(resData) {
52
- if (resData.error) {
53
- throw resData;
54
- } else if (!resData.payload) {
55
- throw { error: "Could not retrieve thread history." };
56
- }
57
-
58
- // Asking for message history from a thread with no message history
59
- // will return undefined for actions here
60
- if (!resData.payload.actions) {
61
- resData.payload.actions = [];
62
- }
63
-
64
- var userIDs = {};
65
- resData.payload.actions.forEach(function(v) {
66
- userIDs[v.author.split(":").pop()] = "";
67
- });
68
-
69
- api.getUserInfo(Object.keys(userIDs), function(err, data) {
70
- if (err) return callback(err); //callback({error: "Could not retrieve user information in getThreadHistory."});
71
-
72
- resData.payload.actions.forEach(function(v) {
73
- var sender = data[v.author.split(":").pop()];
74
- if (sender) v.sender_name = sender.name;
75
- else v.sender_name = "Facebook User";
76
- v.sender_fbid = v.author;
77
- delete v.author;
78
- });
79
-
80
- callback(
81
- null,
82
- resData.payload.actions.map(utils.formatHistoryMessage)
83
- );
84
- });
85
- })
86
- .catch(function(err) {
87
- log.error("getThreadHistory", err);
88
- return callback(err);
89
- });
90
- });
91
- return returnPromise;
92
- };
93
- };
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+
6
+ module.exports = function(defaultFuncs, api, ctx) {
7
+ return function getThreadHistory(threadID, amount, timestamp, callback) {
8
+ var resolveFunc = function(){};
9
+ var rejectFunc = function(){};
10
+ var returnPromise = new Promise(function (resolve, reject) {
11
+ resolveFunc = resolve;
12
+ rejectFunc = reject;
13
+ });
14
+
15
+ if (!callback) {
16
+ callback = function (err, friendList) {
17
+ if (err) {
18
+ return rejectFunc(err);
19
+ }
20
+ resolveFunc(friendList);
21
+ };
22
+ }
23
+
24
+ if (!callback) {
25
+ throw { error: "getThreadHistory: need callback" };
26
+ }
27
+
28
+ var form = {
29
+ client: "mercury"
30
+ };
31
+
32
+ api.getUserInfo(threadID, function(err, res) {
33
+ if (err) {
34
+ return callback(err);
35
+ }
36
+ var key = Object.keys(res).length > 0 ? "user_ids" : "thread_fbids";
37
+ form["messages[" + key + "][" + threadID + "][offset]"] = 0;
38
+ form["messages[" + key + "][" + threadID + "][timestamp]"] = timestamp;
39
+ form["messages[" + key + "][" + threadID + "][limit]"] = amount;
40
+
41
+ if (ctx.globalOptions.pageID)
42
+ form.request_user_id = ctx.globalOptions.pageID;
43
+
44
+ defaultFuncs
45
+ .post(
46
+ "https://www.facebook.com/ajax/mercury/thread_info.php",
47
+ ctx.jar,
48
+ form
49
+ )
50
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
51
+ .then(function(resData) {
52
+ if (resData.error) {
53
+ throw resData;
54
+ } else if (!resData.payload) {
55
+ throw { error: "Could not retrieve thread history." };
56
+ }
57
+
58
+ // Asking for message history from a thread with no message history
59
+ // will return undefined for actions here
60
+ if (!resData.payload.actions) {
61
+ resData.payload.actions = [];
62
+ }
63
+
64
+ var userIDs = {};
65
+ resData.payload.actions.forEach(function(v) {
66
+ userIDs[v.author.split(":").pop()] = "";
67
+ });
68
+
69
+ api.getUserInfo(Object.keys(userIDs), function(err, data) {
70
+ if (err) return callback(err); //callback({error: "Could not retrieve user information in getThreadHistory."});
71
+
72
+ resData.payload.actions.forEach(function(v) {
73
+ var sender = data[v.author.split(":").pop()];
74
+ if (sender) v.sender_name = sender.name;
75
+ else v.sender_name = "Facebook User";
76
+ v.sender_fbid = v.author;
77
+ delete v.author;
78
+ });
79
+
80
+ callback(
81
+ null,
82
+ resData.payload.actions.map(utils.formatHistoryMessage)
83
+ );
84
+ });
85
+ })
86
+ .catch(function(err) {
87
+ log.error("getThreadHistory", err);
88
+ return callback(err);
89
+ });
90
+ });
91
+ return returnPromise;
92
+ };
93
+ };
@@ -1,206 +1,206 @@
1
- "use strict";
2
-
3
- var utils = require("../utils");
4
- var log = require("npmlog");
5
-
6
- function formatEventReminders(reminder) {
7
- return {
8
- reminderID: reminder.id,
9
- eventCreatorID: reminder.lightweight_event_creator.id,
10
- time: reminder.time,
11
- eventType: reminder.lightweight_event_type.toLowerCase(),
12
- locationName: reminder.location_name,
13
- // @TODO verify this
14
- locationCoordinates: reminder.location_coordinates,
15
- locationPage: reminder.location_page,
16
- eventStatus: reminder.lightweight_event_status.toLowerCase(),
17
- note: reminder.note,
18
- repeatMode: reminder.repeat_mode.toLowerCase(),
19
- eventTitle: reminder.event_title,
20
- triggerMessage: reminder.trigger_message,
21
- secondsToNotifyBefore: reminder.seconds_to_notify_before,
22
- allowsRsvp: reminder.allows_rsvp,
23
- relatedEvent: reminder.related_event,
24
- members: reminder.event_reminder_members.edges.map(function(member) {
25
- return {
26
- memberID: member.node.id,
27
- state: member.guest_list_state.toLowerCase()
28
- };
29
- })
30
- };
31
- }
32
-
33
- function formatThreadGraphQLResponse(data) {
34
- try{
35
- var messageThread = data.o0.data.message_thread;
36
- } catch (err){
37
- console.error("GetThreadInfoGraphQL", "Can't get this thread info!");
38
- return {err: err};
39
- }
40
- var threadID = messageThread.thread_key.thread_fbid
41
- ? messageThread.thread_key.thread_fbid
42
- : messageThread.thread_key.other_user_id;
43
-
44
- // Remove me
45
- var lastM = messageThread.last_message;
46
- var snippetID =
47
- lastM &&
48
- lastM.nodes &&
49
- lastM.nodes[0] &&
50
- lastM.nodes[0].message_sender &&
51
- lastM.nodes[0].message_sender.messaging_actor
52
- ? lastM.nodes[0].message_sender.messaging_actor.id
53
- : null;
54
- var snippetText =
55
- lastM && lastM.nodes && lastM.nodes[0] ? lastM.nodes[0].snippet : null;
56
- var lastR = messageThread.last_read_receipt;
57
- var lastReadTimestamp =
58
- lastR && lastR.nodes && lastR.nodes[0] && lastR.nodes[0].timestamp_precise
59
- ? lastR.nodes[0].timestamp_precise
60
- : null;
61
-
62
- return {
63
- threadID: threadID,
64
- threadName: messageThread.name,
65
- participantIDs: messageThread.all_participants.edges.map(d => d.node.messaging_actor.id),
66
- userInfo: messageThread.all_participants.edges.map(d => ({
67
- id: d.node.messaging_actor.id,
68
- name: d.node.messaging_actor.name,
69
- firstName: d.node.messaging_actor.short_name,
70
- vanity: d.node.messaging_actor.username,
71
- thumbSrc: d.node.messaging_actor.big_image_src.uri,
72
- profileUrl: d.node.messaging_actor.big_image_src.uri,
73
- gender: d.node.messaging_actor.gender,
74
- type: d.node.messaging_actor.__typename,
75
- isFriend: d.node.messaging_actor.is_viewer_friend,
76
- isBirthday: !!d.node.messaging_actor.is_birthday //not sure?
77
- })),
78
- unreadCount: messageThread.unread_count,
79
- messageCount: messageThread.messages_count,
80
- timestamp: messageThread.updated_time_precise,
81
- muteUntil: messageThread.mute_until,
82
- isGroup: messageThread.thread_type == "GROUP",
83
- isSubscribed: messageThread.is_viewer_subscribed,
84
- isArchived: messageThread.has_viewer_archived,
85
- folder: messageThread.folder,
86
- cannotReplyReason: messageThread.cannot_reply_reason,
87
- eventReminders: messageThread.event_reminders
88
- ? messageThread.event_reminders.nodes.map(formatEventReminders)
89
- : null,
90
- emoji: messageThread.customization_info
91
- ? messageThread.customization_info.emoji
92
- : null,
93
- color:
94
- messageThread.customization_info &&
95
- messageThread.customization_info.outgoing_bubble_color
96
- ? messageThread.customization_info.outgoing_bubble_color.slice(2)
97
- : null,
98
- nicknames:
99
- messageThread.customization_info &&
100
- messageThread.customization_info.participant_customizations
101
- ? messageThread.customization_info.participant_customizations.reduce(
102
- function(res, val) {
103
- if (val.nickname) res[val.participant_id] = val.nickname;
104
- return res;
105
- },
106
- {}
107
- )
108
- : {},
109
- adminIDs: messageThread.thread_admins,
110
- approvalMode: Boolean(messageThread.approval_mode),
111
- approvalQueue: messageThread.group_approval_queue.nodes.map(a => ({
112
- inviterID: a.inviter.id,
113
- requesterID: a.requester.id,
114
- timestamp: a.request_timestamp,
115
- request_source: a.request_source // @Undocumented
116
- })),
117
-
118
- // @Undocumented
119
- reactionsMuteMode: messageThread.reactions_mute_mode.toLowerCase(),
120
- mentionsMuteMode: messageThread.mentions_mute_mode.toLowerCase(),
121
- isPinProtected: messageThread.is_pin_protected,
122
- relatedPageThread: messageThread.related_page_thread,
123
-
124
- // @Legacy
125
- name: messageThread.name,
126
- snippet: snippetText,
127
- snippetSender: snippetID,
128
- snippetAttachments: [],
129
- serverTimestamp: messageThread.updated_time_precise,
130
- imageSrc: messageThread.image ? messageThread.image.uri : null,
131
- isCanonicalUser: messageThread.is_canonical_neo_user,
132
- isCanonical: messageThread.thread_type != "GROUP",
133
- recipientsLoadable: true,
134
- hasEmailParticipant: false,
135
- readOnly: false,
136
- canReply: messageThread.cannot_reply_reason == null,
137
- lastMessageTimestamp: messageThread.last_message
138
- ? messageThread.last_message.timestamp_precise
139
- : null,
140
- lastMessageType: "message",
141
- lastReadTimestamp: lastReadTimestamp,
142
- threadType: messageThread.thread_type == "GROUP" ? 2 : 1
143
- };
144
- }
145
-
146
- module.exports = function(defaultFuncs, api, ctx) {
147
- return function getThreadInfoGraphQL(threadID, callback) {
148
- var resolveFunc = function(){};
149
- var rejectFunc = function(){};
150
- var returnPromise = new Promise(function (resolve, reject) {
151
- resolveFunc = resolve;
152
- rejectFunc = reject;
153
- });
154
-
155
- if (utils.getType(callback) != "Function" && utils.getType(callback) != "AsyncFunction") {
156
- callback = function (err, data) {
157
- if (err) {
158
- return rejectFunc(err);
159
- }
160
- resolveFunc(data);
161
- };
162
- }
163
-
164
- // `queries` has to be a string. I couldn't tell from the dev console. This
165
- // took me a really long time to figure out. I deserve a cookie for this.
166
- var form = {
167
- queries: JSON.stringify({
168
- o0: {
169
- // This doc_id is valid as of July 20th, 2020
170
- doc_id: "3449967031715030",
171
- query_params: {
172
- id: threadID,
173
- message_limit: 0,
174
- load_messages: false,
175
- load_read_receipts: false,
176
- before: null
177
- }
178
- }
179
- }),
180
- batch_name: "MessengerGraphQLThreadFetcher"
181
- };
182
-
183
- defaultFuncs
184
- .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
185
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
186
- .then(function(resData) {
187
- if (resData.error) {
188
- throw resData;
189
- }
190
- // This returns us an array of things. The last one is the success /
191
- // failure one.
192
- // @TODO What do we do in this case?
193
- if (resData[resData.length - 1].error_results !== 0) {
194
- console.error("GetThreadInfo", "Well darn there was an error_result");
195
- }
196
-
197
- callback(null, formatThreadGraphQLResponse(resData[0]));
198
- })
199
- .catch(function(err) {
200
- log.error("getThreadInfoGraphQL", err);
201
- return callback(err);
202
- });
203
-
204
- return returnPromise;
205
- };
206
- };
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+
6
+ function formatEventReminders(reminder) {
7
+ return {
8
+ reminderID: reminder.id,
9
+ eventCreatorID: reminder.lightweight_event_creator.id,
10
+ time: reminder.time,
11
+ eventType: reminder.lightweight_event_type.toLowerCase(),
12
+ locationName: reminder.location_name,
13
+ // @TODO verify this
14
+ locationCoordinates: reminder.location_coordinates,
15
+ locationPage: reminder.location_page,
16
+ eventStatus: reminder.lightweight_event_status.toLowerCase(),
17
+ note: reminder.note,
18
+ repeatMode: reminder.repeat_mode.toLowerCase(),
19
+ eventTitle: reminder.event_title,
20
+ triggerMessage: reminder.trigger_message,
21
+ secondsToNotifyBefore: reminder.seconds_to_notify_before,
22
+ allowsRsvp: reminder.allows_rsvp,
23
+ relatedEvent: reminder.related_event,
24
+ members: reminder.event_reminder_members.edges.map(function(member) {
25
+ return {
26
+ memberID: member.node.id,
27
+ state: member.guest_list_state.toLowerCase()
28
+ };
29
+ })
30
+ };
31
+ }
32
+
33
+ function formatThreadGraphQLResponse(data) {
34
+ try{
35
+ var messageThread = data.o0.data.message_thread;
36
+ } catch (err){
37
+ console.error("GetThreadInfoGraphQL", "Can't get this thread info!");
38
+ return {err: err};
39
+ }
40
+ var threadID = messageThread.thread_key.thread_fbid
41
+ ? messageThread.thread_key.thread_fbid
42
+ : messageThread.thread_key.other_user_id;
43
+
44
+ // Remove me
45
+ var lastM = messageThread.last_message;
46
+ var snippetID =
47
+ lastM &&
48
+ lastM.nodes &&
49
+ lastM.nodes[0] &&
50
+ lastM.nodes[0].message_sender &&
51
+ lastM.nodes[0].message_sender.messaging_actor
52
+ ? lastM.nodes[0].message_sender.messaging_actor.id
53
+ : null;
54
+ var snippetText =
55
+ lastM && lastM.nodes && lastM.nodes[0] ? lastM.nodes[0].snippet : null;
56
+ var lastR = messageThread.last_read_receipt;
57
+ var lastReadTimestamp =
58
+ lastR && lastR.nodes && lastR.nodes[0] && lastR.nodes[0].timestamp_precise
59
+ ? lastR.nodes[0].timestamp_precise
60
+ : null;
61
+
62
+ return {
63
+ threadID: threadID,
64
+ threadName: messageThread.name,
65
+ participantIDs: messageThread.all_participants.edges.map(d => d.node.messaging_actor.id),
66
+ userInfo: messageThread.all_participants.edges.map(d => ({
67
+ id: d.node.messaging_actor.id,
68
+ name: d.node.messaging_actor.name,
69
+ firstName: d.node.messaging_actor.short_name,
70
+ vanity: d.node.messaging_actor.username,
71
+ thumbSrc: d.node.messaging_actor.big_image_src.uri,
72
+ profileUrl: d.node.messaging_actor.big_image_src.uri,
73
+ gender: d.node.messaging_actor.gender,
74
+ type: d.node.messaging_actor.__typename,
75
+ isFriend: d.node.messaging_actor.is_viewer_friend,
76
+ isBirthday: !!d.node.messaging_actor.is_birthday //not sure?
77
+ })),
78
+ unreadCount: messageThread.unread_count,
79
+ messageCount: messageThread.messages_count,
80
+ timestamp: messageThread.updated_time_precise,
81
+ muteUntil: messageThread.mute_until,
82
+ isGroup: messageThread.thread_type == "GROUP",
83
+ isSubscribed: messageThread.is_viewer_subscribed,
84
+ isArchived: messageThread.has_viewer_archived,
85
+ folder: messageThread.folder,
86
+ cannotReplyReason: messageThread.cannot_reply_reason,
87
+ eventReminders: messageThread.event_reminders
88
+ ? messageThread.event_reminders.nodes.map(formatEventReminders)
89
+ : null,
90
+ emoji: messageThread.customization_info
91
+ ? messageThread.customization_info.emoji
92
+ : null,
93
+ color:
94
+ messageThread.customization_info &&
95
+ messageThread.customization_info.outgoing_bubble_color
96
+ ? messageThread.customization_info.outgoing_bubble_color.slice(2)
97
+ : null,
98
+ nicknames:
99
+ messageThread.customization_info &&
100
+ messageThread.customization_info.participant_customizations
101
+ ? messageThread.customization_info.participant_customizations.reduce(
102
+ function(res, val) {
103
+ if (val.nickname) res[val.participant_id] = val.nickname;
104
+ return res;
105
+ },
106
+ {}
107
+ )
108
+ : {},
109
+ adminIDs: messageThread.thread_admins,
110
+ approvalMode: Boolean(messageThread.approval_mode),
111
+ approvalQueue: messageThread.group_approval_queue.nodes.map(a => ({
112
+ inviterID: a.inviter.id,
113
+ requesterID: a.requester.id,
114
+ timestamp: a.request_timestamp,
115
+ request_source: a.request_source // @Undocumented
116
+ })),
117
+
118
+ // @Undocumented
119
+ reactionsMuteMode: messageThread.reactions_mute_mode.toLowerCase(),
120
+ mentionsMuteMode: messageThread.mentions_mute_mode.toLowerCase(),
121
+ isPinProtected: messageThread.is_pin_protected,
122
+ relatedPageThread: messageThread.related_page_thread,
123
+
124
+ // @Legacy
125
+ name: messageThread.name,
126
+ snippet: snippetText,
127
+ snippetSender: snippetID,
128
+ snippetAttachments: [],
129
+ serverTimestamp: messageThread.updated_time_precise,
130
+ imageSrc: messageThread.image ? messageThread.image.uri : null,
131
+ isCanonicalUser: messageThread.is_canonical_neo_user,
132
+ isCanonical: messageThread.thread_type != "GROUP",
133
+ recipientsLoadable: true,
134
+ hasEmailParticipant: false,
135
+ readOnly: false,
136
+ canReply: messageThread.cannot_reply_reason == null,
137
+ lastMessageTimestamp: messageThread.last_message
138
+ ? messageThread.last_message.timestamp_precise
139
+ : null,
140
+ lastMessageType: "message",
141
+ lastReadTimestamp: lastReadTimestamp,
142
+ threadType: messageThread.thread_type == "GROUP" ? 2 : 1
143
+ };
144
+ }
145
+
146
+ module.exports = function(defaultFuncs, api, ctx) {
147
+ return function getThreadInfoGraphQL(threadID, callback) {
148
+ var resolveFunc = function(){};
149
+ var rejectFunc = function(){};
150
+ var returnPromise = new Promise(function (resolve, reject) {
151
+ resolveFunc = resolve;
152
+ rejectFunc = reject;
153
+ });
154
+
155
+ if (utils.getType(callback) != "Function" && utils.getType(callback) != "AsyncFunction") {
156
+ callback = function (err, data) {
157
+ if (err) {
158
+ return rejectFunc(err);
159
+ }
160
+ resolveFunc(data);
161
+ };
162
+ }
163
+
164
+ // `queries` has to be a string. I couldn't tell from the dev console. This
165
+ // took me a really long time to figure out. I deserve a cookie for this.
166
+ var form = {
167
+ queries: JSON.stringify({
168
+ o0: {
169
+ // This doc_id is valid as of July 20th, 2020
170
+ doc_id: "3449967031715030",
171
+ query_params: {
172
+ id: threadID,
173
+ message_limit: 0,
174
+ load_messages: false,
175
+ load_read_receipts: false,
176
+ before: null
177
+ }
178
+ }
179
+ }),
180
+ batch_name: "MessengerGraphQLThreadFetcher"
181
+ };
182
+
183
+ defaultFuncs
184
+ .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
185
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
186
+ .then(function(resData) {
187
+ if (resData.error) {
188
+ throw resData;
189
+ }
190
+ // This returns us an array of things. The last one is the success /
191
+ // failure one.
192
+ // @TODO What do we do in this case?
193
+ if (resData[resData.length - 1].error_results !== 0) {
194
+ console.error("GetThreadInfo", "Well darn there was an error_result");
195
+ }
196
+
197
+ callback(null, formatThreadGraphQLResponse(resData[0]));
198
+ })
199
+ .catch(function(err) {
200
+ log.error("getThreadInfoGraphQL", err);
201
+ return callback(err);
202
+ });
203
+
204
+ return returnPromise;
205
+ };
206
+ };