toru-fca 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +319 -0
  3. package/advancedSystem.js +95 -0
  4. package/build/messagix.dll +0 -0
  5. package/build/messagix.so +0 -0
  6. package/checkUpdate.js +37 -0
  7. package/config.json +45 -0
  8. package/e2ee.js +719 -0
  9. package/index.js +715 -0
  10. package/lib/index.mjs +1412 -0
  11. package/package.json +69 -0
  12. package/src/OldMessage.js +357 -0
  13. package/src/addExternalModule.js +25 -0
  14. package/src/addUserToGroup.js +117 -0
  15. package/src/changeAdminStatus.js +105 -0
  16. package/src/changeArchivedStatus.js +57 -0
  17. package/src/changeAvatar.js +138 -0
  18. package/src/changeAvatarV2.js +86 -0
  19. package/src/changeAvt.js +85 -0
  20. package/src/changeBio.js +78 -0
  21. package/src/changeBlockedStatus.js +51 -0
  22. package/src/changeBlockedStatusMqtt.js +80 -0
  23. package/src/changeCover.js +72 -0
  24. package/src/changeGroupImage.js +137 -0
  25. package/src/changeName.js +79 -0
  26. package/src/changeNickname.js +61 -0
  27. package/src/changeThreadColor.js +67 -0
  28. package/src/changeThreadEmoji.js +57 -0
  29. package/src/changeUsername.js +59 -0
  30. package/src/createCommentPost.js +230 -0
  31. package/src/createNewGroup.js +90 -0
  32. package/src/createPoll.js +73 -0
  33. package/src/createPost.js +276 -0
  34. package/src/data/getThreadInfo.json +1 -0
  35. package/src/deleteMessage.js +58 -0
  36. package/src/deleteThread.js +58 -0
  37. package/src/editMessage.js +81 -0
  38. package/src/editMessageOld.js +67 -0
  39. package/src/follow.js +74 -0
  40. package/src/forwardAttachment.js +62 -0
  41. package/src/friendList.js +104 -0
  42. package/src/getAccess.js +112 -0
  43. package/src/getAvatarUser.js +78 -0
  44. package/src/getBotInitialData.js +42 -0
  45. package/src/getCtx.js +5 -0
  46. package/src/getCurrentUserID.js +7 -0
  47. package/src/getEmojiUrl.js +29 -0
  48. package/src/getFriendsList.js +85 -0
  49. package/src/getMessage.js +849 -0
  50. package/src/getOptions.js +5 -0
  51. package/src/getRegion.js +7 -0
  52. package/src/getThreadHistory.js +682 -0
  53. package/src/getThreadHistoryDeprecated.js +71 -0
  54. package/src/getThreadInfo.js +232 -0
  55. package/src/getThreadInfoDeprecated.js +56 -0
  56. package/src/getThreadList.js +213 -0
  57. package/src/getThreadListDeprecated.js +46 -0
  58. package/src/getThreadPictures.js +59 -0
  59. package/src/getThreadTheme.js +81 -0
  60. package/src/getUID.js +119 -0
  61. package/src/getUserID.js +61 -0
  62. package/src/getUserInfo.js +66 -0
  63. package/src/handleFriendRequest.js +46 -0
  64. package/src/handleMessageRequest.js +47 -0
  65. package/src/httpGet.js +49 -0
  66. package/src/httpPost.js +48 -0
  67. package/src/httpPostFormData.js +70 -0
  68. package/src/listenMqtt.js +955 -0
  69. package/src/listenNotification.js +85 -0
  70. package/src/logout.js +19 -0
  71. package/src/markAsDelivered.js +47 -0
  72. package/src/markAsRead.js +72 -0
  73. package/src/markAsReadAll.js +40 -0
  74. package/src/markAsSeen.js +48 -0
  75. package/src/metaTheme.js +189 -0
  76. package/src/muteThread.js +45 -0
  77. package/src/note.js +228 -0
  78. package/src/pinMessage.js +59 -0
  79. package/src/refreshFb_dtsg.js +91 -0
  80. package/src/removeSuspiciousAccount.js +78 -0
  81. package/src/removeUserFromGroup.js +81 -0
  82. package/src/reply.js +442 -0
  83. package/src/resolvePhotoUrl.js +47 -0
  84. package/src/searchForThread.js +53 -0
  85. package/src/searchFriends.js +140 -0
  86. package/src/searchStickers.js +53 -0
  87. package/src/send.js +46 -0
  88. package/src/sendButtons.js +163 -0
  89. package/src/sendComment.js +159 -0
  90. package/src/sendFriendRequest.js +112 -0
  91. package/src/sendMessage.js +440 -0
  92. package/src/sendMessageMqtt.js +323 -0
  93. package/src/sendTypingIndicator.js +54 -0
  94. package/src/setActiveStatus.js +92 -0
  95. package/src/setMessageReaction.js +149 -0
  96. package/src/setMessageReactionMqtt.js +62 -0
  97. package/src/setPostReaction.js +114 -0
  98. package/src/setProfileGuard.js +44 -0
  99. package/src/setProfileLock.js +97 -0
  100. package/src/setStoryReaction.js +133 -0
  101. package/src/setStorySeen.js +108 -0
  102. package/src/setThreadTheme.js +102 -0
  103. package/src/setTitle.js +92 -0
  104. package/src/shareContact.js +110 -0
  105. package/src/shareLink.js +59 -0
  106. package/src/stopListenMqtt.js +37 -0
  107. package/src/storyManager.js +357 -0
  108. package/src/suggestFriend.js +132 -0
  109. package/src/threadColors.js +131 -0
  110. package/src/unfriend.js +54 -0
  111. package/src/unsendMessage.js +68 -0
  112. package/src/uploadAttachment.js +115 -0
  113. package/utils.js +3044 -0
