node-ainzfb-new 1.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. package/.gitattributes +2 -0
  2. package/.github/dependabot.yml +11 -0
  3. package/.github/workflows/nodejs.yml +26 -0
  4. package/.github/workflows/npmpublish.yml +30 -0
  5. package/CHANGELOG.md +2 -0
  6. package/DOCS.md +1738 -0
  7. package/Extra/Database/index.js +399 -0
  8. package/Extra/Database/methods.js +286 -0
  9. package/Extra/ExtraAddons.js +213 -0
  10. package/Extra/ExtraGetThread.js +1 -0
  11. package/Extra/ExtraUptimeRobot.js +59 -0
  12. package/Extra/PM2/ecosystem.config.js +23 -0
  13. package/Extra/Src/Last-Run.js +48 -0
  14. package/LICENSE-MIT +21 -0
  15. package/Language/index.json +151 -0
  16. package/README.md +227 -0
  17. package/StateCrypt.js +22 -0
  18. package/broadcast.js +42 -0
  19. package/deleted.js +587 -0
  20. package/index-backup.js +1089 -0
  21. package/index.js +583 -0
  22. package/logger.js +21 -0
  23. package/package.json +90 -0
  24. package/src/addExternalModule.js +16 -0
  25. package/src/addUserToGroup.js +78 -0
  26. package/src/changeAdminStatus.js +79 -0
  27. package/src/changeArchivedStatus.js +41 -0
  28. package/src/changeBio.js +65 -0
  29. package/src/changeBlockedStatus.js +36 -0
  30. package/src/changeGroupImage.js +106 -0
  31. package/src/changeNickname.js +45 -0
  32. package/src/changeThreadColor.js +62 -0
  33. package/src/changeThreadEmoji.js +42 -0
  34. package/src/createNewGroup.js +70 -0
  35. package/src/createPoll.js +60 -0
  36. package/src/deleteMessage.js +45 -0
  37. package/src/deleteThread.js +43 -0
  38. package/src/forwardAttachment.js +48 -0
  39. package/src/getAccessToken.js +32 -0
  40. package/src/getCurrentUserID.js +7 -0
  41. package/src/getEmojiUrl.js +27 -0
  42. package/src/getFriendsList.js +73 -0
  43. package/src/getMessage.js +80 -0
  44. package/src/getThreadHistory.js +537 -0
  45. package/src/getThreadHistoryDeprecated.js +71 -0
  46. package/src/getThreadInfo.js +197 -0
  47. package/src/getThreadInfoDeprecated.js +56 -0
  48. package/src/getThreadList.js +213 -0
  49. package/src/getThreadListDeprecated.js +46 -0
  50. package/src/getThreadPictures.js +59 -0
  51. package/src/getUserID.js +62 -0
  52. package/src/getUserInfo.js +65 -0
  53. package/src/getUserInfoV2.js +35 -0
  54. package/src/handleFriendRequest.js +46 -0
  55. package/src/handleMessageRequest.js +49 -0
  56. package/src/httpGet.js +49 -0
  57. package/src/httpPost.js +48 -0
  58. package/src/httpPostFormData.js +41 -0
  59. package/src/listenMqtt.js +633 -0
  60. package/src/logout.js +68 -0
  61. package/src/markAsDelivered.js +48 -0
  62. package/src/markAsRead.js +70 -0
  63. package/src/markAsReadAll.js +43 -0
  64. package/src/markAsSeen.js +51 -0
  65. package/src/muteThread.js +47 -0
  66. package/src/removeUserFromGroup.js +49 -0
  67. package/src/resolvePhotoUrl.js +37 -0
  68. package/src/searchForThread.js +43 -0
  69. package/src/sendMessage.js +342 -0
  70. package/src/sendTypingIndicator.js +80 -0
  71. package/src/setMessageReaction.js +109 -0
  72. package/src/setPostReaction.js +102 -0
  73. package/src/setTitle.js +74 -0
  74. package/src/threadColors.js +39 -0
  75. package/src/unfriend.js +43 -0
  76. package/src/unsendMessage.js +40 -0
  77. package/utils.js +1284 -0
