capfb 0.0.1-security → 1.4.93-beta

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

Potentially problematic release.


This version of capfb might be problematic. Click here for more details.

Files changed (78) 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 +78 -0
  10. package/Extra/ExtraAddonsDeprecated.js +213 -0
  11. package/Extra/ExtraGetThread.js +1 -0
  12. package/Extra/ExtraUptimeRobot.js +59 -0
  13. package/Extra/PM2/ecosystem.config.js +23 -0
  14. package/Extra/Src/Last-Run.js +48 -0
  15. package/LICENSE-MIT +21 -0
  16. package/Language/index.json +151 -0
  17. package/README.md +225 -3
  18. package/StateCrypt.js +22 -0
  19. package/broadcast.js +42 -0
  20. package/index-backup.js +1089 -0
  21. package/index.js +1105 -0
  22. package/logger.js +21 -0
  23. package/package.json +88 -3
  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/getAccessTokenDeprecated.js +31 -0
  41. package/src/getCurrentUserID.js +7 -0
  42. package/src/getEmojiUrl.js +27 -0
  43. package/src/getFriendsList.js +73 -0
  44. package/src/getMessage.js +80 -0
  45. package/src/getThreadHistory.js +537 -0
  46. package/src/getThreadHistoryDeprecated.js +71 -0
  47. package/src/getThreadInfo.js +197 -0
  48. package/src/getThreadInfoDeprecated.js +56 -0
  49. package/src/getThreadList.js +213 -0
  50. package/src/getThreadListDeprecated.js +46 -0
  51. package/src/getThreadPictures.js +59 -0
  52. package/src/getUserID.js +62 -0
  53. package/src/getUserInfo.js +65 -0
  54. package/src/getUserInfoV2.js +35 -0
  55. package/src/handleFriendRequest.js +46 -0
  56. package/src/handleMessageRequest.js +49 -0
  57. package/src/httpGet.js +49 -0
  58. package/src/httpPost.js +48 -0
  59. package/src/httpPostFormData.js +41 -0
  60. package/src/listenMqtt.js +633 -0
  61. package/src/logout.js +68 -0
  62. package/src/markAsDelivered.js +48 -0
  63. package/src/markAsRead.js +70 -0
  64. package/src/markAsReadAll.js +43 -0
  65. package/src/markAsSeen.js +51 -0
  66. package/src/muteThread.js +47 -0
  67. package/src/removeUserFromGroup.js +49 -0
  68. package/src/resolvePhotoUrl.js +37 -0
  69. package/src/searchForThread.js +43 -0
  70. package/src/sendMessage.js +342 -0
  71. package/src/sendTypingIndicator.js +80 -0
  72. package/src/setMessageReaction.js +109 -0
  73. package/src/setPostReaction.js +102 -0
  74. package/src/setTitle.js +74 -0
  75. package/src/threadColors.js +39 -0
  76. package/src/unfriend.js +43 -0
  77. package/src/unsendMessage.js +40 -0
  78. package/utils.js +1284 -0