@@ -0,0 +1,323 @@
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+ var bluebird = require("bluebird");
6
+
7
+ module.exports = function (defaultFuncs, api, ctx) {
8
+ function uploadAttachment(attachments, callback) {
9
+ callback = callback || function () {};
10
+ var uploads = [];
11
+
12
+ // create an array of promises
13
+ for (var i = 0; i < attachments.length; i++) {
14
+ if (!utils.isReadableStream(attachments[i])) {
15
+ throw {
16
+ error:
17
+ "Attachment should be a readable stream and not " +
18
+ utils.getType(attachments[i]) +
19
+ ".",
20
+ };
21
+ }
22
+
23
+ var form = {
24
+ upload_1024: attachments[i],
25
+ voice_clip: "true",
26
+ };
27
+
28
+ uploads.push(
29
+ defaultFuncs
30
+ .postFormData(
31
+ "https://upload.facebook.com/ajax/mercury/upload.php",
32
+ ctx.jar,
33
+ form,
34
+ {},
35
+ )
36
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
37
+ .then(function (resData) {
38
+ if (resData.error) {
39
+ throw resData;
40
+ }
41
+
42
+ // We have to return the data unformatted unless we want to change it
43
+ // back in sendMessage.
44
+ return resData.payload.metadata[0];
45
+ }),
46
+ );
47
+ }
48
+
49
+ // resolve all promises
50
+ bluebird
51
+ .all(uploads)
52
+ .then(function (resData) {
53
+ callback(null, resData);
54
+ })
55
+ .catch(function (err) {
56
+ log.error("uploadAttachment", err);
57
+ return callback(err);
58
+ });
59
+ }
60
+
61
+ let variance = 0;
62
+ const epoch_id = () =>
63
+ Math.floor(Date.now() * (4194304 + (variance = (variance + 0.1) % 5)));
64
+ const emojiSizes = {
65
+ small: 1,
66
+ medium: 2,
67
+ large: 3,
68
+ };
69
+
70
+ function handleEmoji(msg, form, callback, cb) {
71
+ if (msg.emojiSize != null && msg.emoji == null) {
72
+ return callback({ error: "emoji property is empty" });
73
+ }
74
+ if (msg.emoji) {
75
+ if (!msg.emojiSize) {
76
+ msg.emojiSize = "small";
77
+ }
78
+ if (
79
+ msg.emojiSize !== "small" &&
80
+ msg.emojiSize !== "medium" &&
81
+ msg.emojiSize !== "large" &&
82
+ (isNaN(msg.emojiSize) || msg.emojiSize < 1 || msg.emojiSize > 3)
83
+ ) {
84
+ return callback({ error: "emojiSize property is invalid" });
85
+ }
86
+
87
+ form.payload.tasks[0].payload.send_type = 1;
88
+ form.payload.tasks[0].payload.text = msg.emoji;
89
+ form.payload.tasks[0].payload.hot_emoji_size = !isNaN(msg.emojiSize)
90
+ ? msg.emojiSize
91
+ : emojiSizes[msg.emojiSize];
92
+ }
93
+ cb();
94
+ }
95
+
96
+ function handleSticker(msg, form, callback, cb) {
97
+ if (msg.sticker) {
98
+ form.payload.tasks[0].payload.send_type = 2;
99
+ form.payload.tasks[0].payload.sticker_id = msg.sticker;
100
+ }
101
+ cb();
102
+ }
103
+
104
+ function handleAttachment(msg, form, callback, cb) {
105
+ if (msg.attachment) {
106
+ form.payload.tasks[0].payload.send_type = 3;
107
+ form.payload.tasks[0].payload.attachment_fbids = [];
108
+ if (form.payload.tasks[0].payload.text == "")
109
+ form.payload.tasks[0].payload.text = null;
110
+ if (utils.getType(msg.attachment) !== "Array") {
111
+ msg.attachment = [msg.attachment];
112
+ }
113
+
114
+ uploadAttachment(msg.attachment, function (err, files) {
115
+ if (err) {
116
+ return callback(err);
117
+ }
118
+
119
+ files.forEach(function (file) {
120
+ var key = Object.keys(file);
121
+ var type = key[0]; // image_id, file_id, etc
122
+ form.payload.tasks[0].payload.attachment_fbids.push(file[type]); // push the id
123
+ });
124
+ cb();
125
+ });
126
+ } else {
127
+ cb();
128
+ }
129
+ }
130
+
131
+ function handleMention(msg, form, callback, cb) {
132
+ if (msg.mentions) {
133
+ form.payload.tasks[0].payload.send_type = 1;
134
+
135
+ const arrayIds = [];
136
+ const arrayOffsets = [];
137
+ const arrayLengths = [];
138
+ const mention_types = [];
139
+
140
+ for (let i = 0; i < msg.mentions.length; i++) {
141
+ const mention = msg.mentions[i];
142
+
143
+ const tag = mention.tag;
144
+ if (typeof tag !== "string") {
145
+ return callback({ error: "Mention tags must be strings." });
146
+ }
147
+
148
+ const offset = msg.body.indexOf(tag, mention.fromIndex || 0);
149
+
150
+ if (offset < 0) {
151
+ log.warn(
152
+ "handleMention",
153
+ 'Mention for "' + tag + '" not found in message string.',
154
+ );
155
+ }
156
+
157
+ if (mention.id == null) {
158
+ log.warn("handleMention", "Mention id should be non-null.");
159
+ }
160
+
161
+ const id = mention.id || 0;
162
+ arrayIds.push(id);
163
+ arrayOffsets.push(offset);
164
+ arrayLengths.push(tag.length);
165
+ mention_types.push("p");
166
+ }
167
+
168
+ form.payload.tasks[0].payload.mention_data = {
169
+ mention_ids: arrayIds.join(","),
170
+ mention_offsets: arrayOffsets.join(","),
171
+ mention_lengths: arrayLengths.join(","),
172
+ mention_types: mention_types.join(","),
173
+ };
174
+ }
175
+ cb();
176
+ }
177
+
178
+ function handleLocation(msg, form, callback, cb) {
179
+ // this is not working yet
180
+ if (msg.location) {
181
+ if (msg.location.latitude == null || msg.location.longitude == null) {
182
+ return callback({
183
+ error: "location property needs both latitude and longitude",
184
+ });
185
+ }
186
+
187
+ form.payload.tasks[0].payload.send_type = 1;
188
+ form.payload.tasks[0].payload.location_data = {
189
+ coordinates: {
190
+ latitude: msg.location.latitude,
191
+ longitude: msg.location.longitude,
192
+ },
193
+ is_current_location: !!msg.location.current,
194
+ is_live_location: !!msg.location.live,
195
+ };
196
+ }
197
+
198
+ cb();
199
+ }
200
+
201
+ function send(form, threadID, callback, replyToMessage) {
202
+ if (replyToMessage) {
203
+ form.payload.tasks[0].payload.reply_metadata = {
204
+ reply_source_id: replyToMessage,
205
+ reply_source_type: 1,
206
+ reply_type: 0,
207
+ };
208
+ }
209
+ const mqttClient = ctx.mqttClient;
210
+ form.payload.tasks.forEach((task) => {
211
+ task.payload = JSON.stringify(task.payload);
212
+ });
213
+ form.payload = JSON.stringify(form.payload);
214
+
215
+ return mqttClient.publish(
216
+ "/ls_req",
217
+ JSON.stringify(form),
218
+ function (err, data) {
219
+ if (err) {
220
+ log.error("Error publishing message: ", err);
221
+ callback(err);
222
+ } else {
223
+ log.info("Message published successfully with data: ", data);
224
+ callback(null, data);
225
+ }
226
+ },
227
+ );
228
+ }
229
+
230
+ return function sendMessageMqtt(msg, threadID, callback, replyToMessage) {
231
+ if (
232
+ !callback &&
233
+ (utils.getType(threadID) === "Function" ||
234
+ utils.getType(threadID) === "AsyncFunction")
235
+ ) {
236
+ return threadID({ error: "Pass a threadID as a second argument." });
237
+ }
238
+ if (!replyToMessage && utils.getType(callback) === "String") {
239
+ replyToMessage = callback;
240
+ callback = function () {};
241
+ }
242
+
243
+ if (!callback) {
244
+ callback = function (err, friendList) {};
245
+ }
246
+
247
+ var msgType = utils.getType(msg);
248
+ var threadIDType = utils.getType(threadID);
249
+ var messageIDType = utils.getType(replyToMessage);
250
+
251
+ if (msgType !== "String" && msgType !== "Object") {
252
+ return callback({
253
+ error:
254
+ "Message should be of type string or object and not " + msgType + ".",
255
+ });
256
+ }
257
+
258
+ if (msgType === "String") {
259
+ msg = { body: msg };
260
+ }
261
+
262
+ const timestamp = Date.now();
263
+ // get full date time
264
+ const epoch = timestamp << 22;
265
+ //const otid = epoch + 0; // TODO replace with randomInt(0, 2**22)
266
+ const otid = epoch + Math.floor(Math.random() * 4194304);
267
+
268
+ const form = {
269
+ app_id: "2220391788200892",
270
+ payload: {
271
+ tasks: [
272
+ {
273
+ label: "46",
274
+ payload: {
275
+ thread_id: threadID.toString(),
276
+ otid: otid.toString(),
277
+ source: 0,
278
+ send_type: 1,
279
+ sync_group: 1,
280
+ text:
281
+ msg.body != null && msg.body != undefined
282
+ ? msg.body.toString()
283
+ : "",
284
+ initiating_source: 1,
285
+ skip_url_preview_gen: 0,
286
+ },
287
+ queue_name: threadID.toString(),
288
+ task_id: 0,
289
+ failure_count: null,
290
+ },
291
+ {
292
+ label: "21",
293
+ payload: {
294
+ thread_id: threadID.toString(),
295
+ last_read_watermark_ts: Date.now(),
296
+ sync_group: 1,
297
+ },
298
+ queue_name: threadID.toString(),
299
+ task_id: 1,
300
+ failure_count: null,
301
+ },
302
+ ],
303
+ epoch_id: epoch_id(),
304
+ version_id: "6120284488008082",
305
+ data_trace_id: null,
306
+ },
307
+ request_id: 1,
308
+ type: 3,
309
+ };
310
+
311
+ handleEmoji(msg, form, callback, function () {
312
+ handleLocation(msg, form, callback, function () {
313
+ handleMention(msg, form, callback, function () {
314
+ handleSticker(msg, form, callback, function () {
315
+ handleAttachment(msg, form, callback, function () {
316
+ send(form, threadID, callback, replyToMessage);
317
+ });
318
+ });
319
+ });
320
+ });
321
+ });
322
+ };
323
+ };
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ // @NethWs3Dev
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return async function sendTypingIndicatorV2(sendTyping, threadID, callback) {
8
+ // ── sendTypingE2EE: route E2EE typing indicator through the bridge ──────
9
+ if (ctx.globalOptions && ctx.globalOptions.enableE2EE) {
10
+ var _e2eeMod = require('../e2ee');
11
+ if (_e2eeMod.isE2EEChatJid(String(threadID))) {
12
+ return _e2eeMod.createBridge(ctx).sendTyping(threadID, sendTyping !== false)
13
+ .then(function (r) { if (typeof callback === 'function') callback(null, r); return r; })
14
+ .catch(function (e) { if (typeof callback === 'function') callback(e); });
15
+ }
16
+ }
17
+ // ── end sendTypingE2EE ────────────────────────────────────────────────────
18
+
19
+ const mqttClient = ctx.mqttClient || global.mqttClient;
20
+ if (!mqttClient) {
21
+ if (typeof callback === 'function') callback(new Error('No MQTT client available for typing indicator'));
22
+ return;
23
+ }
24
+
25
+ let count_req = 0;
26
+ var wsContent = {
27
+ app_id: 2220391788200892,
28
+ payload: JSON.stringify({
29
+ label: 3,
30
+ payload: JSON.stringify({
31
+ thread_key: threadID.toString(),
32
+ is_group_thread: +(threadID.toString().length >= 16),
33
+ is_typing: +sendTyping,
34
+ attribution: 0
35
+ }),
36
+ version: 5849951561777440
37
+ }),
38
+ request_id: ++count_req,
39
+ type: 4
40
+ };
41
+
42
+ return new Promise((resolve, reject) => {
43
+ mqttClient.publish('/ls_req', JSON.stringify(wsContent), {}, (err, _packet) => {
44
+ if (err) {
45
+ if (typeof callback === 'function') callback(err);
46
+ reject(err);
47
+ } else {
48
+ if (typeof callback === 'function') callback(null, _packet);
49
+ resolve(_packet);
50
+ }
51
+ });
52
+ });
53
+ };
54
+ };
@@ -0,0 +1,92 @@
1
+ /**
2
+ * ===========================================================
3
+ * 🧑‍💻 Author: HRIDOY (HRIDOY)
4
+ * 🔰 Owner & Developer
5
+ * 🌐 GitHub: https://github.com/hridoy-dev
6
+ * -----------------------------------------------------------
7
+ * 🕊️ Respect the creator & give proper credits if reused.
8
+ * ===========================================================
9
+ */
10
+ "use strict";
11
+
12
+ var utils = require("../utils");
13
+ var log = require("npmlog");
14
+
15
+ module.exports = function (defaultFuncs, api, ctx) {
16
+ /** Developed by HRIDOY | GitHub: hridoy-dev | Instagram: */
17
+ return function setActiveStatus(isActive, callback) {
18
+ var resolveFunc = function () { };
19
+ var rejectFunc = function () { };
20
+ var returnPromise = new Promise(function (resolve, reject) {
21
+ resolveFunc = resolve;
22
+ rejectFunc = reject;
23
+ });
24
+
25
+ if (!callback) {
26
+ callback = function (err, data) {
27
+ if (err) return rejectFunc(err);
28
+ resolveFunc(data);
29
+ };
30
+ }
31
+
32
+ if (typeof isActive !== "boolean") {
33
+ return callback({ error: "isActive must be a boolean value" });
34
+ }
35
+
36
+ const form = {
37
+ av: ctx.userID,
38
+ __aaid: 0,
39
+ __user: ctx.userID,
40
+ __a: 1,
41
+ __req: utils.getSignatureID(),
42
+ __hs: "20351.HYP:comet_pkg.2.1...0",
43
+ dpr: 1,
44
+ __ccg: "EXCELLENT",
45
+ __rev: "1027388793",
46
+ __s: utils.getSignatureID(),
47
+ __hsi: "7552256848274926554",
48
+ __comet_req: 15,
49
+ fb_dtsg: ctx.fb_dtsg,
50
+ jazoest: ctx.ttstamp,
51
+ lsd: ctx.fb_dtsg,
52
+ __spin_r: "1027388793",
53
+ __spin_b: "trunk",
54
+ __spin_t: Date.now(),
55
+ fb_api_caller_class: "RelayModern",
56
+ fb_api_req_friendly_name: "UpdatePresenceSettingsMutation",
57
+ variables: JSON.stringify({
58
+ input: {
59
+ online_policy: "ALLOWLIST",
60
+ web_allowlist: [],
61
+ web_visibility: isActive,
62
+ actor_id: ctx.userID.toString(),
63
+ client_mutation_id: "1"
64
+ }
65
+ }),
66
+ server_timestamps: true,
67
+ doc_id: "9444355898946246"
68
+ };
69
+
70
+ defaultFuncs
71
+ .post("https://www.facebook.com/api/graphql/", ctx.jar, form)
72
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
73
+ .then(function (resData) {
74
+ if (resData.error) {
75
+ throw resData;
76
+ }
77
+
78
+ return callback(null, {
79
+ success: true,
80
+ activeStatus: isActive,
81
+ response: resData
82
+ });
83
+ })
84
+ .catch(function (err) {
85
+ log.error("setActiveStatus", err);
86
+ return callback(err);
87
+ });
88
+
89
+ return returnPromise;
90
+ };
91
+ };
92
+ /** Developed by HRIDOY | GitHub: hridoy-dev | Please give credits if reused. */
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+
3
+ var log = require("npmlog");
4
+
5
+ const utils = require("../utils");
6
+ // @NethWs3Dev
7
+
8
+ module.exports = function (defaultFuncs, api, ctx) {
9
+ return function setMessageReaction(
10
+ reaction,
11
+ messageID,
12
+ callback,
13
+ forceCustomReaction,
14
+ ) {
15
+ let resolveFunc = function () {};
16
+ let rejectFunc = function () {};
17
+ const returnPromise = new Promise(function (resolve, reject) {
18
+ resolveFunc = resolve;
19
+ rejectFunc = reject;
20
+ });
21
+
22
+ if (!callback) {
23
+ callback = function (err, friendList) {
24
+ if (err) {
25
+ return rejectFunc(err);
26
+ }
27
+ resolveFunc(friendList);
28
+ };
29
+ }
30
+
31
+ // ── sendReactionE2EE: route E2EE reactions through the bridge ─────────────
32
+ if (ctx.globalOptions && ctx.globalOptions.enableE2EE) {
33
+ var _e2eeMod = require('../e2ee');
34
+ var _jid = global._e2eeMessageMap && global._e2eeMessageMap.get(String(messageID));
35
+ if (_jid && _e2eeMod.isE2EEChatJid(_jid)) {
36
+ var _senderJid = (global._e2eeSenderJidMap && global._e2eeSenderJidMap.get(String(messageID))) || null;
37
+ // Always route through the bridge when the JID is confirmed E2EE —
38
+ // never fall through to the HTTP path which cannot reach E2EE threads.
39
+ // senderJid is required by the E2EE protocol; fall back to chatJid for DMs
40
+ // (in a DM the chatJid IS the other person's JID).
41
+ var _effectiveSender = _senderJid || _jid;
42
+ _e2eeMod.createBridge(ctx).sendReaction(_jid, messageID, _effectiveSender, reaction)
43
+ .then(function (r) { callback(null, r); resolveFunc(r); })
44
+ .catch(function (e) {
45
+ var log = require('../utils').log;
46
+ log.error("setMessageReaction", "E2EE sendReaction failed — jid:" + _jid +
47
+ " msgID:" + messageID + " sender:" + _effectiveSender + " emoji:" + reaction +
48
+ " err:" + (e && e.message ? e.message : String(e)));
49
+ callback(e); rejectFunc(e);
50
+ });
51
+ return returnPromise;
52
+ }
53
+ }
54
+ // ── end sendReactionE2EE ──────────────────────────────────────────────────
55
+
56
+ switch (reaction) {
57
+ case "\uD83D\uDE0D": //:heart_eyes:
58
+ case "\uD83D\uDE06": //:laughing:
59
+ case "\uD83D\uDE2E": //:open_mouth:
60
+ case "\uD83D\uDE22": //:cry:
61
+ case "\uD83D\uDE20": //:angry:
62
+ case "\uD83D\uDC4D": //:thumbsup:
63
+ case "\uD83D\uDC4E": //:thumbsdown:
64
+ case "\u2764": //:heart:
65
+ case "\uD83D\uDC97": //:glowingheart:
66
+ case "":
67
+ //valid
68
+ break;
69
+ case ":heart_eyes:":
70
+ case ":love:":
71
+ reaction = "\uD83D\uDE0D";
72
+ break;
73
+ case ":laughing:":
74
+ case ":haha:":
75
+ reaction = "\uD83D\uDE06";
76
+ break;
77
+ case ":open_mouth:":
78
+ case ":wow:":
79
+ reaction = "\uD83D\uDE2E";
80
+ break;
81
+ case ":cry:":
82
+ case ":sad:":
83
+ reaction = "\uD83D\uDE22";
84
+ break;
85
+ case ":angry:":
86
+ reaction = "\uD83D\uDE20";
87
+ break;
88
+ case ":thumbsup:":
89
+ case ":like:":
90
+ reaction = "\uD83D\uDC4D";
91
+ break;
92
+ case ":thumbsdown:":
93
+ case ":dislike:":
94
+ reaction = "\uD83D\uDC4E";
95
+ break;
96
+ case ":heart:":
97
+ reaction = "\u2764";
98
+ break;
99
+ case ":glowingheart:":
100
+ reaction = "\uD83D\uDC97";
101
+ break;
102
+ default:
103
+ if (forceCustomReaction) {
104
+ break;
105
+ }
106
+ return callback({ error: "Reaction is not a valid emoji." });
107
+ }
108
+
109
+ const variables = {
110
+ data: {
111
+ client_mutation_id: ctx.clientMutationId++,
112
+ actor_id: ctx.userID,
113
+ action: reaction == "" ? "REMOVE_REACTION" : "ADD_REACTION",
114
+ message_id: messageID,
115
+ reaction: reaction,
116
+ },
117
+ };
118
+
119
+ const qs = {
120
+ doc_id: "1491398900900362",
121
+ variables: JSON.stringify(variables),
122
+ dpr: 1,
123
+ };
124
+
125
+ defaultFuncs
126
+ .postFormData(
127
+ "https://www.facebook.com/webgraphql/mutation/",
128
+ ctx.jar,
129
+ {},
130
+ qs,
131
+ )
132
+ .then(utils.parseAndCheckLogin(ctx.jar, defaultFuncs))
133
+ .then(function (resData) {
134
+ if (!resData) {
135
+ throw { error: "setReaction returned empty object." };
136
+ }
137
+ if (resData.error) {
138
+ throw resData;
139
+ }
140
+ callback(null);
141
+ })
142
+ .catch(function (err) {
143
+ log.error("setReaction", err);
144
+ return callback(err);
145
+ });
146
+
147
+ return returnPromise;
148
+ };
149
+ };
@@ -0,0 +1,62 @@
1
+
2
+ 'use strict';
3
+
4
+ const { generateOfflineThreadingID } = require('../utils');
5
+
6
+ function isCallable(func) {
7
+ try {
8
+ Reflect.apply(func, null, []);
9
+ return true;
10
+ } catch (error) {
11
+ return false;
12
+ }
13
+ }
14
+
15
+ module.exports = function (defaultFuncs, api, ctx) {
16
+ return function setMessageReactionMqtt(reaction, messageID, threadID, callback) {
17
+ if (!ctx.mqttClient) {
18
+ throw new Error('Not connected to MQTT');
19
+ }
20
+
21
+
22
+ ctx.wsReqNumber += 1;
23
+ ctx.wsTaskNumber += 1;
24
+
25
+ const taskPayload = {
26
+ thread_key: threadID,
27
+ timestamp_ms: Date.now(),
28
+ message_id: messageID,
29
+ reaction: reaction,
30
+ actor_id: ctx.userID,
31
+ reaction_style: null,
32
+ sync_group: 1,
33
+ send_attribution: Math.random() < 0.5 ? 65537 : 524289
34
+ };
35
+
36
+ const task = {
37
+ failure_count: null,
38
+ label: '29',
39
+ payload: JSON.stringify(taskPayload),
40
+ queue_name: JSON.stringify(['reaction', messageID]),
41
+ task_id: ctx.wsTaskNumber,
42
+ };
43
+
44
+ const content = {
45
+ app_id: '2220391788200892',
46
+ payload: JSON.stringify({
47
+ data_trace_id: null,
48
+ epoch_id: parseInt(generateOfflineThreadingID()),
49
+ tasks: [task],
50
+ version_id: '7158486590867448',
51
+ }),
52
+ request_id: ctx.wsReqNumber,
53
+ type: 3,
54
+ };
55
+
56
+ if (isCallable(callback)) {
57
+ ctx.reqCallbacks[ctx.wsReqNumber] = callback;
58
+ }
59
+
60
+ ctx.mqttClient.publish('/ls_req', JSON.stringify(content), { qos: 1, retain: false });
61
+ };
62
+ };