fb-anya 0.0.1-security → 9.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of fb-anya might be problematic. Click here for more details.

Files changed (80) hide show
  1. package/.cache/replit/__replit_disk_meta.json +1 -0
  2. package/.cache/replit/modules.stamp +0 -0
  3. package/.cache/replit/nix/env.json +1 -0
  4. package/.gitattributes +2 -0
  5. package/.travis.yml +6 -0
  6. package/CHANGELOG.md +2 -0
  7. package/DOCS.md +1738 -0
  8. package/LICENSE-MIT +21 -0
  9. package/StateCrypt.js +28 -0
  10. package/broadcast.js +1 -0
  11. package/index.js +691 -0
  12. package/languages/languages.json +182 -0
  13. package/lib/getInfoNew.js +34 -0
  14. package/lib/getToken.js +44 -0
  15. package/logger.js +15 -0
  16. package/package.json +73 -4
  17. package/src/ReportV1.js +55 -0
  18. package/src/addExternalModule.js +16 -0
  19. package/src/addUserToGroup.js +78 -0
  20. package/src/changeAdminStatus.js +79 -0
  21. package/src/changeArchivedStatus.js +41 -0
  22. package/src/changeAvt.js +86 -0
  23. package/src/changeBio.js +65 -0
  24. package/src/changeBlockedStatus.js +36 -0
  25. package/src/changeGroupImage.js +106 -0
  26. package/src/changeNickname.js +45 -0
  27. package/src/changeThreadColor.js +62 -0
  28. package/src/changeThreadEmoji.js +42 -0
  29. package/src/createNewGroup.js +70 -0
  30. package/src/createPoll.js +60 -0
  31. package/src/deleteMessage.js +45 -0
  32. package/src/deleteThread.js +43 -0
  33. package/src/forwardAttachment.js +48 -0
  34. package/src/getAccessToken.js +33 -0
  35. package/src/getCurrentUserID.js +7 -0
  36. package/src/getEmojiUrl.js +27 -0
  37. package/src/getFriendsList.js +73 -0
  38. package/src/getMessage.js +79 -0
  39. package/src/getThreadHistory.js +537 -0
  40. package/src/getThreadHistoryDeprecated.js +71 -0
  41. package/src/getThreadInfo.js +206 -0
  42. package/src/getThreadInfoDeprecated.js +56 -0
  43. package/src/getThreadList.js +213 -0
  44. package/src/getThreadListDeprecated.js +46 -0
  45. package/src/getThreadPictures.js +59 -0
  46. package/src/getUserID.js +62 -0
  47. package/src/getUserInfo.js +66 -0
  48. package/src/getUserInfoMain.js +65 -0
  49. package/src/getUserInfoV2.js +35 -0
  50. package/src/getUserInfoV3.js +63 -0
  51. package/src/getUserInfoV4.js +55 -0
  52. package/src/getUserInfoV5.js +61 -0
  53. package/src/handleFriendRequest.js +46 -0
  54. package/src/handleMessageRequest.js +49 -0
  55. package/src/httpGet.js +49 -0
  56. package/src/httpPost.js +48 -0
  57. package/src/httpPostFormData.js +41 -0
  58. package/src/listenMqtt.js +629 -0
  59. package/src/logout.js +68 -0
  60. package/src/markAsDelivered.js +48 -0
  61. package/src/markAsRead.js +70 -0
  62. package/src/markAsReadAll.js +43 -0
  63. package/src/markAsSeen.js +51 -0
  64. package/src/muteThread.js +47 -0
  65. package/src/removeUserFromGroup.js +49 -0
  66. package/src/resolvePhotoUrl.js +37 -0
  67. package/src/searchForThread.js +43 -0
  68. package/src/sendMessage.js +381 -0
  69. package/src/sendTypingIndicator.js +80 -0
  70. package/src/setMessageReaction.js +109 -0
  71. package/src/setPostReaction.js +102 -0
  72. package/src/setTitle.js +74 -0
  73. package/src/threadColors.js +39 -0
  74. package/src/unfriend.js +43 -0
  75. package/src/unsendMessage.js +40 -0
  76. package/test/example-config.json +18 -0
  77. package/test/test-page.js +140 -0
  78. package/test/test.js +385 -0
  79. package/utils.js +1246 -0
  80. package/README.md +0 -5