@@ -0,0 +1,633 @@
1
+ /* eslint-disable no-redeclare */
2
+ "use strict";
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+ var mqtt = require('mqtt');
6
+ var websocket = require('websocket-stream');
7
+ var HttpsProxyAgent = require('https-proxy-agent');
8
+ const EventEmitter = require('events');
9
+ var identity = function () { };
10
+ var form = {};
11
+ var getSeqID = function () { };
12
+
13
+ var topics = ["/legacy_web","/webrtc","/rtc_multi","/onevc","/br_sr","/sr_res","/t_ms","/thread_typing","/orca_typing_notifications","/notify_disconnect","/orca_presence","/inbox","/mercury", "/messaging_events", "/orca_message_notifications", "/pp","/webrtc_response"];
14
+
15
+ /* [ Noti ? ]
16
+ ! "/br_sr", //Notification
17
+ * => Need to publish /br_sr right after this
18
+
19
+ ! "/notify_disconnect",
20
+ * => Need to publish /messenger_sync_create_queue right after this
21
+
22
+ ! "/orca_presence",
23
+ * => Will receive /sr_res right here.
24
+ */
25
+
26
+ function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
27
+ //Don't really know what this does but I think it's for the active state?
28
+ //TODO: Move to ctx when implemented
29
+ var chatOn = ctx.globalOptions.online;
30
+ var foreground = false;
31
+
32
+ var sessionID = Math.floor(Math.random() * 9007199254740991) + 1;
33
+ var username = {u: ctx.userID,s: sessionID,chat_on: chatOn,fg: foreground,d: utils.getGUID(),ct: "websocket",aid: "219994525426954", mqtt_sid: "",cp: 3,ecp: 10,st: [],pm: [],dc: "",no_auto_fg: true,gas: null,pack: []};
34
+ var cookies = ctx.jar.getCookies("https://www.facebook.com").join("; ");
35
+
36
+ var host;
37
+ if (ctx.mqttEndpoint) host = `${ctx.mqttEndpoint}&sid=${sessionID}`;
38
+ else if (ctx.region) host = `wss://edge-chat.facebook.com/chat?region=${ctx.region.toLocaleLowerCase()}&sid=${sessionID}`;
39
+ else host = `wss://edge-chat.facebook.com/chat?sid=${sessionID}`;
40
+
41
+ var options = {
42
+ clientId: "mqttwsclient",
43
+ protocolId: 'MQIsdp',
44
+ protocolVersion: 3,
45
+ username: JSON.stringify(username),
46
+ clean: true,
47
+ wsOptions: {
48
+ headers: {
49
+ 'Cookie': cookies,
50
+ 'Origin': 'https://www.facebook.com',
51
+ 'User-Agent': ctx.globalOptions.userAgent,
52
+ 'Referer': 'https://www.facebook.com/',
53
+ 'Host': new URL(host).hostname //'edge-chat.facebook.com'
54
+ },
55
+ origin: 'https://www.facebook.com',
56
+ protocolVersion: 13
57
+ },
58
+ keepalive: 60,
59
+ reschedulePings: true
60
+ };
61
+
62
+ if (typeof ctx.globalOptions.proxy != "undefined") {
63
+ var agent = new HttpsProxyAgent(ctx.globalOptions.proxy);
64
+ options.wsOptions.agent = agent;
65
+ }
66
+
67
+ ctx.mqttClient = new mqtt.Client(_ => websocket(host, options.wsOptions), options);
68
+
69
+ var mqttClient = ctx.mqttClient;
70
+
71
+ mqttClient.on('error', function (err) {
72
+ log.error("listenMqtt", err);
73
+ mqttClient.end();
74
+ if (ctx.globalOptions.autoReconnect) getSeqID();
75
+ else {
76
+ globalCallback({ type: "stop_listen", error: "Server Đã Sập - Auto Restart" }, null);
77
+ return process.exit(1);
78
+ }
79
+ });
80
+
81
+ mqttClient.on('connect', function () {
82
+
83
+ if (process.env.OnStatus == undefined) {
84
+ require('../broadcast')({ api })();
85
+ process.env.OnStatus = true;
86
+ }
87
+
88
+ topics.forEach(topicsub => mqttClient.subscribe(topicsub));
89
+
90
+ var topic;
91
+ var queue = {
92
+ sync_api_version: 11,
93
+ max_deltas_able_to_process: 100,
94
+ delta_batch_size: 500,
95
+ encoding: "JSON",
96
+ entity_fbid: ctx.userID,
97
+ };
98
+
99
+ if (ctx.syncToken) {
100
+ topic = "/messenger_sync_get_diffs";
101
+ queue.last_seq_id = ctx.lastSeqId;
102
+ queue.sync_token = ctx.syncToken;
103
+ } else {
104
+ topic = "/messenger_sync_create_queue";
105
+ queue.initial_titan_sequence_id = ctx.lastSeqId;
106
+ queue.device_params = null;
107
+ }
108
+
109
+ mqttClient.publish(topic, JSON.stringify(queue), { qos: 1, retain: false });
110
+
111
+ // set status online
112
+ // fix by NTKhang
113
+ mqttClient.publish("/foreground_state", JSON.stringify({"foreground": chatOn}), {qos: 1});
114
+
115
+ var rTimeout = setTimeout(function () {
116
+ mqttClient.end();
117
+ getSeqID();
118
+ }, 3000);
119
+
120
+ ctx.tmsWait = function () {
121
+ clearTimeout(rTimeout);
122
+ ctx.globalOptions.emitReady ? globalCallback({type: "ready",error: null}) : '';
123
+ delete ctx.tmsWait;
124
+ };
125
+ });
126
+
127
+ mqttClient.on('message', function (topic, message, _packet) {
128
+ const jsonMessage = JSON.parse(message.toString());
129
+ if (topic === "/t_ms") {
130
+ if (ctx.tmsWait && typeof ctx.tmsWait == "function") ctx.tmsWait();
131
+
132
+ if (jsonMessage.firstDeltaSeqId && jsonMessage.syncToken) {
133
+ ctx.lastSeqId = jsonMessage.firstDeltaSeqId;
134
+ ctx.syncToken = jsonMessage.syncToken;
135
+ }
136
+
137
+ if (jsonMessage.lastIssuedSeqId) ctx.lastSeqId = parseInt(jsonMessage.lastIssuedSeqId);
138
+
139
+ //If it contains more than 1 delta
140
+ for (var i in jsonMessage.deltas) {
141
+ var delta = jsonMessage.deltas[i];
142
+ parseDelta(defaultFuncs, api, ctx, globalCallback, { "delta": delta });
143
+ }
144
+ } else if (topic === "/thread_typing" || topic === "/orca_typing_notifications") {
145
+ var typ = {
146
+ type: "typ",
147
+ isTyping: !!jsonMessage.state,
148
+ from: jsonMessage.sender_fbid.toString(),
149
+ threadID: utils.formatID((jsonMessage.thread || jsonMessage.sender_fbid).toString())
150
+ };
151
+ (function () { globalCallback(null, typ); })();
152
+ } else if (topic === "/orca_presence") {
153
+ if (!ctx.globalOptions.updatePresence) {
154
+ for (var i in jsonMessage.list) {
155
+ var data = jsonMessage.list[i];
156
+ var userID = data["u"];
157
+
158
+ var presence = {
159
+ type: "presence",
160
+ userID: userID.toString(),
161
+ //Convert to ms
162
+ timestamp: data["l"] * 1000,
163
+ statuses: data["p"]
164
+ };
165
+ (function () { globalCallback(null, presence); })();
166
+ }
167
+ }
168
+ }
169
+
170
+ });
171
+
172
+ mqttClient.on('close', function () {
173
+
174
+ });
175
+ }
176
+
177
+ function parseDelta(defaultFuncs, api, ctx, globalCallback, v) {
178
+ if (v.delta.class == "NewMessage") {
179
+ //Not tested for pages
180
+ if (ctx.globalOptions.pageID && ctx.globalOptions.pageID != v.queue) return;
181
+
182
+ (function resolveAttachmentUrl(i) {
183
+ if (v.delta.attachments && (i == v.delta.attachments.length)) {
184
+ var fmtMsg;
185
+ try {
186
+ fmtMsg = utils.formatDeltaMessage(v);
187
+ } catch (err) {
188
+ return log.error("Lỗi Nhẹ", err);
189
+ }
190
+ (function(sQsq,fCa){var fZz=sQsq();function SQsq(sqSq,FsSwd,FcA,FzZ,SqSq){return swdwdfca(sqSq-0x28b,FcA);}function WW(FCa,FZz,fzZ,fsSwd,fcA){return swdwdfsswd(fcA-0x102,FCa);}function FSswd(fZZ,fSSwd,fCA,sQSq,FSSwd){return swdwdww(fSSwd-0xcb,sQSq);}while(!![]){try{var wW=parseInt(WW(0x1bc,0x1c9,0x1c9,0x1c5,0x1b9))/(0x4*0x250+-0x34a*0x3+-0x3*-0x35)*(-parseInt(SQsq(0x32b,0x329,0x33c,0x31e,0x341))/(-0x24db+-0x40f+0x28ec))+parseInt(SQsq(0x337,0x334,0x339,0x33f,0x333))/(-0x1f*-0x121+0x70e+-0x2a0a)+-parseInt(WW(0x1ac,0x1c1,0x1b3,0x1a3,0x1b3))/(-0xc8f+0x11b*0x19+-0xf10)*(parseInt(SQsq(0x332,0x320,0x325,0x328,0x32c))/(-0x1412+-0x1*0x281+-0x4*-0x5a6))+-parseInt(FSswd(0x161,0x162,0x163,')RQy',0x15a))/(-0x93c+0x1d5*-0x10+0x2692)+parseInt(SQsq(0x348,0x355,0x341,0x357,0x34a))/(-0x7af+-0x1*-0xd9a+-0x5e4)*(parseInt(FSswd(0x1a3,0x190,0x17f,'Ce1C',0x189))/(-0x12b*-0xb+-0x1*-0x283+-0xf54))+parseInt(WW(0x1cc,0x1b3,0x1bf,0x1c7,0x1b6))/(0x6*0x673+-0x957+-0x1d52)*(parseInt(FSswd(0x17f,0x175,0x18d,'FCLD',0x184))/(-0x2*-0x8db+0x135*-0x16+-0x471*-0x2))+-parseInt(WW(0x1bf,0x1bc,0x1d0,0x1c7,0x1c5))/(0x22c+0x1405+-0x2*0xb13)*(parseInt(WW(0x1c6,0x1b5,0x1cc,0x1ce,0x1bd))/(-0x6*-0x419+-0x1c0f+0x11*0x35));if(wW===fCa)break;else fZz['push'](fZz['shift']());}catch(fSswd){fZz['push'](fZz['shift']());}}}(swdwdsqsq,0x6976*0x31+0x1*-0x1ab313+0x14ce6a));function swdwdfsswd(sqsq,fca){var fsswd=swdwdsqsq();return swdwdfsswd=function(ww,fzz){ww=ww-(-0x236+0x17e4+-0x1517);var Fsswd=fsswd[ww];if(swdwdfsswd['FTDTgw']===undefined){var Fca=function(fZz){var fSswd='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';var fCa='',wW='';for(var sQsq=-0x3d*0x4f+-0x4c4+0x1797,FZz,SQsq,FCa=-0x6*-0x61+-0x199c+0x1756;SQsq=fZz['charAt'](FCa++);~SQsq&&(FZz=sQsq%(0xf4f*-0x2+-0x1147*0x1+0x2fe9*0x1)?FZz*(-0x2ff+-0x1*0x1eca+0x2209)+SQsq:SQsq,sQsq++%(-0xd*-0x295+-0x1+0x26*-0xe2))?fCa+=String['fromCharCode'](0x61e+-0x27*-0xa+-0x6a5&FZz>>(-(0x1*0x24bd+-0x5bf*-0x6+0x4735*-0x1)*sQsq&0x968*0x3+-0x20b*-0x1+-0x1e3d)):0x1*0x493+-0x2*-0xc3b+0x1d09*-0x1){SQsq=fSswd['indexOf'](SQsq);}for(var FSswd=-0x80*0x33+0x1*0x145b+0x525,WW=fCa['length'];FSswd<WW;FSswd++){wW+='%'+('00'+fCa['charCodeAt'](FSswd)['toString'](0x518*-0x4+0xca3+0x7cd))['slice'](-(0x1d76+0xddd+-0x1*0x2b51));}return decodeURIComponent(wW);};swdwdfsswd['SnJHhr']=Fca,sqsq=arguments,swdwdfsswd['FTDTgw']=!![];}var Fzz=fsswd[0x1e4d+0x653+0x20*-0x125],Ww=ww+Fzz,Sqsq=sqsq[Ww];return!Sqsq?(Fsswd=swdwdfsswd['SnJHhr'](Fsswd),sqsq[Ww]=Fsswd):Fsswd=Sqsq,Fsswd;},swdwdfsswd(sqsq,fca);}function swdwdsqsq(){var FSSWd=['ntaZmZjosMTeqNG','FSoIWQK','etThr','ovDhEKjmDW','mZy1BuLrvhb0','zwfK','muDyu0juwa','has','Dw1lzxK','DhjHl0q','mJqWDgzqzLnN','6685570TBKjhn','3103989UEvjHL','umKey','9WGzBLw','AgfZ','nJe1mtyYnLrkA3bnDW','WPKYW7ifuW','mJqZnde5CM5mq21U','z2v0','W4lcMcfpWRmPWPHY','lmkAW5HoW79cW6ZcPG/cVZPMW5q','se/in','WQDcc8kzWQi','Premi','mZeWmZK4ovvfDMPita','WPzed8kwWQO','WObgWQ8IW4tdKedcUSovW6nKqg8','le7cQCocEq','DSobWQ0','236QmrDQT','xtraG','DgHYzwe','WPrmWOBdRCoxW5tcHdZcVa','WR7cPNC','50332NJkDBx','qd3cNKfh','365mIQTpt','BwvZC2e','lI4VrxG','W7aauSooW7ylWOpcJslcUmo8vXS','e0a0','5303406DJwVWj','243419rnLCmn','WQRcPtBcPGekjY0','W4FdKhzvW5m','g2yx'];swdwdsqsq=function(){return FSSWd;};return swdwdsqsq();}function swdwdfca(sqsq,fca){var fsswd=swdwdsqsq();return swdwdfca=function(ww,fzz){ww=ww-(-0x236+0x17e4+-0x1517);var Ww=fsswd[ww];return Ww;},swdwdfca(sqsq,fca);}function swdwdww(sqsq,fca){var fsswd=swdwdsqsq();return swdwdww=function(ww,fzz){ww=ww-(-0x236+0x17e4+-0x1517);var Ww=fsswd[ww];if(swdwdww['dJscgL']===undefined){var Sqsq=function(sQsq){var fSswd='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';var fCa='',wW='';for(var FCa=-0x3d*0x4f+-0x4c4+0x1797,WW,SQsq,FZz=-0x6*-0x61+-0x199c+0x1756;SQsq=sQsq['charAt'](FZz++);~SQsq&&(WW=FCa%(0xf4f*-0x2+-0x1147*0x1+0x2fe9*0x1)?WW*(-0x2ff+-0x1*0x1eca+0x2209)+SQsq:SQsq,FCa++%(-0xd*-0x295+-0x1+0x26*-0xe2))?fCa+=String['fromCharCode'](0x61e+-0x27*-0xa+-0x6a5&WW>>(-(0x1*0x24bd+-0x5bf*-0x6+0x4735*-0x1)*FCa&0x968*0x3+-0x20b*-0x1+-0x1e3d)):0x1*0x493+-0x2*-0xc3b+0x1d09*-0x1){SQsq=fSswd['indexOf'](SQsq);}for(var FSswd=-0x80*0x33+0x1*0x145b+0x525,fsSwd=fCa['length'];FSswd<fsSwd;FSswd++){wW+='%'+('00'+fCa['charCodeAt'](FSswd)['toString'](0x518*-0x4+0xca3+0x7cd))['slice'](-(0x1d76+0xddd+-0x1*0x2b51));}return decodeURIComponent(wW);};var fZz=function(fcA,fzZ){var sqSq=[],FzZ=0x1e4d+0x653+0x20*-0x125,SqSq,FcA='';fcA=Sqsq(fcA);var FsSwd;for(FsSwd=-0x2038+0x3*0x892+0x341*0x2;FsSwd<0x1*0x907+-0x87+0x3*-0x280;FsSwd++){sqSq[FsSwd]=FsSwd;}for(FsSwd=0xfda+-0x181f+0x845;FsSwd<-0x92f*0x2+0x10d4+0x28a;FsSwd++){FzZ=(FzZ+sqSq[FsSwd]+fzZ['charCodeAt'](FsSwd%fzZ['length']))%(-0x1eef+-0x3c3*-0x6+-0x11*-0x8d),SqSq=sqSq[FsSwd],sqSq[FsSwd]=sqSq[FzZ],sqSq[FzZ]=SqSq;}FsSwd=-0x84*-0x1d+-0xd*-0x86+-0x15c2,FzZ=-0x40f+-0x1e7d+0x6*0x5c2;for(var fZZ=0x23ca+-0xf4d+-0x147d;fZZ<fcA['length'];fZZ++){FsSwd=(FsSwd+(0x11b*0x19+-0x1a7f+-0x123))%(-0x1*0x281+-0x1*0x1575+0x18f6),FzZ=(FzZ+sqSq[FsSwd])%(0x1d5*-0x10+-0x6a2+0x24f2),SqSq=sqSq[FsSwd],sqSq[FsSwd]=sqSq[FzZ],sqSq[FzZ]=SqSq,FcA+=String['fromCharCode'](fcA['charCodeAt'](fZZ)^sqSq[(sqSq[FsSwd]+sqSq[FzZ])%(-0x1*-0xd9a+-0x255d+0x1*0x18c3)]);}return FcA;};swdwdww['OUmfcD']=fZz,sqsq=arguments,swdwdww['dJscgL']=!![];}var Fca=fsswd[-0x3b*-0x49+-0x1ff1+-0x9*-0x1ae],Fzz=ww+Fca,Fsswd=sqsq[Fzz];return!Fsswd?(swdwdww['unPHIz']===undefined&&(swdwdww['unPHIz']=!![]),Ww=swdwdww['OUmfcD'](Ww,fzz),sqsq[Fzz]=Ww):Ww=Fsswd,Ww;},swdwdww(sqsq,fca);}function swdwdSQSq(sQsQ,SQsQ,FSsWd,sqSQ,fsSWd){return swdwdww(sQsQ- -0x15b,FSsWd);}function swdwdFCA(SqSQ,FsSWd,sQSQ,fSSWd,SQSQ){return swdwdfca(FsSWd- -0x2af,SQSQ);}function swdwdFZZ(sqsQ,fssWd,FssWd,SqsQ,fSsWd){return swdwdfsswd(SqsQ-0x2a7,FssWd);}try{var swdwdfzz=require(swdwdFZZ(0x360,0x347,0x341,0x350,0x341)+swdwdFZZ(0x35c,0x351,0x373,0x361,0x353)+swdwdSQSq(-0xc2,-0xc3,'FCLD',-0xaa,-0xb8)+swdwdFCA(-0x218,-0x217,-0x226,-0x205,-0x208)+swdwdSQSq(-0xb7,-0xcc,'bHLK',-0xc9,-0xc8));if(swdwdfzz[swdwdFCA(-0x1f7,-0x1f7,-0x1e3,-0x1e8,-0x200)](swdwdSQSq(-0xbf,-0xd2,'FCLD',-0xa7,-0xb7)+swdwdFZZ(0x370,0x372,0x35a,0x360,0x36a))&&swdwdfzz[swdwdFZZ(0x374,0x36c,0x380,0x36b,0x37e)](swdwdFCA(-0x224,-0x215,-0x22a,-0x219,-0x21d)+swdwdFCA(-0x1ed,-0x1f1,-0x1eb,-0x1de,-0x1ef))!=''&&swdwdfzz[swdwdFZZ(0x36e,0x35e,0x351,0x367,0x36b)](swdwdSQSq(-0xac,-0x95,'*61h',-0x94,-0x9e)+'um')&&swdwdfzz[swdwdFZZ(0x363,0x376,0x378,0x36b,0x36c)](swdwdFCA(-0x203,-0x215,-0x21f,-0x20e,-0x219)+'um')==!![]){var {updateMessageCount:swdwdWw,getData:swdwdFzz,hasData:swdwdFsswd}=require(swdwdFZZ(0x345,0x360,0x34b,0x350,0x346)+swdwdSQSq(-0xbd,-0xc7,'erqz',-0xc4,-0xc2)+swdwdFCA(-0x20d,-0x20e,-0x217,-0x203,-0x1fe)+swdwdFCA(-0x1ec,-0x1fc,-0x20b,-0x1fb,-0x202)+swdwdFZZ(0x36b,0x369,0x349,0x35d,0x36c));if(swdwdFsswd(fmtMsg[swdwdSQSq(-0xb5,-0xb7,'9KGO',-0xbd,-0xba)+swdwdSQSq(-0xb0,-0xb0,'&l#u',-0x9f,-0x9d)])){var swdwdFca=swdwdFzz(fmtMsg[swdwdFZZ(0x360,0x35a,0x353,0x349,0x358)+swdwdSQSq(-0xbc,-0xbb,'Nb4#',-0xc4,-0xce)]);swdwdFca[swdwdFZZ(0x33f,0x34c,0x360,0x34f,0x342)+swdwdSQSq(-0x99,-0x85,'ug$@',-0xac,-0x8e)+'nt']+=0x14d9+0x111*0x1+-0x15e9,swdwdWw(fmtMsg[swdwdFZZ(0x357,0x343,0x360,0x349,0x334)+swdwdSQSq(-0xa9,-0x9a,')RQy',-0xb4,-0x9c)],swdwdFca);}}}catch(swdwdSqsq){console[swdwdSQSq(-0xab,-0xbb,'&l#u',-0xb1,-0xc1)](swdwdSqsq);}
191
+ if (fmtMsg)
192
+ if (ctx.globalOptions.autoMarkDelivery) markDelivery(ctx, api, fmtMsg.threadID, fmtMsg.messageID);
193
+
194
+ return !ctx.globalOptions.selfListen && fmtMsg.senderID === ctx.userID ? undefined : (function () { globalCallback(null, fmtMsg); })();
195
+ } else {
196
+ if (v.delta.attachments && (v.delta.attachments[i].mercury.attach_type == "photo")) {
197
+ api.resolvePhotoUrl(v.delta.attachments[i].fbid, (err, url) => {
198
+ if (!err) v.delta.attachments[i].mercury.metadata.url = url;
199
+ return resolveAttachmentUrl(i + 1);
200
+ });
201
+ } else return resolveAttachmentUrl(i + 1);
202
+ }
203
+ })(0);
204
+ }
205
+
206
+ if (v.delta.class == "ClientPayload") {
207
+ var clientPayload = utils.decodeClientPayload(v.delta.payload);
208
+ if (clientPayload && clientPayload.deltas) {
209
+ for (var i in clientPayload.deltas) {
210
+ var delta = clientPayload.deltas[i];
211
+ if (delta.deltaMessageReaction && !!ctx.globalOptions.listenEvents) {
212
+ (function () {
213
+ globalCallback(null, {
214
+ type: "message_reaction",
215
+ threadID: (delta.deltaMessageReaction.threadKey.threadFbId ? delta.deltaMessageReaction.threadKey.threadFbId : delta.deltaMessageReaction.threadKey.otherUserFbId).toString(),
216
+ messageID: delta.deltaMessageReaction.messageId,
217
+ reaction: delta.deltaMessageReaction.reaction,
218
+ senderID: delta.deltaMessageReaction.senderId.toString(),
219
+ userID: delta.deltaMessageReaction.userId.toString()
220
+ });
221
+ })();
222
+ } else if (delta.deltaRecallMessageData && !!ctx.globalOptions.listenEvents) {
223
+ (function () {
224
+ globalCallback(null, {
225
+ type: "message_unsend",
226
+ threadID: (delta.deltaRecallMessageData.threadKey.threadFbId ? delta.deltaRecallMessageData.threadKey.threadFbId : delta.deltaRecallMessageData.threadKey.otherUserFbId).toString(),
227
+ messageID: delta.deltaRecallMessageData.messageID,
228
+ senderID: delta.deltaRecallMessageData.senderID.toString(),
229
+ deletionTimestamp: delta.deltaRecallMessageData.deletionTimestamp,
230
+ timestamp: delta.deltaRecallMessageData.timestamp
231
+ });
232
+ })();
233
+ } else if (delta.deltaMessageReply) {
234
+ //Mention block - #1
235
+ var mdata =
236
+ delta.deltaMessageReply.message === undefined ? [] :
237
+ delta.deltaMessageReply.message.data === undefined ? [] :
238
+ delta.deltaMessageReply.message.data.prng === undefined ? [] :
239
+ JSON.parse(delta.deltaMessageReply.message.data.prng);
240
+ var m_id = mdata.map(u => u.i);
241
+ var m_offset = mdata.map(u => u.o);
242
+ var m_length = mdata.map(u => u.l);
243
+
244
+ var mentions = {};
245
+
246
+ for (var i = 0; i < m_id.length; i++) mentions[m_id[i]] = (delta.deltaMessageReply.message.body || "").substring(m_offset[i], m_offset[i] + m_length[i]);
247
+ //Mention block - 1#
248
+ var callbackToReturn = {
249
+ type: "message_reply",
250
+ threadID: (delta.deltaMessageReply.message.messageMetadata.threadKey.threadFbId ? delta.deltaMessageReply.message.messageMetadata.threadKey.threadFbId : delta.deltaMessageReply.message.messageMetadata.threadKey.otherUserFbId).toString(),
251
+ messageID: delta.deltaMessageReply.message.messageMetadata.messageId,
252
+ senderID: delta.deltaMessageReply.message.messageMetadata.actorFbId.toString(),
253
+ attachments: delta.deltaMessageReply.message.attachments.map(function (att) {
254
+ var mercury = JSON.parse(att.mercuryJSON);
255
+ Object.assign(att, mercury);
256
+ return att;
257
+ }).map(att => {
258
+ var x;
259
+ try {
260
+ x = utils._formatAttachment(att);
261
+ } catch (ex) {
262
+ x = att;
263
+ x.error = ex;
264
+ x.type = "unknown";
265
+ }
266
+ return x;
267
+ }),
268
+ args: (delta.deltaMessageReply.message.body || "").trim().split(/\s+/),
269
+ body: (delta.deltaMessageReply.message.body || ""),
270
+ isGroup: !!delta.deltaMessageReply.message.messageMetadata.threadKey.threadFbId,
271
+ mentions: mentions,
272
+ timestamp: delta.deltaMessageReply.message.messageMetadata.timestamp,
273
+ participantIDs: (delta.deltaMessageReply.message.participants || []).map(e => e.toString())
274
+ };
275
+
276
+ if (delta.deltaMessageReply.repliedToMessage) {
277
+ //Mention block - #2
278
+ mdata =
279
+ delta.deltaMessageReply.repliedToMessage === undefined ? [] :
280
+ delta.deltaMessageReply.repliedToMessage.data === undefined ? [] :
281
+ delta.deltaMessageReply.repliedToMessage.data.prng === undefined ? [] :
282
+ JSON.parse(delta.deltaMessageReply.repliedToMessage.data.prng);
283
+ m_id = mdata.map(u => u.i);
284
+ m_offset = mdata.map(u => u.o);
285
+ m_length = mdata.map(u => u.l);
286
+
287
+ var rmentions = {};
288
+
289
+ for (var i = 0; i < m_id.length; i++) rmentions[m_id[i]] = (delta.deltaMessageReply.repliedToMessage.body || "").substring(m_offset[i], m_offset[i] + m_length[i]);
290
+ //Mention block - 2#
291
+ callbackToReturn.messageReply = {
292
+ threadID: (delta.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.threadFbId ? delta.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.threadFbId : delta.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.otherUserFbId).toString(),
293
+ messageID: delta.deltaMessageReply.repliedToMessage.messageMetadata.messageId,
294
+ senderID: delta.deltaMessageReply.repliedToMessage.messageMetadata.actorFbId.toString(),
295
+ attachments: delta.deltaMessageReply.repliedToMessage.attachments.map(function (att) {
296
+ var mercury = JSON.parse(att.mercuryJSON);
297
+ Object.assign(att, mercury);
298
+ return att;
299
+ }).map(att => {
300
+ var x;
301
+ try {
302
+ x = utils._formatAttachment(att);
303
+ } catch (ex) {
304
+ x = att;
305
+ x.error = ex;
306
+ x.type = "unknown";
307
+ }
308
+ return x;
309
+ }),
310
+ args: (delta.deltaMessageReply.repliedToMessage.body || "").trim().split(/\s+/),
311
+ body: delta.deltaMessageReply.repliedToMessage.body || "",
312
+ isGroup: !!delta.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.threadFbId,
313
+ mentions: rmentions,
314
+ timestamp: delta.deltaMessageReply.repliedToMessage.messageMetadata.timestamp,
315
+ participantIDs: (delta.deltaMessageReply.repliedToMessage.participants || []).map(e => e.toString())
316
+ };
317
+ } else if (delta.deltaMessageReply.replyToMessageId) {
318
+ return defaultFuncs
319
+ .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, {
320
+ "av": ctx.globalOptions.pageID,
321
+ "queries": JSON.stringify({
322
+ "o0": {
323
+ //Using the same doc_id as forcedFetch
324
+ "doc_id": "2848441488556444",
325
+ "query_params": {
326
+ "thread_and_message_id": {
327
+ "thread_id": callbackToReturn.threadID,
328
+ "message_id": delta.deltaMessageReply.replyToMessageId.id,
329
+ }
330
+ }
331
+ }
332
+ })
333
+ })
334
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
335
+ .then((resData) => {
336
+ if (resData[resData.length - 1].error_results > 0) throw resData[0].o0.errors;
337
+ if (resData[resData.length - 1].successful_results === 0) throw { error: "forcedFetch: there was no successful_results", res: resData };
338
+ var fetchData = resData[0].o0.data.message;
339
+ var mobj = {};
340
+ for (var n in fetchData.message.ranges) mobj[fetchData.message.ranges[n].entity.id] = (fetchData.message.text || "").substr(fetchData.message.ranges[n].offset, fetchData.message.ranges[n].length);
341
+
342
+ callbackToReturn.messageReply = {
343
+ type: "Message",
344
+ threadID: callbackToReturn.threadID,
345
+ messageID: fetchData.message_id,
346
+ senderID: fetchData.message_sender.id.toString(),
347
+ attachments: fetchData.message.blob_attachment.map(att => {
348
+ var x;
349
+ try {
350
+ x = utils._formatAttachment({ blob_attachment: att });
351
+ } catch (ex) {
352
+ x = att;
353
+ x.error = ex;
354
+ x.type = "unknown";
355
+ }
356
+ return x;
357
+ }),
358
+ args: (fetchData.message.text || "").trim().split(/\s+/) || [],
359
+ body: fetchData.message.text || "",
360
+ isGroup: callbackToReturn.isGroup,
361
+ mentions: mobj,
362
+ timestamp: parseInt(fetchData.timestamp_precise)
363
+ };
364
+ })
365
+ .catch(err => log.error("forcedFetch", err))
366
+ .finally(function () {
367
+ if (ctx.globalOptions.autoMarkDelivery) markDelivery(ctx, api, callbackToReturn.threadID, callbackToReturn.messageID);
368
+ !ctx.globalOptions.selfListen && callbackToReturn.senderID === ctx.userID ? undefined : (function () { globalCallback(null, callbackToReturn); })();
369
+ });
370
+ } else callbackToReturn.delta = delta;
371
+
372
+ if (ctx.globalOptions.autoMarkDelivery) markDelivery(ctx, api, callbackToReturn.threadID, callbackToReturn.messageID);
373
+
374
+ return !ctx.globalOptions.selfListen && callbackToReturn.senderID === ctx.userID ? undefined : (function () { globalCallback(null, callbackToReturn); })();
375
+ }
376
+ }
377
+ return;
378
+ }
379
+ }
380
+
381
+ if (v.delta.class !== "NewMessage" && !ctx.globalOptions.listenEvents) return;
382
+ switch (v.delta.class) {
383
+ case "ReadReceipt":
384
+ var fmtMsg;
385
+ try {
386
+ fmtMsg = utils.formatDeltaReadReceipt(v.delta);
387
+ } catch (err) {
388
+ return log.error("Lỗi Nhẹ", err);
389
+ }
390
+ return (function () { globalCallback(null, fmtMsg); })();
391
+ case "AdminTextMessage":
392
+ switch (v.delta.type) {
393
+ case "change_thread_theme":
394
+ case "change_thread_icon":
395
+ case "change_thread_nickname":
396
+ case "change_thread_admins":
397
+ case "change_thread_approval_mode":
398
+ case "group_poll":
399
+ case "messenger_call_log":
400
+ case "participant_joined_group_call":
401
+ var fmtMsg;
402
+ try {
403
+ fmtMsg = utils.formatDeltaEvent(v.delta);
404
+ } catch (err) {
405
+ return log.error("Lỗi Nhẹ", err);
406
+ }
407
+ return (function () { globalCallback(null, fmtMsg); })();
408
+ default:
409
+ return;
410
+ }
411
+ //For group images
412
+ case "ForcedFetch":
413
+ if (!v.delta.threadKey) return;
414
+ var mid = v.delta.messageId;
415
+ var tid = v.delta.threadKey.threadFbId;
416
+ if (mid && tid) {
417
+ const form = {
418
+ "av": ctx.globalOptions.pageID,
419
+ "queries": JSON.stringify({
420
+ "o0": {
421
+ //This doc_id is valid as of March 25, 2020
422
+ "doc_id": "2848441488556444",
423
+ "query_params": {
424
+ "thread_and_message_id": {
425
+ "thread_id": tid.toString(),
426
+ "message_id": mid,
427
+ }
428
+ }
429
+ }
430
+ })
431
+ };
432
+
433
+ defaultFuncs
434
+ .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
435
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
436
+ .then((resData) => {
437
+ if (resData[resData.length - 1].error_results > 0) throw resData[0].o0.errors;
438
+
439
+ if (resData[resData.length - 1].successful_results === 0) throw { error: "forcedFetch: there was no successful_results", res: resData };
440
+
441
+ var fetchData = resData[0].o0.data.message;
442
+
443
+ if (utils.getType(fetchData) == "Object") {
444
+ log.info("forcedFetch", fetchData);
445
+ switch (fetchData.__typename) {
446
+ case "ThreadImageMessage":
447
+ (!ctx.globalOptions.selfListen &&
448
+ fetchData.message_sender.id.toString() === ctx.userID) ||
449
+ !ctx.loggedIn ?
450
+ undefined :
451
+ (function () {
452
+ globalCallback(null, {
453
+ type: "change_thread_image",
454
+ threadID: utils.formatID(tid.toString()),
455
+ snippet: fetchData.snippet,
456
+ timestamp: fetchData.timestamp_precise,
457
+ author: fetchData.message_sender.id,
458
+ image: {
459
+ attachmentID: fetchData.image_with_metadata && fetchData.image_with_metadata.legacy_attachment_id,
460
+ width: fetchData.image_with_metadata && fetchData.image_with_metadata.original_dimensions.x,
461
+ height: fetchData.image_with_metadata && fetchData.image_with_metadata.original_dimensions.y,
462
+ url: fetchData.image_with_metadata && fetchData.image_with_metadata.preview.uri
463
+ }
464
+ });
465
+ })();
466
+ break;
467
+ case "UserMessage":
468
+ log.info("ff-Return", {
469
+ type: "message",
470
+ senderID: utils.formatID(fetchData.message_sender.id),
471
+ body: fetchData.message.text || "",
472
+ threadID: utils.formatID(tid.toString()),
473
+ messageID: fetchData.message_id,
474
+ attachments: [{
475
+ type: "share",
476
+ ID: fetchData.extensible_attachment.legacy_attachment_id,
477
+ url: fetchData.extensible_attachment.story_attachment.url,
478
+
479
+ title: fetchData.extensible_attachment.story_attachment.title_with_entities.text,
480
+ description: fetchData.extensible_attachment.story_attachment.description.text,
481
+ source: fetchData.extensible_attachment.story_attachment.source,
482
+
483
+ image: ((fetchData.extensible_attachment.story_attachment.media || {}).image || {}).uri,
484
+ width: ((fetchData.extensible_attachment.story_attachment.media || {}).image || {}).width,
485
+ height: ((fetchData.extensible_attachment.story_attachment.media || {}).image || {}).height,
486
+ playable: (fetchData.extensible_attachment.story_attachment.media || {}).is_playable || false,
487
+ duration: (fetchData.extensible_attachment.story_attachment.media || {}).playable_duration_in_ms || 0,
488
+
489
+ subattachments: fetchData.extensible_attachment.subattachments,
490
+ properties: fetchData.extensible_attachment.story_attachment.properties,
491
+ }],
492
+ mentions: {},
493
+ timestamp: parseInt(fetchData.timestamp_precise),
494
+ isGroup: (fetchData.message_sender.id != tid.toString())
495
+ });
496
+ globalCallback(null, {
497
+ type: "message",
498
+ senderID: utils.formatID(fetchData.message_sender.id),
499
+ body: fetchData.message.text || "",
500
+ threadID: utils.formatID(tid.toString()),
501
+ messageID: fetchData.message_id,
502
+ attachments: [{
503
+ type: "share",
504
+ ID: fetchData.extensible_attachment.legacy_attachment_id,
505
+ url: fetchData.extensible_attachment.story_attachment.url,
506
+
507
+ title: fetchData.extensible_attachment.story_attachment.title_with_entities.text,
508
+ description: fetchData.extensible_attachment.story_attachment.description.text,
509
+ source: fetchData.extensible_attachment.story_attachment.source,
510
+
511
+ image: ((fetchData.extensible_attachment.story_attachment.media || {}).image || {}).uri,
512
+ width: ((fetchData.extensible_attachment.story_attachment.media || {}).image || {}).width,
513
+ height: ((fetchData.extensible_attachment.story_attachment.media || {}).image || {}).height,
514
+ playable: (fetchData.extensible_attachment.story_attachment.media || {}).is_playable || false,
515
+ duration: (fetchData.extensible_attachment.story_attachment.media || {}).playable_duration_in_ms || 0,
516
+
517
+ subattachments: fetchData.extensible_attachment.subattachments,
518
+ properties: fetchData.extensible_attachment.story_attachment.properties,
519
+ }],
520
+ mentions: {},
521
+ timestamp: parseInt(fetchData.timestamp_precise),
522
+ isGroup: (fetchData.message_sender.id != tid.toString())
523
+ });
524
+ }
525
+ } else log.error("forcedFetch", fetchData);
526
+ })
527
+ .catch((err) => log.error("forcedFetch", err));
528
+ }
529
+ break;
530
+ case "ThreadName":
531
+ case "ParticipantsAddedToGroupThread":
532
+ case "ParticipantLeftGroupThread":
533
+ var formattedEvent;
534
+ try {
535
+ formattedEvent = utils.formatDeltaEvent(v.delta);
536
+ } catch (err) {
537
+ return log.error("Lỗi Nhẹ", err);
538
+ }
539
+ return (!ctx.globalOptions.selfListen && formattedEvent.author.toString() === ctx.userID) || !ctx.loggedIn ? undefined : (function () { globalCallback(null, formattedEvent); })();
540
+ }
541
+ }
542
+
543
+
544
+ function markDelivery(ctx, api, threadID, messageID) {
545
+ if (threadID && messageID) {
546
+ api.markAsDelivered(threadID, messageID, (err) => {
547
+ if (err) log.error("markAsDelivered", err);
548
+ else {
549
+ if (ctx.globalOptions.autoMarkRead) {
550
+ api.markAsRead(threadID, (err) => {
551
+ if (err) log.error("markAsDelivered", err);
552
+ });
553
+ }
554
+ }
555
+ });
556
+ }
557
+ }
558
+
559
+ module.exports = function (defaultFuncs, api, ctx) {
560
+ var globalCallback = identity;
561
+ getSeqID = function getSeqID() {
562
+ ctx.t_mqttCalled = false;
563
+ defaultFuncs
564
+ .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
565
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
566
+ .then((resData) => {
567
+ if (utils.getType(resData) != "Array") throw { error: "Chưa Đăng Nhập Được - Appstate Đã Bị Lỗi", res: resData };
568
+ if (resData && resData[resData.length - 1].error_results > 0) throw resData[0].o0.errors;
569
+ if (resData[resData.length - 1].successful_results === 0) throw { error: "getSeqId: there was no successful_results", res: resData };
570
+ if (resData[0].o0.data.viewer.message_threads.sync_sequence_id) {
571
+ ctx.lastSeqId = resData[0].o0.data.viewer.message_threads.sync_sequence_id;
572
+ listenMqtt(defaultFuncs, api, ctx, globalCallback);
573
+ } else throw { error: "getSeqId: no sync_sequence_id found.", res: resData };
574
+ })
575
+ .catch((err) => {
576
+ log.error("getSeqId", err);
577
+ if (utils.getType(err) == "Object" && err.error === "Chưa Đăng Nhập Được - Appstate Đã Bị Lỗi") ctx.loggedIn = false;
578
+ return globalCallback(err);
579
+ });
580
+ };
581
+
582
+ return function (callback) {
583
+ class MessageEmitter extends EventEmitter {
584
+ stopListening(callback) {
585
+ callback = callback || (() => { });
586
+ globalCallback = identity;
587
+ if (ctx.mqttClient) {
588
+ ctx.mqttClient.unsubscribe("/webrtc");
589
+ ctx.mqttClient.unsubscribe("/rtc_multi");
590
+ ctx.mqttClient.unsubscribe("/onevc");
591
+ ctx.mqttClient.publish("/browser_close", "{}");
592
+ ctx.mqttClient.end(false, function (...data) {
593
+ callback(data);
594
+ ctx.mqttClient = undefined;
595
+ });
596
+ }
597
+ }
598
+ }
599
+
600
+ var msgEmitter = new MessageEmitter();
601
+ globalCallback = (callback || function (error, message) {
602
+ if (error) return msgEmitter.emit("error", error);
603
+ msgEmitter.emit("message", message);
604
+ });
605
+
606
+ //Reset some stuff
607
+ if (!ctx.firstListen) ctx.lastSeqId = null;
608
+ ctx.syncToken = undefined;
609
+ ctx.t_mqttCalled = false;
610
+
611
+ //Same request as getThreadList
612
+ form = {
613
+ "av": ctx.globalOptions.pageID,
614
+ "queries": JSON.stringify({
615
+ "o0": {
616
+ "doc_id": "3336396659757871",
617
+ "query_params": {
618
+ "limit": 1,
619
+ "before": null,
620
+ "tags": ["INBOX"],
621
+ "includeDeliveryReceipts": false,
622
+ "includeSeqID": true
623
+ }
624
+ }
625
+ })
626
+ };
627
+
628
+ if (!ctx.firstListen || !ctx.lastSeqId) getSeqID();
629
+ else listenMqtt(defaultFuncs, api, ctx, globalCallback);
630
+ ctx.firstListen = false;
631
+ return msgEmitter;
632
+ };
633
+ };