isoy 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. package/.gitattributes +2 -0
  2. package/Extra/Database/index.js +469 -0
  3. package/Extra/ExtraAddons.js +82 -0
  4. package/Extra/ExtraFindUID.js +62 -0
  5. package/Extra/ExtraGetThread.js +340 -0
  6. package/Extra/ExtraScreenShot.js +430 -0
  7. package/Extra/ExtraUptimeRobot.js +38 -0
  8. package/Extra/Html/Classic/script.js +119 -0
  9. package/Extra/Html/Classic/style.css +8 -0
  10. package/Extra/Security/AES_256_GCM/index.js +0 -0
  11. package/Extra/Security/Base/Step_1.js +6 -0
  12. package/Extra/Security/Base/Step_2.js +22 -0
  13. package/Extra/Security/Base/Step_3.js +22 -0
  14. package/Extra/Security/Base/index.js +173 -0
  15. package/Extra/Security/Index.js +5 -0
  16. package/Extra/Security/Step_1.js +6 -0
  17. package/Extra/Security/Step_2.js +22 -0
  18. package/Extra/Security/Step_3.js +22 -0
  19. package/Extra/Src/Change_Environment.js +24 -0
  20. package/Extra/Src/Check_Update.js +66 -0
  21. package/Extra/Src/History.js +115 -0
  22. package/Extra/Src/Instant_Update.js +65 -0
  23. package/Extra/Src/Last-Run.js +65 -0
  24. package/Extra/Src/Premium.js +81 -0
  25. package/Extra/Src/Release_Memory.js +41 -0
  26. package/Extra/Src/Websocket.js +213 -0
  27. package/Extra/Src/image/checkmate.jpg +0 -0
  28. package/Extra/Src/uuid.js +137 -0
  29. package/Func/AcceptAgreement.js +31 -0
  30. package/Func/ClearCache.js +64 -0
  31. package/Func/ReportV1.js +54 -0
  32. package/LICENSE +674 -0
  33. package/Language/index.json +217 -0
  34. package/Main.js +1216 -0
  35. package/README.md +140 -0
  36. package/SECURITY.md +18 -0
  37. package/broadcast.js +40 -0
  38. package/index.js +386 -0
  39. package/logger.js +67 -0
  40. package/package.json +93 -0
  41. package/src/Dev_Horizon_Data.js +125 -0
  42. package/src/Premium.js +25 -0
  43. package/src/Screenshot.js +83 -0
  44. package/src/addExternalModule.js +16 -0
  45. package/src/addUserToGroup.js +79 -0
  46. package/src/changeAdminStatus.js +79 -0
  47. package/src/changeArchivedStatus.js +41 -0
  48. package/src/changeAvt.js +85 -0
  49. package/src/changeBio.js +65 -0
  50. package/src/changeBlockedStatus.js +36 -0
  51. package/src/changeGroupImage.js +106 -0
  52. package/src/changeNickname.js +45 -0
  53. package/src/changeThreadColor.js +62 -0
  54. package/src/changeThreadEmoji.js +42 -0
  55. package/src/createNewGroup.js +70 -0
  56. package/src/createPoll.js +60 -0
  57. package/src/deleteMessage.js +45 -0
  58. package/src/deleteThread.js +43 -0
  59. package/src/forwardAttachment.js +48 -0
  60. package/src/getAccessToken.js +28 -0
  61. package/src/getCurrentUserID.js +7 -0
  62. package/src/getEmojiUrl.js +27 -0
  63. package/src/getFriendsList.js +73 -0
  64. package/src/getMessage.js +80 -0
  65. package/src/getThreadHistory.js +537 -0
  66. package/src/getThreadInfo.js +425 -0
  67. package/src/getThreadList.js +213 -0
  68. package/src/getThreadMain.js +220 -0
  69. package/src/getThreadPictures.js +59 -0
  70. package/src/getUID.js +59 -0
  71. package/src/getUserID.js +62 -0
  72. package/src/getUserInfo.js +113 -0
  73. package/src/getUserInfoMain.js +65 -0
  74. package/src/getUserInfoV2.js +32 -0
  75. package/src/getUserInfoV3.js +63 -0
  76. package/src/getUserInfoV4.js +55 -0
  77. package/src/getUserInfoV5.js +61 -0
  78. package/src/handleFriendRequest.js +46 -0
  79. package/src/handleMessageRequest.js +49 -0
  80. package/src/httpGet.js +49 -0
  81. package/src/httpPost.js +48 -0
  82. package/src/httpPostFormData.js +41 -0
  83. package/src/listenMqtt.js +787 -0
  84. package/src/logout.js +68 -0
  85. package/src/markAsDelivered.js +48 -0
  86. package/src/markAsRead.js +70 -0
  87. package/src/markAsReadAll.js +43 -0
  88. package/src/markAsSeen.js +51 -0
  89. package/src/muteThread.js +47 -0
  90. package/src/removeUserFromGroup.js +49 -0
  91. package/src/resolvePhotoUrl.js +37 -0
  92. package/src/searchForThread.js +43 -0
  93. package/src/sendMessage.js +440 -0
  94. package/src/sendTypingIndicator.js +80 -0
  95. package/src/setMessageReaction.js +109 -0
  96. package/src/setPostReaction.js +102 -0
  97. package/src/setTitle.js +74 -0
  98. package/src/threadColors.js +39 -0
  99. package/src/unfriend.js +43 -0
  100. package/src/unsendMessage.js +40 -0
  101. package/test/Database_Test.js +4 -0
  102. package/test/Db2.js +530 -0
  103. package/test/Horizon_Database/A_README.md +1 -0
  104. package/test/Horizon_Database/Database.db +0 -0
  105. package/test/data/shareAttach.js +146 -0
  106. package/test/data/something.mov +0 -0
  107. package/test/data/test.png +0 -0
  108. package/test/data/test.txt +7 -0
  109. package/test/env/.env +0 -0
  110. package/test/example-config.json +18 -0
  111. package/test/example-db.db +0 -0
  112. package/test/memoryleak.js +18 -0
  113. package/test/test-page.js +140 -0
  114. package/test/test.js +385 -0
  115. package/test/testv2.js +18 -0
  116. package/utils.js +1683 -0