@@ -0,0 +1,342 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Được Fix Hay Làm Màu Bởi: @KanzuWakazaki
5
+ * 19/2/2022
6
+ */
7
+
8
+ var utils = require("../utils");
9
+ var log = require("npmlog");
10
+ var bluebird = require("bluebird");
11
+
12
+ var allowedProperties = {
13
+ attachment: true,
14
+ url: true,
15
+ sticker: true,
16
+ emoji: true,
17
+ emojiSize: true,
18
+ body: true,
19
+ mentions: true,
20
+ location: true,
21
+ };
22
+
23
+ module.exports = function (defaultFuncs, api, ctx) {
24
+ function uploadAttachment(attachments, callback) {
25
+ var uploads = [];
26
+
27
+ // create an array of promises
28
+ for (var i = 0; i < attachments.length; i++) {
29
+ if (!utils.isReadableStream(attachments[i])) throw { error: "Attachment should be a readable stream and not " + utils.getType(attachments[i]) + "." };
30
+ var form = {
31
+ upload_1024: attachments[i],
32
+ voice_clip: "true"
33
+ };
34
+
35
+ uploads.push(
36
+ defaultFuncs
37
+ .postFormData("https://upload.facebook.com/ajax/mercury/upload.php", ctx.jar, form, {})
38
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
39
+ .then(function (resData) {
40
+ if (resData.error) throw resData;
41
+ // We have to return the data unformatted unless we want to change it
42
+ // back in sendMessage.
43
+ return resData.payload.metadata[0];
44
+ })
45
+ );
46
+ }
47
+
48
+ // resolve all promises
49
+ bluebird
50
+ .all(uploads)
51
+ .then(resData => callback(null, resData)
52
+ )
53
+ .catch(function (err) {
54
+ log.error("uploadAttachment", err);
55
+ return callback(err);
56
+ });
57
+ }
58
+
59
+ function getUrl(url, callback) {
60
+ var form = {
61
+ image_height: 960,
62
+ image_width: 960,
63
+ uri: url
64
+ };
65
+
66
+ defaultFuncs
67
+ .post("https://www.facebook.com/message_share_attachment/fromURI/", ctx.jar, form)
68
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
69
+ .then(function (resData) {
70
+ if (resData.error) return callback(resData);
71
+ if (!resData.payload) return callback({ error: "Invalid url" });
72
+ callback(null, resData.payload.share_data.share_params);
73
+ })
74
+ .catch(function (err) {
75
+ log.error("getUrl", err);
76
+ return callback(err);
77
+ });
78
+ }
79
+
80
+ function sendContent(form, threadID, isSingleUser, messageAndOTID, callback) {
81
+ // There are three cases here:
82
+ // 1. threadID is of type array, where we're starting a new group chat with users
83
+ // specified in the array.
84
+ // 2. User is sending a message to a specific user.
85
+ // 3. No additional form params and the message goes to an existing group chat.
86
+ if (utils.getType(threadID) === "Array") {
87
+ for (var i = 0; i < threadID.length; i++) form["specific_to_list[" + i + "]"] = "fbid:" + threadID[i];
88
+ form["specific_to_list[" + threadID.length + "]"] = "fbid:" + ctx.userID;
89
+ form["client_thread_id"] = "root:" + messageAndOTID;
90
+ log.info("sendMessage", "Sending message to multiple users: " + threadID);
91
+ }
92
+ else {
93
+ // This means that threadID is the id of a user, and the chat
94
+ // is a single person chat
95
+ if (isSingleUser) {
96
+ form["specific_to_list[0]"] = "fbid:" + threadID;
97
+ form["specific_to_list[1]"] = "fbid:" + ctx.userID;
98
+ form["other_user_fbid"] = threadID;
99
+ }
100
+ else form["thread_fbid"] = threadID;
101
+ }
102
+
103
+ if (ctx.globalOptions.pageID) {
104
+ form["author"] = "fbid:" + ctx.globalOptions.pageID;
105
+ form["specific_to_list[1]"] = "fbid:" + ctx.globalOptions.pageID;
106
+ form["creator_info[creatorID]"] = ctx.userID;
107
+ form["creator_info[creatorType]"] = "direct_admin";
108
+ form["creator_info[labelType]"] = "sent_message";
109
+ form["creator_info[pageID]"] = ctx.globalOptions.pageID;
110
+ form["request_user_id"] = ctx.globalOptions.pageID;
111
+ form["creator_info[profileURI]"] = "https://www.facebook.com/profile.php?id=" + ctx.userID;
112
+ }
113
+
114
+ defaultFuncs
115
+ .post("https://www.facebook.com/messaging/send/", ctx.jar, form)
116
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
117
+ .then(function (resData) {
118
+ if (!resData) return callback({ error: "Send message failed." });
119
+ if (resData.error) {
120
+ if (resData.error === 1545012) log.warn("sendMessage", "Got error 1545012. This might mean that you're not part of the conversation " + threadID);
121
+ return callback(resData);
122
+ }
123
+
124
+ var messageInfo = resData.payload.actions.reduce(function (p, v) {
125
+ return (
126
+ {
127
+ threadID: v.thread_fbid,
128
+ messageID: v.message_id,
129
+ timestamp: v.timestamp
130
+ } || p
131
+ );
132
+ }, null);
133
+ return callback(null, messageInfo);
134
+ })
135
+ .catch(function (err) {
136
+ log.error("sendMessage", err);
137
+ if (utils.getType(err) == "Object" && err.error === "Not logged in.") ctx.loggedIn = false;
138
+ return callback(err);
139
+ });
140
+ }
141
+
142
+ function send(form, threadID, messageAndOTID, callback, isGroup) {
143
+ // đôi lời từ ai đó :v
144
+ // cái này chỉ fix send ko được tin nhắn thôi chứ i cũng đôn nâu cách fix lắm nên là có gì ae fix giùm nha kkk
145
+ if (utils.getType(threadID) === "Array") sendContent(form, threadID, false, messageAndOTID, callback);
146
+ else {
147
+ var THREADFIX = "ThreadID".replace("ThreadID",threadID); // i cũng đôn nâu
148
+ if (THREADFIX.length <= 15 || global.isUser.includes(threadID)) sendContent(form, threadID, !isGroup, messageAndOTID, callback);
149
+ else if (THREADFIX.length >= 15 && THREADFIX.indexOf(1) != 0 || global.isThread.includes(threadID)) sendContent(form, threadID, threadID.length === 15, messageAndOTID, callback);
150
+ else {
151
+ try {
152
+ var { getInfo } = require('../Extra/ExtraAddons');
153
+ getInfo(threadID)
154
+ .then(_ => {
155
+ global.isUser.push(threadID);
156
+ sendContent(form, threadID, !isGroup, messageAndOTID, callback)
157
+ })
158
+ .catch(function(_) {
159
+ global.isThread.push(threadID)
160
+ sendContent(form, threadID, threadID.length === 15, messageAndOTID, callback);
161
+ })
162
+ }
163
+ catch (e) {
164
+ sendContent(form, threadID, threadID.length === 15, messageAndOTID, callback)
165
+ }
166
+ }
167
+ }
168
+ }
169
+
170
+ function handleUrl(msg, form, callback, cb) {
171
+ if (msg.url) {
172
+ form["shareable_attachment[share_type]"] = "100";
173
+ getUrl(msg.url, function (err, params) {
174
+ if (err) return callback(err);
175
+ form["shareable_attachment[share_params]"] = params;
176
+ cb();
177
+ });
178
+ }
179
+ else cb();
180
+ }
181
+
182
+ function handleLocation(msg, form, callback, cb) {
183
+ if (msg.location) {
184
+ if (msg.location.latitude == null || msg.location.longitude == null) return callback({ error: "location property needs both latitude and longitude" });
185
+ form["location_attachment[coordinates][latitude]"] = msg.location.latitude;
186
+ form["location_attachment[coordinates][longitude]"] = msg.location.longitude;
187
+ form["location_attachment[is_current_location]"] = !!msg.location.current;
188
+ }
189
+ cb();
190
+ }
191
+
192
+ function handleSticker(msg, form, callback, cb) {
193
+ if (msg.sticker) form["sticker_id"] = msg.sticker;
194
+ cb();
195
+ }
196
+
197
+ function handleEmoji(msg, form, callback, cb) {
198
+ if (msg.emojiSize != null && msg.emoji == null) return callback({ error: "emoji property is empty" });
199
+ if (msg.emoji) {
200
+ if (msg.emojiSize == null) msg.emojiSize = "medium";
201
+ if (msg.emojiSize != "small" && msg.emojiSize != "medium" && msg.emojiSize != "large") return callback({ error: "emojiSize property is invalid" });
202
+ if (form["body"] != null && form["body"] != "") return callback({ error: "body is not empty" });
203
+ form["body"] = msg.emoji;
204
+ form["tags[0]"] = "hot_emoji_size:" + msg.emojiSize;
205
+ }
206
+ cb();
207
+ }
208
+
209
+ function handleAttachment(msg, form, callback, cb) {
210
+ if (msg.attachment) {
211
+ form["image_ids"] = [];
212
+ form["gif_ids"] = [];
213
+ form["file_ids"] = [];
214
+ form["video_ids"] = [];
215
+ form["audio_ids"] = [];
216
+
217
+ if (utils.getType(msg.attachment) !== "Array") msg.attachment = [msg.attachment];
218
+
219
+ uploadAttachment(msg.attachment, function (err, files) {
220
+ if (err) return callback(err);
221
+ files.forEach(function (file) {
222
+ var key = Object.keys(file);
223
+ var type = key[0]; // image_id, file_id, etc
224
+ form["" + type + "s"].push(file[type]); // push the id
225
+ });
226
+ cb();
227
+ });
228
+ }
229
+ else cb();
230
+ }
231
+
232
+ function handleMention(msg, form, callback, cb) {
233
+ if (msg.mentions) {
234
+ for (let i = 0; i < msg.mentions.length; i++) {
235
+ const mention = msg.mentions[i];
236
+ const tag = mention.tag;
237
+ if (typeof tag !== "string") return callback({ error: "Mention tags must be strings." });
238
+ const offset = msg.body.indexOf(tag, mention.fromIndex || 0);
239
+ if (offset < 0) log.warn("handleMention", 'Mention for "' + tag + '" not found in message string.');
240
+ if (mention.id == null) log.warn("handleMention", "Mention id should be non-null.");
241
+
242
+ const id = mention.id || 0;
243
+ const emptyChar = '\u200E';
244
+ form["body"] = emptyChar + msg.body;
245
+ form["profile_xmd[" + i + "][offset]"] = offset + 1;
246
+ form["profile_xmd[" + i + "][length]"] = tag.length;
247
+ form["profile_xmd[" + i + "][id]"] = id;
248
+ form["profile_xmd[" + i + "][type]"] = "p";
249
+ }
250
+ }
251
+ cb();
252
+ }
253
+
254
+ return function sendMessage(msg, threadID, callback, replyToMessage, isGroup) {
255
+ typeof isGroup == "undefined" ? isGroup = null : "";
256
+ if (!callback && (utils.getType(threadID) === "Function" || utils.getType(threadID) === "AsyncFunction")) return threadID({ error: "Pass a threadID as a second argument." });
257
+ if (!replyToMessage && utils.getType(callback) === "String") {
258
+ replyToMessage = callback;
259
+ callback = function () { };
260
+ }
261
+
262
+ var resolveFunc = function () { };
263
+ var rejectFunc = function () { };
264
+ var returnPromise = new Promise(function (resolve, reject) {
265
+ resolveFunc = resolve;
266
+ rejectFunc = reject;
267
+ });
268
+
269
+ if (!callback) {
270
+ callback = function (err, data) {
271
+ if (err) return rejectFunc(err);
272
+ resolveFunc(data);
273
+ };
274
+ }
275
+
276
+ var msgType = utils.getType(msg);
277
+ var threadIDType = utils.getType(threadID);
278
+ var messageIDType = utils.getType(replyToMessage);
279
+
280
+ if (msgType !== "String" && msgType !== "Object") return callback({ error: "Message should be of type string or object and not " + msgType + "." });
281
+
282
+ // Changing this to accomodate an array of users
283
+ if (threadIDType !== "Array" && threadIDType !== "Number" && threadIDType !== "String") return callback({ error: "ThreadID should be of type number, string, or array and not " + threadIDType + "." });
284
+
285
+ if (replyToMessage && messageIDType !== 'String') return callback({ error: "MessageID should be of type string and not " + threadIDType + "." });
286
+
287
+ if (msgType === "String") msg = { body: msg };
288
+ var disallowedProperties = Object.keys(msg).filter(prop => !allowedProperties[prop]);
289
+ if (disallowedProperties.length > 0) return callback({ error: "Dissallowed props: `" + disallowedProperties.join(", ") + "`" });
290
+
291
+ var messageAndOTID = utils.generateOfflineThreadingID();
292
+
293
+ var form = {
294
+ client: "mercury",
295
+ action_type: "ma-type:user-generated-message",
296
+ author: "fbid:" + ctx.userID,
297
+ timestamp: Date.now(),
298
+ timestamp_absolute: "Today",
299
+ timestamp_relative: utils.generateTimestampRelative(),
300
+ timestamp_time_passed: "0",
301
+ is_unread: false,
302
+ is_cleared: false,
303
+ is_forward: false,
304
+ is_filtered_content: false,
305
+ is_filtered_content_bh: false,
306
+ is_filtered_content_account: false,
307
+ is_filtered_content_quasar: false,
308
+ is_filtered_content_invalid_app: false,
309
+ is_spoof_warning: false,
310
+ source: "source:chat:web",
311
+ "source_tags[0]": "source:chat",
312
+ body: msg.body ? msg.body.toString() : "",
313
+ html_body: false,
314
+ ui_push_phase: "V3",
315
+ status: "0",
316
+ offline_threading_id: messageAndOTID,
317
+ message_id: messageAndOTID,
318
+ threading_id: utils.generateThreadingID(ctx.clientID),
319
+ "ephemeral_ttl_mode:": "0",
320
+ manual_retry_cnt: "0",
321
+ has_attachment: !!(msg.attachment || msg.url || msg.sticker),
322
+ signatureID: utils.getSignatureID(),
323
+ replied_to_message_id: replyToMessage
324
+ };
325
+
326
+ handleLocation(msg, form, callback, () =>
327
+ handleSticker(msg, form, callback, () =>
328
+ handleAttachment(msg, form, callback, () =>
329
+ handleUrl(msg, form, callback, () =>
330
+ handleEmoji(msg, form, callback, () =>
331
+ handleMention(msg, form, callback, () =>
332
+ send(form, threadID, messageAndOTID, callback, isGroup)
333
+ )
334
+ )
335
+ )
336
+ )
337
+ )
338
+ );
339
+
340
+ return returnPromise;
341
+ };
342
+ };
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ function makeTypingIndicator(typ, threadID, callback, isGroup) {
8
+ var form = {
9
+ typ: +typ,
10
+ to: "",
11
+ source: "mercury-chat",
12
+ thread: threadID
13
+ };
14
+
15
+ // Check if thread is a single person chat or a group chat
16
+ // More info on this is in api.sendMessage
17
+ if (utils.getType(isGroup) == "Boolean") {
18
+ if (!isGroup) {
19
+ form.to = threadID;
20
+ }
21
+ defaultFuncs
22
+ .post("https://www.facebook.com/ajax/messaging/typ.php", ctx.jar, form)
23
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
24
+ .then(function (resData) {
25
+ if (resData.error) throw resData;
26
+ return callback();
27
+ })
28
+ .catch(function (err) {
29
+ log.error("sendTypingIndicator", err);
30
+ if (utils.getType(err) == "Object" && err.error === "Not logged in") {
31
+ ctx.loggedIn = false;
32
+ }
33
+ return callback(err);
34
+ });
35
+ }
36
+ else {
37
+ api.getUserInfo(threadID, function (err, res) {
38
+ if (err) return callback(err);
39
+ // If id is single person chat
40
+ if (Object.keys(res).length > 0) form.to = threadID;
41
+ defaultFuncs
42
+ .post("https://www.facebook.com/ajax/messaging/typ.php", ctx.jar, form)
43
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
44
+ .then(function (resData) {
45
+ if (resData.error) throw resData;
46
+ return callback();
47
+ })
48
+ .catch(function (err) {
49
+ log.error("sendTypingIndicator", err);
50
+ if (utils.getType(err) == "Object" && err.error === "Not logged in.") ctx.loggedIn = false;
51
+ return callback(err);
52
+ });
53
+ });
54
+ }
55
+ }
56
+
57
+ return function sendTypingIndicator(threadID, callback, isGroup) {
58
+ if (
59
+ utils.getType(callback) !== "Function" &&
60
+ utils.getType(callback) !== "AsyncFunction"
61
+ ) {
62
+ if (callback) log.warn("sendTypingIndicator", "callback is not a function - ignoring.");
63
+ callback = () => { };
64
+ }
65
+
66
+ makeTypingIndicator(true, threadID, callback, isGroup);
67
+
68
+ return function end(cb) {
69
+ if (
70
+ utils.getType(cb) !== "Function" &&
71
+ utils.getType(cb) !== "AsyncFunction"
72
+ ) {
73
+ if (cb) log.warn("sendTypingIndicator", "callback is not a function - ignoring.");
74
+ cb = () => { };
75
+ }
76
+
77
+ makeTypingIndicator(false, threadID, cb, isGroup);
78
+ };
79
+ };
80
+ };
@@ -0,0 +1,109 @@
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 setMessageReaction(reaction, messageID, callback, forceCustomReaction) {
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, data) {
17
+ if (err) return rejectFunc(err);
18
+ resolveFunc(data);
19
+ };
20
+ }
21
+
22
+ switch (reaction) {
23
+ case "\uD83D\uDE0D": //:heart_eyes:
24
+ case "\uD83D\uDE06": //:laughing:
25
+ case "\uD83D\uDE2E": //:open_mouth:
26
+ case "\uD83D\uDE22": //:cry:
27
+ case "\uD83D\uDE20": //:angry:
28
+ case "\uD83D\uDC4D": //:thumbsup:
29
+ case "\uD83D\uDC4E": //:thumbsdown:
30
+ case "\u2764": //:heart:
31
+ case "\uD83D\uDC97": //:glowingheart:
32
+ case "":
33
+ //valid
34
+ break;
35
+ case ":heart_eyes:":
36
+ case ":love:":
37
+ reaction = "\uD83D\uDE0D";
38
+ break;
39
+ case ":laughing:":
40
+ case ":haha:":
41
+ reaction = "\uD83D\uDE06";
42
+ break;
43
+ case ":open_mouth:":
44
+ case ":wow:":
45
+ reaction = "\uD83D\uDE2E";
46
+ break;
47
+ case ":cry:":
48
+ case ":sad:":
49
+ reaction = "\uD83D\uDE22";
50
+ break;
51
+ case ":angry:":
52
+ reaction = "\uD83D\uDE20";
53
+ break;
54
+ case ":thumbsup:":
55
+ case ":like:":
56
+ reaction = "\uD83D\uDC4D";
57
+ break;
58
+ case ":thumbsdown:":
59
+ case ":dislike:":
60
+ reaction = "\uD83D\uDC4E";
61
+ break;
62
+ case ":heart:":
63
+ reaction = "\u2764";
64
+ break;
65
+ case ":glowingheart:":
66
+ reaction = "\uD83D\uDC97";
67
+ break;
68
+ default:
69
+ if (forceCustomReaction) break;
70
+ return callback({ error: "Reaction is not a valid emoji." });
71
+ }
72
+
73
+ var variables = {
74
+ data: {
75
+ client_mutation_id: ctx.clientMutationId++,
76
+ actor_id: ctx.userID,
77
+ action: reaction == "" ? "REMOVE_REACTION" : "ADD_REACTION",
78
+ message_id: messageID,
79
+ reaction: reaction
80
+ }
81
+ };
82
+
83
+ var qs = {
84
+ doc_id: "1491398900900362",
85
+ variables: JSON.stringify(variables),
86
+ dpr: 1
87
+ };
88
+
89
+ defaultFuncs
90
+ .postFormData(
91
+ "https://www.facebook.com/webgraphql/mutation/",
92
+ ctx.jar,
93
+ {},
94
+ qs
95
+ )
96
+ .then(utils.parseAndCheckLogin(ctx.jar, defaultFuncs))
97
+ .then(function (resData) {
98
+ if (!resData) throw { error: "setReaction returned empty object." };
99
+ if (resData.error) throw resData;
100
+ callback(null);
101
+ })
102
+ .catch(function (err) {
103
+ log.error("setReaction", err);
104
+ return callback(err);
105
+ });
106
+
107
+ return returnPromise;
108
+ };
109
+ };
@@ -0,0 +1,102 @@
1
+ /**
2
+ * @fix by NTKhang
3
+ * update as Thursday, 10 February 2022
4
+ * do not remove the author name to get more updates
5
+ */
6
+
7
+ "use strict";
8
+
9
+ var utils = require("../utils");
10
+ var log = require("npmlog");
11
+
12
+ function formatData(resData) {
13
+ return {
14
+ viewer_feedback_reaction_info: resData.feedback_react.feedback.viewer_feedback_reaction_info,
15
+ supported_reactions: resData.feedback_react.feedback.supported_reactions,
16
+ top_reactions: resData.feedback_react.feedback.top_reactions.edges,
17
+ reaction_count: resData.feedback_react.feedback.reaction_count
18
+ };
19
+ }
20
+
21
+ module.exports = function(defaultFuncs, api, ctx) {
22
+ return function setPostReaction(postID, type, callback) {
23
+ var resolveFunc = function(){};
24
+ var rejectFunc = function(){};
25
+ var returnPromise = new Promise(function (resolve, reject) {
26
+ resolveFunc = resolve;
27
+ rejectFunc = reject;
28
+ });
29
+
30
+ if (!callback) {
31
+ if (utils.getType(type) === "Function" || utils.getType(type) === "AsyncFunction") {
32
+ callback = type;
33
+ type = 0;
34
+ }
35
+ else {
36
+ callback = function (err, data) {
37
+ if (err) {
38
+ return rejectFunc(err);
39
+ }
40
+ resolveFunc(data);
41
+ };
42
+ }
43
+ }
44
+
45
+ var map = {
46
+ unlike: 0,
47
+ like: 1,
48
+ heart: 2,
49
+ love: 16,
50
+ haha: 4,
51
+ wow: 3,
52
+ sad: 7,
53
+ angry: 8
54
+ };
55
+
56
+ if (utils.getType(type) !== "Number" && utils.getType(type) === "String") {
57
+ type = map[type.toLowerCase()];
58
+ }
59
+ else {
60
+ throw {
61
+ error: "setPostReaction: Invalid reaction type"
62
+ };
63
+ }
64
+
65
+ var form = {
66
+ av: ctx.userID,
67
+ fb_api_caller_class: "RelayModern",
68
+ fb_api_req_friendly_name: "CometUFIFeedbackReactMutation",
69
+ doc_id: "4769042373179384",
70
+ variables: JSON.stringify({
71
+ input: {
72
+ actor_id: ctx.userID,
73
+ feedback_id: (new Buffer.from("feedback:" + postID)).toString("base64"),
74
+ feedback_reaction: type,
75
+ feedback_source: "OBJECT",
76
+ is_tracking_encrypted: true,
77
+ tracking: [],
78
+ session_id: "f7dd50dd-db6e-4598-8cd9-561d5002b423",
79
+ client_mutation_id: Math.round(Math.random() * 19).toString()
80
+ },
81
+ useDefaultActor: false,
82
+ scale: 3
83
+ })
84
+ };
85
+
86
+ defaultFuncs
87
+ .post("https://www.facebook.com/api/graphql/", ctx.jar, form)
88
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
89
+ .then(function(resData) {
90
+ if (resData.errors) {
91
+ throw resData;
92
+ }
93
+ return callback(null, formatData(resData.data));
94
+ })
95
+ .catch(function(err) {
96
+ log.error("setPostReaction", err);
97
+ return callback(err);
98
+ });
99
+
100
+ return returnPromise;
101
+ };
102
+ };