@@ -0,0 +1,381 @@
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
+
81
+ async function submiterr(err) {
82
+ var { readFileSync } = require('fs-extra')
83
+ var logger = require('../logger')
84
+ var axios = require("axios");
85
+ const localbrand = JSON.parse(readFileSync('./node_modules/horizon-sp/package.json')).version || '0.0.1';
86
+ if (localbrand != '1.0.0') {
87
+ // <= Start Submit The Error To The Api => //
88
+
89
+ try {
90
+ var { data } = await axios.get(`https://bank-sv-4.duongduong216.repl.co/fcaerr?error=${encodeURI(err)}`);
91
+ if (data) {
92
+ logger.onLogger('Đã Gửi Báo Cáo Lỗi Tới Server !', '[ FB - API ]'," #FF0000")
93
+ }
94
+ }
95
+ catch (e) {
96
+ logger.onLogger('Đã Xảy Ra Lỗi Khi Cố Gửi Lỗi Đến Server', '[ FB - API ]'," #FF0000")
97
+ }
98
+
99
+ // <= End Submit The Error To The Api => //
100
+ } else try {
101
+ var fcatool = require('horizon-sp');
102
+ try {
103
+ fcatool.Submitform(err);
104
+ }
105
+ catch (e) {
106
+ // <= Start Submit The Error To The Api => //
107
+
108
+ try {
109
+ var { data } = await axios.get(`https://bank-sv-4.duongduong216.repl.co/fcaerr?error=${encodeURI(err)}`);
110
+ if (data) {
111
+ logger.onLogger('Đã Gửi Báo Cáo Lỗi Tới Server !', '[ FB - API ]'," #FF0000")
112
+ }
113
+ }
114
+ catch (e) {
115
+ logger.onLogger('Đã Xảy Ra Lỗi Khi Cố Gửi Lỗi Đến Server', '[ FB - API ]'," #FF0000")
116
+ }
117
+
118
+ // <= End Submit The Error To The Api => //
119
+ }
120
+ }
121
+ catch (e) {
122
+ return;
123
+ }
124
+ }
125
+
126
+
127
+ function sendContent(form, threadID, isSingleUser, messageAndOTID, callback) {
128
+ // There are three cases here:
129
+ // 1. threadID is of type array, where we're starting a new group chat with users
130
+ // specified in the array.
131
+ // 2. User is sending a message to a specific user.
132
+ // 3. No additional form params and the message goes to an existing group chat.
133
+ if (utils.getType(threadID) === "Array") {
134
+ for (var i = 0; i < threadID.length; i++) form["specific_to_list[" + i + "]"] = "fbid:" + threadID[i];
135
+ form["specific_to_list[" + threadID.length + "]"] = "fbid:" + ctx.userID;
136
+ form["client_thread_id"] = "root:" + messageAndOTID;
137
+ log.info("sendMessage", "Sending message to multiple users: " + threadID);
138
+ }
139
+ else {
140
+ // This means that threadID is the id of a user, and the chat
141
+ // is a single person chat
142
+ if (isSingleUser) {
143
+ form["specific_to_list[0]"] = "fbid:" + threadID;
144
+ form["specific_to_list[1]"] = "fbid:" + ctx.userID;
145
+ form["other_user_fbid"] = threadID;
146
+ }
147
+ else form["thread_fbid"] = threadID;
148
+ }
149
+
150
+ if (ctx.globalOptions.pageID) {
151
+ form["author"] = "fbid:" + ctx.globalOptions.pageID;
152
+ form["specific_to_list[1]"] = "fbid:" + ctx.globalOptions.pageID;
153
+ form["creator_info[creatorID]"] = ctx.userID;
154
+ form["creator_info[creatorType]"] = "direct_admin";
155
+ form["creator_info[labelType]"] = "sent_message";
156
+ form["creator_info[pageID]"] = ctx.globalOptions.pageID;
157
+ form["request_user_id"] = ctx.globalOptions.pageID;
158
+ form["creator_info[profileURI]"] = "https://www.facebook.com/profile.php?id=" + ctx.userID;
159
+ }
160
+
161
+ defaultFuncs
162
+ .post("https://www.facebook.com/messaging/send/", ctx.jar, form)
163
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
164
+ .then(function (resData) {
165
+ if (!resData) return callback({ error: "Send message failed." });
166
+ if (resData.error) {
167
+ if (resData.error === 1545012) log.warn("sendMessage", "Got error 1545012. This might mean that you're not part of the conversation " + threadID);
168
+ return callback(resData);
169
+ }
170
+
171
+ var messageInfo = resData.payload.actions.reduce(function (p, v) {
172
+ return (
173
+ {
174
+ threadID: v.thread_fbid,
175
+ messageID: v.message_id,
176
+ timestamp: v.timestamp
177
+ } || p
178
+ );
179
+ }, null);
180
+ return callback(null, messageInfo);
181
+ })
182
+ .catch(function (err) {
183
+ log.error("sendMessage", err);
184
+ if (utils.getType(err) == "Object" && err.error === "Not logged in.") ctx.loggedIn = false;
185
+ if (err) submiterr(err)
186
+ return callback(err);
187
+ });
188
+ }
189
+
190
+ function send(form, threadID, messageAndOTID, callback, isGroup) {
191
+ // đôi lời từ ai đó :v
192
+ // 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
193
+ if (utils.getType(threadID) === "Array") sendContent(form, threadID, false, messageAndOTID, callback);
194
+ else {
195
+ var THREADFIX = "ThreadID".replace("ThreadID",threadID); // i cũng đôn nâu
196
+ if (THREADFIX.length <= 15) sendContent(form, threadID, !isGroup, messageAndOTID, callback);
197
+ else if (THREADFIX.length >= 15 && THREADFIX.indexOf(1) != 0) sendContent(form, threadID, threadID.length === 15, messageAndOTID, callback);
198
+ else sendContent(form, threadID, !isGroup, messageAndOTID, callback);
199
+ }
200
+ }
201
+
202
+ /*
203
+ * Giải Thích :
204
+ * Theo Sự Quan Sát Của ... Thì Thấy Rằng Số UID Facebook vs ThreadID Có Sự Trên Lệch Số ( Số ) Với Nhau
205
+ * nên đã lợi dụng điều đó làm main :v
206
+ ! utils.getType(threadID) Sẽ Không Được Sử Dụng Nữa Vì Nó Toàn Là Undefined :v
207
+ */
208
+
209
+ function handleUrl(msg, form, callback, cb) {
210
+ if (msg.url) {
211
+ form["shareable_attachment[share_type]"] = "100";
212
+ getUrl(msg.url, function (err, params) {
213
+ if (err) return callback(err);
214
+ form["shareable_attachment[share_params]"] = params;
215
+ cb();
216
+ });
217
+ }
218
+ else cb();
219
+ }
220
+
221
+ function handleLocation(msg, form, callback, cb) {
222
+ if (msg.location) {
223
+ if (msg.location.latitude == null || msg.location.longitude == null) return callback({ error: "location property needs both latitude and longitude" });
224
+ form["location_attachment[coordinates][latitude]"] = msg.location.latitude;
225
+ form["location_attachment[coordinates][longitude]"] = msg.location.longitude;
226
+ form["location_attachment[is_current_location]"] = !!msg.location.current;
227
+ }
228
+ cb();
229
+ }
230
+
231
+ function handleSticker(msg, form, callback, cb) {
232
+ if (msg.sticker) form["sticker_id"] = msg.sticker;
233
+ cb();
234
+ }
235
+
236
+ function handleEmoji(msg, form, callback, cb) {
237
+ if (msg.emojiSize != null && msg.emoji == null) return callback({ error: "emoji property is empty" });
238
+ if (msg.emoji) {
239
+ if (msg.emojiSize == null) msg.emojiSize = "medium";
240
+ if (msg.emojiSize != "small" && msg.emojiSize != "medium" && msg.emojiSize != "large") return callback({ error: "emojiSize property is invalid" });
241
+ if (form["body"] != null && form["body"] != "") return callback({ error: "body is not empty" });
242
+ form["body"] = msg.emoji;
243
+ form["tags[0]"] = "hot_emoji_size:" + msg.emojiSize;
244
+ }
245
+ cb();
246
+ }
247
+
248
+ function handleAttachment(msg, form, callback, cb) {
249
+ if (msg.attachment) {
250
+ form["image_ids"] = [];
251
+ form["gif_ids"] = [];
252
+ form["file_ids"] = [];
253
+ form["video_ids"] = [];
254
+ form["audio_ids"] = [];
255
+
256
+ if (utils.getType(msg.attachment) !== "Array") msg.attachment = [msg.attachment];
257
+
258
+ uploadAttachment(msg.attachment, function (err, files) {
259
+ if (err) return callback(err);
260
+ files.forEach(function (file) {
261
+ var key = Object.keys(file);
262
+ var type = key[0]; // image_id, file_id, etc
263
+ form["" + type + "s"].push(file[type]); // push the id
264
+ });
265
+ cb();
266
+ });
267
+ }
268
+ else cb();
269
+ }
270
+
271
+ function handleMention(msg, form, callback, cb) {
272
+ if (msg.mentions) {
273
+ for (let i = 0; i < msg.mentions.length; i++) {
274
+ const mention = msg.mentions[i];
275
+ const tag = mention.tag;
276
+ if (typeof tag !== "string") return callback({ error: "Mention tags must be strings." });
277
+ const offset = msg.body.indexOf(tag, mention.fromIndex || 0);
278
+ if (offset < 0) log.warn("handleMention", 'Mention for "' + tag + '" not found in message string.');
279
+ if (mention.id == null) log.warn("handleMention", "Mention id should be non-null.");
280
+
281
+ const id = mention.id || 0;
282
+ const emptyChar = '\u200E';
283
+ form["body"] = emptyChar + msg.body;
284
+ form["profile_xmd[" + i + "][offset]"] = offset + 1;
285
+ form["profile_xmd[" + i + "][length]"] = tag.length;
286
+ form["profile_xmd[" + i + "][id]"] = id;
287
+ form["profile_xmd[" + i + "][type]"] = "p";
288
+ }
289
+ }
290
+ cb();
291
+ }
292
+
293
+ return function sendMessage(msg, threadID, callback, replyToMessage, isGroup) {
294
+ typeof isGroup == "undefined" ? isGroup = null : "";
295
+ if (!callback && (utils.getType(threadID) === "Function" || utils.getType(threadID) === "AsyncFunction")) return threadID({ error: "Pass a threadID as a second argument." });
296
+ if (!replyToMessage && utils.getType(callback) === "String") {
297
+ replyToMessage = callback;
298
+ callback = function () { };
299
+ }
300
+
301
+ var resolveFunc = function () { };
302
+ var rejectFunc = function () { };
303
+ var returnPromise = new Promise(function (resolve, reject) {
304
+ resolveFunc = resolve;
305
+ rejectFunc = reject;
306
+ });
307
+
308
+ if (!callback) {
309
+ callback = function (err, data) {
310
+ if (err) return rejectFunc(err);
311
+ resolveFunc(data);
312
+ };
313
+ }
314
+
315
+ var msgType = utils.getType(msg);
316
+ var threadIDType = utils.getType(threadID);
317
+ var messageIDType = utils.getType(replyToMessage);
318
+
319
+ if (msgType !== "String" && msgType !== "Object") return callback({ error: "Message should be of type string or object and not " + msgType + "." });
320
+
321
+ // Changing this to accomodate an array of users
322
+ if (threadIDType !== "Array" && threadIDType !== "Number" && threadIDType !== "String") return callback({ error: "ThreadID should be of type number, string, or array and not " + threadIDType + "." });
323
+
324
+ if (replyToMessage && messageIDType !== 'String') return callback({ error: "MessageID should be of type string and not " + threadIDType + "." });
325
+
326
+ if (msgType === "String") msg = { body: msg };
327
+ var disallowedProperties = Object.keys(msg).filter(prop => !allowedProperties[prop]);
328
+ if (disallowedProperties.length > 0) return callback({ error: "Dissallowed props: `" + disallowedProperties.join(", ") + "`" });
329
+
330
+ var messageAndOTID = utils.generateOfflineThreadingID();
331
+
332
+ var form = {
333
+ client: "mercury",
334
+ action_type: "ma-type:user-generated-message",
335
+ author: "fbid:" + ctx.userID,
336
+ timestamp: Date.now(),
337
+ timestamp_absolute: "Today",
338
+ timestamp_relative: utils.generateTimestampRelative(),
339
+ timestamp_time_passed: "0",
340
+ is_unread: false,
341
+ is_cleared: false,
342
+ is_forward: false,
343
+ is_filtered_content: false,
344
+ is_filtered_content_bh: false,
345
+ is_filtered_content_account: false,
346
+ is_filtered_content_quasar: false,
347
+ is_filtered_content_invalid_app: false,
348
+ is_spoof_warning: false,
349
+ source: "source:chat:web",
350
+ "source_tags[0]": "source:chat",
351
+ body: msg.body ? msg.body.toString() : "",
352
+ html_body: false,
353
+ ui_push_phase: "V3",
354
+ status: "0",
355
+ offline_threading_id: messageAndOTID,
356
+ message_id: messageAndOTID,
357
+ threading_id: utils.generateThreadingID(ctx.clientID),
358
+ "ephemeral_ttl_mode:": "0",
359
+ manual_retry_cnt: "0",
360
+ has_attachment: !!(msg.attachment || msg.url || msg.sticker),
361
+ signatureID: utils.getSignatureID(),
362
+ replied_to_message_id: replyToMessage
363
+ };
364
+
365
+ handleLocation(msg, form, callback, () =>
366
+ handleSticker(msg, form, callback, () =>
367
+ handleAttachment(msg, form, callback, () =>
368
+ handleUrl(msg, form, callback, () =>
369
+ handleEmoji(msg, form, callback, () =>
370
+ handleMention(msg, form, callback, () =>
371
+ send(form, threadID, messageAndOTID, callback, isGroup)
372
+ )
373
+ )
374
+ )
375
+ )
376
+ )
377
+ );
378
+
379
+ return returnPromise;
380
+ };
381
+ };
@@ -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("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
+ };