@@ -0,0 +1,440 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Được Fix Hay Làm Màu Bởi: @HarryWakazaki
5
+ * 21/4/2022
6
+ */
7
+
8
+ var utils = require("../utils");
9
+ var log = require("npmlog");
10
+ var bluebird = require("bluebird");
11
+ var fs = require('fs-extra');
12
+
13
+ var allowedProperties = {
14
+ attachment: true,
15
+ url: true,
16
+ sticker: true,
17
+ emoji: true,
18
+ emojiSize: true,
19
+ body: true,
20
+ mentions: true,
21
+ location: true,
22
+ };
23
+
24
+ var AntiText = "Your criminal activity was detected while attempting to send an Appstate file";
25
+ var Location_Stack;
26
+
27
+ module.exports = function (defaultFuncs, api, ctx) {
28
+
29
+ let customfont = {
30
+ a: "𝖺",
31
+ b: "𝖻",
32
+ c: "𝖼",
33
+ d: "𝖽",
34
+ e: "𝖾",
35
+ f: "𝖿",
36
+ g: "𝗀",
37
+ h: "𝗁",
38
+ i: "𝗂",
39
+ j: "𝗃",
40
+ k: "𝗄",
41
+ l: "𝗅",
42
+ m: "𝗆",
43
+ n: "𝗇",
44
+ o: "𝗈",
45
+ p: "𝗉",
46
+ q: "𝗊",
47
+ r: "𝗋",
48
+ s: "𝗌",
49
+ t: "𝗍",
50
+ u: "𝗎",
51
+ v: "𝗏",
52
+ w: "𝗐",
53
+ x: "𝗑",
54
+ y: "𝗒",
55
+ z: "𝗓",
56
+ A: "𝖠",
57
+ B: "𝖡",
58
+ C: "𝖢",
59
+ D: "𝖣",
60
+ E: "𝖤",
61
+ F: "𝖥",
62
+ G: "𝖦",
63
+ H: "𝖧",
64
+ I: "𝖨",
65
+ J: "𝖩",
66
+ K: "𝖪",
67
+ L: "𝖫",
68
+ M: "𝖬",
69
+ N: "𝖭",
70
+ O: "𝖮",
71
+ P: "𝖯",
72
+ Q: "𝖰",
73
+ R: "𝖱",
74
+ S: "𝖲",
75
+ T: "𝖳",
76
+ U: "𝖴",
77
+ V: "𝖵",
78
+ W: "𝖶",
79
+ X: "𝖷",
80
+ Y: "𝖸",
81
+ Z: "𝖹",
82
+ };
83
+ function customfont1(inputString) {
84
+ const replacedString = inputString.replace(/[A-Za-z]/g, (char) => {
85
+ return customfont[char] || char;
86
+ });
87
+ return replacedString;
88
+ }
89
+ function uploadAttachment(attachments, callback) {
90
+ var uploads = [];
91
+
92
+ // create an array of promises
93
+ for (var i = 0; i < attachments.length; i++) {
94
+ if (!utils.isReadableStream(attachments[i])) throw { error: "Attachment should be a readable stream and not " + utils.getType(attachments[i]) + "." };
95
+ var form = {
96
+ upload_1024: attachments[i],
97
+ voice_clip: "true"
98
+ };
99
+
100
+ uploads.push(
101
+ defaultFuncs
102
+ .postFormData("https://upload.facebook.com/ajax/mercury/upload.php", ctx.jar, form, {})
103
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
104
+ .then(function (resData) {
105
+ if (resData.error) throw resData;
106
+ // We have to return the data unformatted unless we want to change it
107
+ // back in sendMessage.
108
+ return resData.payload.metadata[0];
109
+ })
110
+ );
111
+ }
112
+
113
+ // resolve all promises
114
+ bluebird
115
+ .all(uploads)
116
+ .then(resData => callback(null, resData)
117
+ )
118
+ .catch(function (err) {
119
+ log.error("uploadAttachment", err);
120
+ return callback(err);
121
+ });
122
+ }
123
+
124
+ function getUrl(url, callback) {
125
+ var form = {
126
+ image_height: 960,
127
+ image_width: 960,
128
+ uri: url
129
+ };
130
+
131
+ defaultFuncs
132
+ .post("https://www.facebook.com/message_share_attachment/fromURI/", ctx.jar, form)
133
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
134
+ .then(function (resData) {
135
+ if (resData.error) return callback(resData);
136
+ if (!resData.payload) return callback({ error: "Invalid url" });
137
+ callback(null, resData.payload.share_data.share_params);
138
+ })
139
+ .catch(function (err) {
140
+ log.error("getUrl", err);
141
+ return callback(err);
142
+ });
143
+ }
144
+
145
+ function sendContent(form, threadID, isSingleUser, messageAndOTID, callback) {
146
+ // There are three cases here:
147
+ // 1. threadID is of type array, where we're starting a new group chat with users
148
+ // specified in the array.
149
+ // 2. User is sending a message to a specific user.
150
+ // 3. No additional form params and the message goes to an existing group chat.
151
+ if (utils.getType(threadID) === "Array") {
152
+ for (var i = 0; i < threadID.length; i++) form["specific_to_list[" + i + "]"] = "fbid:" + threadID[i];
153
+ form["specific_to_list[" + threadID.length + "]"] = "fbid:" + ctx.userID;
154
+ form["client_thread_id"] = "root:" + messageAndOTID;
155
+ log.info("sendMessage", "Sending message to multiple users: " + threadID);
156
+ }
157
+ else {
158
+ // This means that threadID is the id of a user, and the chat
159
+ // is a single person chat
160
+ if (isSingleUser) {
161
+ form["specific_to_list[0]"] = "fbid:" + threadID;
162
+ form["specific_to_list[1]"] = "fbid:" + ctx.userID;
163
+ form["other_user_fbid"] = threadID;
164
+ }
165
+ else form["thread_fbid"] = threadID;
166
+ }
167
+
168
+ if (ctx.globalOptions.pageID) {
169
+ form["author"] = "fbid:" + ctx.globalOptions.pageID;
170
+ form["specific_to_list[1]"] = "fbid:" + ctx.globalOptions.pageID;
171
+ form["creator_info[creatorID]"] = ctx.userID;
172
+ form["creator_info[creatorType]"] = "direct_admin";
173
+ form["creator_info[labelType]"] = "sent_message";
174
+ form["creator_info[pageID]"] = ctx.globalOptions.pageID;
175
+ form["request_user_id"] = ctx.globalOptions.pageID;
176
+ form["creator_info[profileURI]"] = "https://www.facebook.com/profile.php?id=" + ctx.userID;
177
+ }
178
+
179
+ if (global.Fca.Require.FastConfig.AntiSendAppState == true) {
180
+ try {
181
+ if (Location_Stack != undefined || Location_Stack != null) {
182
+ let location = (((Location_Stack).replace("Error",'')).split('\n')[7]).split(' ');
183
+ let format = {
184
+ Source: (location[6]).split('s:')[0].replace("(",'') + 's',
185
+ Line: (location[6]).split('s:')[1].replace(")",'')
186
+ };
187
+ form.body = AntiText + "\n- Source: " + format.Source + "\n- Line: " + format.Line;
188
+ }
189
+ }
190
+ catch (e) {}
191
+ }
192
+
193
+ defaultFuncs
194
+ .post("https://www.facebook.com/messaging/send/", ctx.jar, form)
195
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
196
+ .then(function (resData) {
197
+ Location_Stack = undefined;
198
+ if (!resData) return callback({ error: "Send message failed." });
199
+ if (resData.error) {
200
+ if (resData.error === 1545012) log.warn("sendMessage", "Got error 1545012. This might mean that you're not part of the conversation " + threadID);
201
+ return callback(resData);
202
+ }
203
+
204
+ var messageInfo = resData.payload.actions.reduce(function (p, v) {
205
+ return (
206
+ {
207
+ threadID: v.thread_fbid,
208
+ messageID: v.message_id,
209
+ timestamp: v.timestamp
210
+ } || p
211
+ );
212
+ }, null);
213
+ return callback(null, messageInfo);
214
+ })
215
+ .catch(function (err) {
216
+ log.error("sendMessage", err);
217
+ if (utils.getType(err) == "Object" && err.error === "Not logged in.") ctx.loggedIn = false;
218
+ return callback(err,null);
219
+ });
220
+ }
221
+
222
+ function send(form, threadID, messageAndOTID, callback, isGroup) {
223
+ //Full Fix sendMessage
224
+ if (utils.getType(threadID) === "Array") sendContent(form, threadID, false, messageAndOTID, callback);
225
+ else {
226
+ var THREADFIX = "ThreadID".replace("ThreadID",threadID); // i cũng đôn nâu
227
+ if (THREADFIX.length <= 15 || global.Fca.isUser.includes(threadID)) sendContent(form, threadID, !isGroup, messageAndOTID, callback);
228
+ else if (THREADFIX.length >= 15 && THREADFIX.indexOf(1) != 0 || global.Fca.isThread.includes(threadID)) sendContent(form, threadID, threadID.length === 15, messageAndOTID, callback);
229
+ else {
230
+ if (global.Fca.Data.event.isGroup) {
231
+ sendContent(form, threadID, threadID.length === 15, messageAndOTID, callback);
232
+ global.Fca.isThread.push(threadID);
233
+ }
234
+ else {
235
+ sendContent(form, threadID, !isGroup, messageAndOTID, callback);
236
+ global.Fca.isUser.push(threadID);
237
+ }
238
+ }
239
+ }
240
+ }
241
+
242
+ function handleUrl(msg, form, callback, cb) {
243
+ if (msg.url) {
244
+ form["shareable_attachment[share_type]"] = "100";
245
+ getUrl(msg.url, function (err, params) {
246
+ if (err) return callback(err);
247
+ form["shareable_attachment[share_params]"] = params;
248
+ cb();
249
+ });
250
+ }
251
+ else cb();
252
+ }
253
+
254
+ function handleLocation(msg, form, callback, cb) {
255
+ if (msg.location) {
256
+ if (msg.location.latitude == null || msg.location.longitude == null) return callback({ error: "location property needs both latitude and longitude" });
257
+ form["location_attachment[coordinates][latitude]"] = msg.location.latitude;
258
+ form["location_attachment[coordinates][longitude]"] = msg.location.longitude;
259
+ form["location_attachment[is_current_location]"] = !!msg.location.current;
260
+ }
261
+ cb();
262
+ }
263
+
264
+ function handleSticker(msg, form, callback, cb) {
265
+ if (msg.sticker) form["sticker_id"] = msg.sticker;
266
+ cb();
267
+ }
268
+
269
+ function handleEmoji(msg, form, callback, cb) {
270
+ if (msg.emojiSize != null && msg.emoji == null) return callback({ error: "emoji property is empty" });
271
+ if (msg.emoji) {
272
+ if (msg.emojiSize == null) msg.emojiSize = "medium";
273
+ if (msg.emojiSize != "small" && msg.emojiSize != "medium" && msg.emojiSize != "large") return callback({ error: "emojiSize property is invalid" });
274
+ if (form["body"] != null && form["body"] != "") return callback({ error: "body is not empty" });
275
+ form["body"] = msg.emoji;
276
+ form["tags[0]"] = "hot_emoji_size:" + msg.emojiSize;
277
+ }
278
+ cb();
279
+ }
280
+
281
+ function handleAttachment(msg, form, callback, cb) {
282
+ if (msg.attachment) {
283
+ form["image_ids"] = [];
284
+ form["gif_ids"] = [];
285
+ form["file_ids"] = [];
286
+ form["video_ids"] = [];
287
+ form["audio_ids"] = [];
288
+
289
+ if (utils.getType(msg.attachment) !== "Array") msg.attachment = [msg.attachment];
290
+
291
+ if (global.Fca.Require.FastConfig.AntiSendAppState) {
292
+ try {
293
+ const AllowList = [".png", ".mp3", ".mp4", ".wav", ".gif", ".jpg", ".tff"];
294
+ const CheckList = [".json", ".js", ".txt", ".docx", '.php'];
295
+ var Has;
296
+ for (let i = 0; i < (msg.attachment).length; i++) {
297
+ if (utils.isReadableStream((msg.attachment)[i])) {
298
+ var path = (msg.attachment)[i].path != undefined ? (msg.attachment)[i].path : "nonpath";
299
+ if (AllowList.some(i => path.includes(i))) continue;
300
+ else if (CheckList.some(i => path.includes(i))) {
301
+ let data = fs.readFileSync(path, 'utf-8');
302
+ if (data.includes("datr")) {
303
+ Has = true;
304
+ var err = new Error();
305
+ Location_Stack = err.stack;
306
+ }
307
+ else continue;
308
+ }
309
+ }
310
+ }
311
+ if (Has == true) {
312
+ msg.attachment = [fs.createReadStream(__dirname + "/../Extra/Src/Image/checkmate.jpg")];
313
+ }
314
+ }
315
+ catch (e) {}
316
+ }
317
+ uploadAttachment(msg.attachment, function (err, files) {
318
+ if (err) return callback(err);
319
+ files.forEach(function (file) {
320
+ var key = Object.keys(file);
321
+ var type = key[0]; // image_id, file_id, etc
322
+ form["" + type + "s"].push(file[type]); // push the id
323
+ });
324
+ cb();
325
+ });
326
+ }
327
+ else cb();
328
+ }
329
+
330
+ function handleMention(msg, form, callback, cb) {
331
+ if (msg.mentions) {
332
+ for (let i = 0; i < msg.mentions.length; i++) {
333
+ const mention = msg.mentions[i];
334
+ const tag = mention.tag;
335
+ if (typeof tag !== "string") return callback({ error: "Mention tags must be strings." });
336
+ const offset = msg.body.indexOf(tag, mention.fromIndex || 0);
337
+ if (offset < 0) log.warn("handleMention", 'Mention for "' + tag + '" not found in message string.');
338
+ if (mention.id == null) log.warn("handleMention", "Mention id should be non-null.");
339
+
340
+ const id = mention.id || 0;
341
+ const emptyChar = '\u200E';
342
+ form["body"] = emptyChar + msg.body;
343
+ form["profile_xmd[" + i + "][offset]"] = offset + 1;
344
+ form["profile_xmd[" + i + "][length]"] = tag.length;
345
+ form["profile_xmd[" + i + "][id]"] = id;
346
+ form["profile_xmd[" + i + "][type]"] = "p";
347
+ }
348
+ }
349
+ cb();
350
+ }
351
+
352
+ return function sendMessage(msg, threadID, callback, replyToMessage, isGroup) {
353
+ typeof isGroup == "undefined" ? isGroup = null : "";
354
+ if (!callback && (utils.getType(threadID) === "Function" || utils.getType(threadID) === "AsyncFunction")) return threadID({ error: "Pass a threadID as a second argument." });
355
+ if (!replyToMessage && utils.getType(callback) === "String") {
356
+ replyToMessage = callback;
357
+ callback = function () { };
358
+ }
359
+
360
+ var resolveFunc = function () { };
361
+ var rejectFunc = function () { };
362
+ var returnPromise = new Promise(function (resolve, reject) {
363
+ resolveFunc = resolve;
364
+ rejectFunc = reject;
365
+ });
366
+
367
+ if (!callback) {
368
+ callback = function (err, data) {
369
+ if (err) return rejectFunc(err);
370
+ resolveFunc(data);
371
+ };
372
+ }
373
+
374
+ var msgType = utils.getType(msg);
375
+ var threadIDType = utils.getType(threadID);
376
+ var messageIDType = utils.getType(replyToMessage);
377
+
378
+ if (msgType !== "String" && msgType !== "Object") return callback({ error: "Message should be of type string or object and not " + msgType + "." });
379
+
380
+ // Changing this to accomodate an array of users
381
+ if (threadIDType !== "Array" && threadIDType !== "Number" && threadIDType !== "String") return callback({ error: "ThreadID should be of type number, string, or array and not " + threadIDType + "." });
382
+
383
+ if (replyToMessage && messageIDType !== 'String') return callback({ error: "MessageID should be of type string and not " + threadIDType + "." });
384
+
385
+ if (msgType === "String") msg = { body: msg };
386
+ var disallowedProperties = Object.keys(msg).filter(prop => !allowedProperties[prop]);
387
+ if (disallowedProperties.length > 0) return callback({ error: "Dissallowed props: `" + disallowedProperties.join(", ") + "`" });
388
+
389
+ var messageAndOTID = utils.generateOfflineThreadingID();
390
+
391
+ var form = {
392
+ client: "mercury",
393
+ action_type: "ma-type:user-generated-message",
394
+ author: "fbid:" + ctx.userID,
395
+ timestamp: Date.now(),
396
+ timestamp_absolute: "Today",
397
+ timestamp_relative: utils.generateTimestampRelative(),
398
+ timestamp_time_passed: "0",
399
+ is_unread: false,
400
+ is_cleared: false,
401
+ is_forward: false,
402
+ is_filtered_content: false,
403
+ is_filtered_content_bh: false,
404
+ is_filtered_content_account: false,
405
+ is_filtered_content_quasar: false,
406
+ is_filtered_content_invalid_app: false,
407
+ is_spoof_warning: false,
408
+ source: "source:chat:web",
409
+ "source_tags[0]": "source:chat",
410
+ body: msg.body ? customfont1(msg.body.toString()) : "",
411
+ html_body: false,
412
+ ui_push_phase: "V3",
413
+ status: "0",
414
+ offline_threading_id: messageAndOTID,
415
+ message_id: messageAndOTID,
416
+ threading_id: utils.generateThreadingID(ctx.clientID),
417
+ "ephemeral_ttl_mode:": "0",
418
+ manual_retry_cnt: "0",
419
+ has_attachment: !!(msg.attachment || msg.url || msg.sticker),
420
+ signatureID: utils.getSignatureID(),
421
+ replied_to_message_id: replyToMessage
422
+ };
423
+
424
+ handleLocation(msg, form, callback, () =>
425
+ handleSticker(msg, form, callback, () =>
426
+ handleAttachment(msg, form, callback, () =>
427
+ handleUrl(msg, form, callback, () =>
428
+ handleEmoji(msg, form, callback, () =>
429
+ handleMention(msg, form, callback, () =>
430
+ send(form, threadID, messageAndOTID, callback, isGroup)
431
+ )
432
+ )
433
+ )
434
+ )
435
+ )
436
+ );
437
+
438
+ return returnPromise;
439
+ };
440
+ };
@@ -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
+ };