fca-smart-shankar 10.9.1 → 12.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 (363) hide show
  1. package/.cache/nix/binary-cache-v6.sqlite +0 -0
  2. package/.cache/replit/env/latest +117 -48
  3. package/.cache/replit/env/latest.json +1 -1
  4. package/.cache/replit/modules/nix.res +1 -0
  5. package/.cache/replit/modules/nodejs-20.res +1 -0
  6. package/.cache/replit/nix/env.json +1 -0
  7. package/.cache/typescript/5.6/node_modules/.package-lock.json +171 -0
  8. package/.cache/typescript/5.6/node_modules/@types/bluebird/LICENSE +21 -0
  9. package/.cache/typescript/5.6/node_modules/@types/bluebird/README.md +15 -0
  10. package/.cache/typescript/5.6/node_modules/@types/bluebird/index.d.ts +1365 -0
  11. package/.cache/typescript/5.6/node_modules/@types/bluebird/package.json +25 -0
  12. package/.cache/typescript/5.6/node_modules/@types/caseless/LICENSE +21 -0
  13. package/.cache/typescript/5.6/node_modules/@types/caseless/README.md +48 -0
  14. package/.cache/typescript/5.6/node_modules/@types/caseless/index.d.ts +29 -0
  15. package/.cache/typescript/5.6/node_modules/@types/caseless/package.json +35 -0
  16. package/.cache/typescript/5.6/node_modules/@types/cheerio/LICENSE +21 -0
  17. package/.cache/typescript/5.6/node_modules/@types/cheerio/README.md +15 -0
  18. package/.cache/typescript/5.6/node_modules/@types/cheerio/index.d.ts +318 -0
  19. package/.cache/typescript/5.6/node_modules/@types/cheerio/package.json +71 -0
  20. package/.cache/typescript/5.6/node_modules/@types/mocha/LICENSE +21 -0
  21. package/.cache/typescript/5.6/node_modules/@types/mocha/README.md +15 -0
  22. package/.cache/typescript/5.6/node_modules/@types/mocha/index.d.ts +2929 -0
  23. package/.cache/typescript/5.6/node_modules/@types/mocha/package.json +56 -0
  24. package/.cache/typescript/5.6/node_modules/@types/node/LICENSE +21 -0
  25. package/.cache/typescript/5.6/node_modules/@types/node/README.md +15 -0
  26. package/.cache/typescript/5.6/node_modules/@types/node/assert/strict.d.ts +8 -0
  27. package/.cache/typescript/5.6/node_modules/@types/node/assert.d.ts +1040 -0
  28. package/.cache/typescript/5.6/node_modules/@types/node/async_hooks.d.ts +541 -0
  29. package/.cache/typescript/5.6/node_modules/@types/node/buffer.buffer.d.ts +385 -0
  30. package/.cache/typescript/5.6/node_modules/@types/node/buffer.d.ts +1933 -0
  31. package/.cache/typescript/5.6/node_modules/@types/node/child_process.d.ts +1549 -0
  32. package/.cache/typescript/5.6/node_modules/@types/node/cluster.d.ts +579 -0
  33. package/.cache/typescript/5.6/node_modules/@types/node/compatibility/disposable.d.ts +16 -0
  34. package/.cache/typescript/5.6/node_modules/@types/node/compatibility/index.d.ts +9 -0
  35. package/.cache/typescript/5.6/node_modules/@types/node/compatibility/indexable.d.ts +23 -0
  36. package/.cache/typescript/5.6/node_modules/@types/node/compatibility/iterators.d.ts +21 -0
  37. package/.cache/typescript/5.6/node_modules/@types/node/console.d.ts +452 -0
  38. package/.cache/typescript/5.6/node_modules/@types/node/constants.d.ts +19 -0
  39. package/.cache/typescript/5.6/node_modules/@types/node/crypto.d.ts +4475 -0
  40. package/.cache/typescript/5.6/node_modules/@types/node/dgram.d.ts +596 -0
  41. package/.cache/typescript/5.6/node_modules/@types/node/diagnostics_channel.d.ts +554 -0
  42. package/.cache/typescript/5.6/node_modules/@types/node/dns/promises.d.ts +476 -0
  43. package/.cache/typescript/5.6/node_modules/@types/node/dns.d.ts +865 -0
  44. package/.cache/typescript/5.6/node_modules/@types/node/dom-events.d.ts +124 -0
  45. package/.cache/typescript/5.6/node_modules/@types/node/domain.d.ts +170 -0
  46. package/.cache/typescript/5.6/node_modules/@types/node/events.d.ts +931 -0
  47. package/.cache/typescript/5.6/node_modules/@types/node/fs/promises.d.ts +1275 -0
  48. package/.cache/typescript/5.6/node_modules/@types/node/fs.d.ts +4396 -0
  49. package/.cache/typescript/5.6/node_modules/@types/node/globals.d.ts +566 -0
  50. package/.cache/typescript/5.6/node_modules/@types/node/globals.typedarray.d.ts +21 -0
  51. package/.cache/typescript/5.6/node_modules/@types/node/http.d.ts +1958 -0
  52. package/.cache/typescript/5.6/node_modules/@types/node/http2.d.ts +2558 -0
  53. package/.cache/typescript/5.6/node_modules/@types/node/https.d.ts +543 -0
  54. package/.cache/typescript/5.6/node_modules/@types/node/index.d.ts +92 -0
  55. package/.cache/typescript/5.6/node_modules/@types/node/inspector.d.ts +3966 -0
  56. package/.cache/typescript/5.6/node_modules/@types/node/module.d.ts +402 -0
  57. package/.cache/typescript/5.6/node_modules/@types/node/net.d.ts +1001 -0
  58. package/.cache/typescript/5.6/node_modules/@types/node/os.d.ts +495 -0
  59. package/.cache/typescript/5.6/node_modules/@types/node/package.json +220 -0
  60. package/.cache/typescript/5.6/node_modules/@types/node/path.d.ts +200 -0
  61. package/.cache/typescript/5.6/node_modules/@types/node/perf_hooks.d.ts +965 -0
  62. package/.cache/typescript/5.6/node_modules/@types/node/process.d.ts +1963 -0
  63. package/.cache/typescript/5.6/node_modules/@types/node/punycode.d.ts +117 -0
  64. package/.cache/typescript/5.6/node_modules/@types/node/querystring.d.ts +153 -0
  65. package/.cache/typescript/5.6/node_modules/@types/node/readline/promises.d.ts +162 -0
  66. package/.cache/typescript/5.6/node_modules/@types/node/readline.d.ts +589 -0
  67. package/.cache/typescript/5.6/node_modules/@types/node/repl.d.ts +430 -0
  68. package/.cache/typescript/5.6/node_modules/@types/node/sea.d.ts +153 -0
  69. package/.cache/typescript/5.6/node_modules/@types/node/sqlite.d.ts +213 -0
  70. package/.cache/typescript/5.6/node_modules/@types/node/stream/consumers.d.ts +12 -0
  71. package/.cache/typescript/5.6/node_modules/@types/node/stream/promises.d.ts +90 -0
  72. package/.cache/typescript/5.6/node_modules/@types/node/stream/web.d.ts +609 -0
  73. package/.cache/typescript/5.6/node_modules/@types/node/stream.d.ts +1726 -0
  74. package/.cache/typescript/5.6/node_modules/@types/node/string_decoder.d.ts +67 -0
  75. package/.cache/typescript/5.6/node_modules/@types/node/test.d.ts +2248 -0
  76. package/.cache/typescript/5.6/node_modules/@types/node/timers/promises.d.ts +97 -0
  77. package/.cache/typescript/5.6/node_modules/@types/node/timers.d.ts +240 -0
  78. package/.cache/typescript/5.6/node_modules/@types/node/tls.d.ts +1226 -0
  79. package/.cache/typescript/5.6/node_modules/@types/node/trace_events.d.ts +197 -0
  80. package/.cache/typescript/5.6/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +385 -0
  81. package/.cache/typescript/5.6/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +19 -0
  82. package/.cache/typescript/5.6/node_modules/@types/node/ts5.6/index.d.ts +92 -0
  83. package/.cache/typescript/5.6/node_modules/@types/node/tty.d.ts +208 -0
  84. package/.cache/typescript/5.6/node_modules/@types/node/url.d.ts +972 -0
  85. package/.cache/typescript/5.6/node_modules/@types/node/util.d.ts +2371 -0
  86. package/.cache/typescript/5.6/node_modules/@types/node/v8.d.ts +808 -0
  87. package/.cache/typescript/5.6/node_modules/@types/node/vm.d.ts +976 -0
  88. package/.cache/typescript/5.6/node_modules/@types/node/wasi.d.ts +181 -0
  89. package/.cache/typescript/5.6/node_modules/@types/node/worker_threads.d.ts +745 -0
  90. package/.cache/typescript/5.6/node_modules/@types/node/zlib.d.ts +539 -0
  91. package/.cache/typescript/5.6/node_modules/@types/request/LICENSE +21 -0
  92. package/.cache/typescript/5.6/node_modules/@types/request/README.md +15 -0
  93. package/.cache/typescript/5.6/node_modules/@types/request/index.d.ts +395 -0
  94. package/.cache/typescript/5.6/node_modules/@types/request/package.json +70 -0
  95. package/.cache/typescript/5.6/node_modules/@types/tough-cookie/LICENSE +21 -0
  96. package/.cache/typescript/5.6/node_modules/@types/tough-cookie/README.md +15 -0
  97. package/.cache/typescript/5.6/node_modules/@types/tough-cookie/index.d.ts +321 -0
  98. package/.cache/typescript/5.6/node_modules/@types/tough-cookie/package.json +35 -0
  99. package/.cache/typescript/5.6/node_modules/asynckit/LICENSE +21 -0
  100. package/.cache/typescript/5.6/node_modules/asynckit/README.md +233 -0
  101. package/.cache/typescript/5.6/node_modules/asynckit/bench.js +76 -0
  102. package/.cache/typescript/5.6/node_modules/asynckit/index.js +6 -0
  103. package/.cache/typescript/5.6/node_modules/asynckit/lib/abort.js +29 -0
  104. package/.cache/typescript/5.6/node_modules/asynckit/lib/async.js +34 -0
  105. package/.cache/typescript/5.6/node_modules/asynckit/lib/defer.js +26 -0
  106. package/.cache/typescript/5.6/node_modules/asynckit/lib/iterate.js +75 -0
  107. package/.cache/typescript/5.6/node_modules/asynckit/lib/readable_asynckit.js +91 -0
  108. package/.cache/typescript/5.6/node_modules/asynckit/lib/readable_parallel.js +25 -0
  109. package/.cache/typescript/5.6/node_modules/asynckit/lib/readable_serial.js +25 -0
  110. package/.cache/typescript/5.6/node_modules/asynckit/lib/readable_serial_ordered.js +29 -0
  111. package/.cache/typescript/5.6/node_modules/asynckit/lib/state.js +37 -0
  112. package/.cache/typescript/5.6/node_modules/asynckit/lib/streamify.js +141 -0
  113. package/.cache/typescript/5.6/node_modules/asynckit/lib/terminator.js +29 -0
  114. package/.cache/typescript/5.6/node_modules/asynckit/package.json +63 -0
  115. package/.cache/typescript/5.6/node_modules/asynckit/parallel.js +43 -0
  116. package/.cache/typescript/5.6/node_modules/asynckit/serial.js +17 -0
  117. package/.cache/typescript/5.6/node_modules/asynckit/serialOrdered.js +75 -0
  118. package/.cache/typescript/5.6/node_modules/asynckit/stream.js +21 -0
  119. package/.cache/typescript/5.6/node_modules/combined-stream/License +19 -0
  120. package/.cache/typescript/5.6/node_modules/combined-stream/Readme.md +138 -0
  121. package/.cache/typescript/5.6/node_modules/combined-stream/lib/combined_stream.js +208 -0
  122. package/.cache/typescript/5.6/node_modules/combined-stream/package.json +25 -0
  123. package/.cache/typescript/5.6/node_modules/combined-stream/yarn.lock +17 -0
  124. package/.cache/typescript/5.6/node_modules/delayed-stream/License +19 -0
  125. package/.cache/typescript/5.6/node_modules/delayed-stream/Makefile +7 -0
  126. package/.cache/typescript/5.6/node_modules/delayed-stream/Readme.md +141 -0
  127. package/.cache/typescript/5.6/node_modules/delayed-stream/lib/delayed_stream.js +107 -0
  128. package/.cache/typescript/5.6/node_modules/delayed-stream/package.json +27 -0
  129. package/.cache/typescript/5.6/node_modules/form-data/License +19 -0
  130. package/.cache/typescript/5.6/node_modules/form-data/Readme.md +350 -0
  131. package/.cache/typescript/5.6/node_modules/form-data/index.d.ts +51 -0
  132. package/.cache/typescript/5.6/node_modules/form-data/lib/browser.js +2 -0
  133. package/.cache/typescript/5.6/node_modules/form-data/lib/form_data.js +484 -0
  134. package/.cache/typescript/5.6/node_modules/form-data/lib/populate.js +10 -0
  135. package/.cache/typescript/5.6/node_modules/form-data/package.json +72 -0
  136. package/.cache/typescript/5.6/node_modules/mime-db/HISTORY.md +507 -0
  137. package/.cache/typescript/5.6/node_modules/mime-db/LICENSE +23 -0
  138. package/.cache/typescript/5.6/node_modules/mime-db/README.md +100 -0
  139. package/.cache/typescript/5.6/node_modules/mime-db/db.json +8519 -0
  140. package/.cache/typescript/5.6/node_modules/mime-db/index.js +12 -0
  141. package/.cache/typescript/5.6/node_modules/mime-db/package.json +60 -0
  142. package/.cache/typescript/5.6/node_modules/mime-types/HISTORY.md +397 -0
  143. package/.cache/typescript/5.6/node_modules/mime-types/LICENSE +23 -0
  144. package/.cache/typescript/5.6/node_modules/mime-types/README.md +113 -0
  145. package/.cache/typescript/5.6/node_modules/mime-types/index.js +188 -0
  146. package/.cache/typescript/5.6/node_modules/mime-types/package.json +44 -0
  147. package/.cache/typescript/5.6/node_modules/safe-buffer/LICENSE +21 -0
  148. package/.cache/typescript/5.6/node_modules/safe-buffer/README.md +584 -0
  149. package/.cache/typescript/5.6/node_modules/safe-buffer/index.d.ts +187 -0
  150. package/.cache/typescript/5.6/node_modules/safe-buffer/index.js +65 -0
  151. package/.cache/typescript/5.6/node_modules/safe-buffer/package.json +51 -0
  152. package/.cache/typescript/5.6/node_modules/types-registry/README.md +2 -0
  153. package/.cache/typescript/5.6/node_modules/types-registry/index.json +1 -0
  154. package/.cache/typescript/5.6/node_modules/types-registry/package.json +20 -0
  155. package/.cache/typescript/5.6/node_modules/undici-types/LICENSE +21 -0
  156. package/.cache/typescript/5.6/node_modules/undici-types/README.md +6 -0
  157. package/.cache/typescript/5.6/node_modules/undici-types/agent.d.ts +31 -0
  158. package/.cache/typescript/5.6/node_modules/undici-types/api.d.ts +43 -0
  159. package/.cache/typescript/5.6/node_modules/undici-types/balanced-pool.d.ts +29 -0
  160. package/.cache/typescript/5.6/node_modules/undici-types/cache.d.ts +36 -0
  161. package/.cache/typescript/5.6/node_modules/undici-types/client.d.ts +108 -0
  162. package/.cache/typescript/5.6/node_modules/undici-types/connector.d.ts +34 -0
  163. package/.cache/typescript/5.6/node_modules/undici-types/content-type.d.ts +21 -0
  164. package/.cache/typescript/5.6/node_modules/undici-types/cookies.d.ts +28 -0
  165. package/.cache/typescript/5.6/node_modules/undici-types/diagnostics-channel.d.ts +66 -0
  166. package/.cache/typescript/5.6/node_modules/undici-types/dispatcher.d.ts +255 -0
  167. package/.cache/typescript/5.6/node_modules/undici-types/env-http-proxy-agent.d.ts +21 -0
  168. package/.cache/typescript/5.6/node_modules/undici-types/errors.d.ts +149 -0
  169. package/.cache/typescript/5.6/node_modules/undici-types/eventsource.d.ts +61 -0
  170. package/.cache/typescript/5.6/node_modules/undici-types/fetch.d.ts +209 -0
  171. package/.cache/typescript/5.6/node_modules/undici-types/file.d.ts +39 -0
  172. package/.cache/typescript/5.6/node_modules/undici-types/filereader.d.ts +54 -0
  173. package/.cache/typescript/5.6/node_modules/undici-types/formdata.d.ts +108 -0
  174. package/.cache/typescript/5.6/node_modules/undici-types/global-dispatcher.d.ts +9 -0
  175. package/.cache/typescript/5.6/node_modules/undici-types/global-origin.d.ts +7 -0
  176. package/.cache/typescript/5.6/node_modules/undici-types/handlers.d.ts +15 -0
  177. package/.cache/typescript/5.6/node_modules/undici-types/header.d.ts +4 -0
  178. package/.cache/typescript/5.6/node_modules/undici-types/index.d.ts +71 -0
  179. package/.cache/typescript/5.6/node_modules/undici-types/interceptors.d.ts +17 -0
  180. package/.cache/typescript/5.6/node_modules/undici-types/mock-agent.d.ts +50 -0
  181. package/.cache/typescript/5.6/node_modules/undici-types/mock-client.d.ts +25 -0
  182. package/.cache/typescript/5.6/node_modules/undici-types/mock-errors.d.ts +12 -0
  183. package/.cache/typescript/5.6/node_modules/undici-types/mock-interceptor.d.ts +93 -0
  184. package/.cache/typescript/5.6/node_modules/undici-types/mock-pool.d.ts +25 -0
  185. package/.cache/typescript/5.6/node_modules/undici-types/package.json +55 -0
  186. package/.cache/typescript/5.6/node_modules/undici-types/patch.d.ts +33 -0
  187. package/.cache/typescript/5.6/node_modules/undici-types/pool-stats.d.ts +19 -0
  188. package/.cache/typescript/5.6/node_modules/undici-types/pool.d.ts +39 -0
  189. package/.cache/typescript/5.6/node_modules/undici-types/proxy-agent.d.ts +28 -0
  190. package/.cache/typescript/5.6/node_modules/undici-types/readable.d.ts +60 -0
  191. package/.cache/typescript/5.6/node_modules/undici-types/retry-agent.d.ts +8 -0
  192. package/.cache/typescript/5.6/node_modules/undici-types/retry-handler.d.ts +116 -0
  193. package/.cache/typescript/5.6/node_modules/undici-types/util.d.ts +18 -0
  194. package/.cache/typescript/5.6/node_modules/undici-types/webidl.d.ts +222 -0
  195. package/.cache/typescript/5.6/node_modules/undici-types/websocket.d.ts +150 -0
  196. package/.cache/typescript/5.6/package-lock.json +183 -0
  197. package/.cache/typescript/5.6/package.json +1 -0
  198. package/.replit +3 -3
  199. package/LICENSE-MIT +21 -0
  200. package/README.md +176 -30
  201. package/index.js +452 -425
  202. package/package.json +39 -90
  203. package/replit.nix +3 -0
  204. package/src/addExternalModule.js +14 -5
  205. package/src/addUserToGroup.js +57 -21
  206. package/src/changeAdminStatus.js +46 -22
  207. package/src/changeArchivedStatus.js +26 -12
  208. package/src/changeAvatar.js +136 -0
  209. package/src/{changeAvt.js → changeAvatarV2.js} +4 -3
  210. package/src/changeBio.js +26 -15
  211. package/src/changeBlockedStatus.js +22 -9
  212. package/src/changeBlockedStatusMqtt.js +80 -0
  213. package/src/changeCover.js +73 -0
  214. package/src/changeGroupImage.js +55 -26
  215. package/src/changeName.js +79 -0
  216. package/src/changeNickname.js +28 -14
  217. package/src/changeThreadColor.js +22 -19
  218. package/src/changeThreadEmoji.js +25 -12
  219. package/src/changeUsername.js +59 -0
  220. package/src/createCommentPost.js +230 -0
  221. package/src/createNewGroup.js +36 -18
  222. package/src/createPoll.js +28 -17
  223. package/src/createPost.js +276 -0
  224. package/src/data/getThreadInfo.json +1 -0
  225. package/src/deleteMessage.js +25 -14
  226. package/src/deleteThread.js +26 -13
  227. package/src/editMessage.js +56 -50
  228. package/src/editMessageOld.js +67 -0
  229. package/src/follow.js +74 -0
  230. package/src/forwardAttachment.js +28 -16
  231. package/src/getAccess.js +112 -0
  232. package/src/getAvatarUser.js +78 -0
  233. package/src/getCurrentUserID.js +3 -3
  234. package/src/getEmojiUrl.js +10 -8
  235. package/src/getFriendsList.js +25 -15
  236. package/src/getMessage.js +813 -81
  237. package/src/getRegion.js +7 -0
  238. package/src/getThreadHistory.js +241 -98
  239. package/src/getThreadHistoryDeprecated.js +93 -0
  240. package/src/getThreadInfo.js +90 -287
  241. package/src/getThreadInfoDeprecated.js +80 -0
  242. package/src/getThreadList.js +215 -158
  243. package/src/getThreadListDeprecated.js +75 -0
  244. package/src/getThreadPictures.js +40 -20
  245. package/src/getUID.js +113 -50
  246. package/src/getUserID.js +18 -14
  247. package/src/getUserInfo.js +35 -75
  248. package/src/handleFriendRequest.js +25 -14
  249. package/src/handleMessageRequest.js +37 -21
  250. package/src/httpGet.js +36 -20
  251. package/src/httpPost.js +37 -20
  252. package/src/httpPostFormData.js +53 -24
  253. package/src/listenMqtt.js +413 -666
  254. package/src/listenNotification.js +85 -0
  255. package/src/logout.js +24 -17
  256. package/src/markAsDelivered.js +23 -16
  257. package/src/markAsRead.js +43 -28
  258. package/src/markAsReadAll.js +22 -15
  259. package/src/markAsSeen.js +29 -19
  260. package/src/muteThread.js +18 -13
  261. package/src/pinMessage.js +59 -0
  262. package/src/refreshFb_dtsg.js +89 -0
  263. package/src/removeUserFromGroup.js +48 -18
  264. package/src/resolvePhotoUrl.js +22 -14
  265. package/src/searchForThread.js +23 -13
  266. package/src/searchStickers.js +53 -0
  267. package/src/sendMessage.js +180 -122
  268. package/src/sendMessageMqtt.js +322 -0
  269. package/src/sendTypingIndicator.js +42 -21
  270. package/src/sendTypingIndicatorV2.js +28 -0
  271. package/src/setMessageReaction.js +33 -20
  272. package/src/setMessageReactionMqtt.js +62 -0
  273. package/src/setPostReaction.js +105 -95
  274. package/src/setProfileGuard.js +45 -0
  275. package/src/setStoryReaction.js +64 -0
  276. package/src/setTitle.js +35 -19
  277. package/src/shareContact.js +92 -37
  278. package/src/shareLink.js +6 -5
  279. package/src/stopListenMqtt.js +23 -0
  280. package/src/threadColors.js +110 -18
  281. package/src/unfriend.js +20 -11
  282. package/src/unsendMessage.js +31 -34
  283. package/src/uploadAttachment.js +94 -0
  284. package/test/test-page.js +1 -1
  285. package/test/test.js +1 -1
  286. package/utils.js +1237 -2935
  287. package/.cache/replit/modules/nodejs-14.res +0 -1
  288. package/.cache/replit/modules/web.res +0 -1
  289. package/.cache/typescript/5.5/package.json +0 -1
  290. package/.config/configstore/update-notifier-npm.json +0 -4
  291. package/.gitattributes +0 -2
  292. package/.upm/store.json +0 -1
  293. package/Extra/Balancer.js +0 -49
  294. package/Extra/Bypass/956/index.js +0 -234
  295. package/Extra/Bypass/test/aaaa.json +0 -170
  296. package/Extra/Bypass/test/index.js +0 -188
  297. package/Extra/Database/index.js +0 -469
  298. package/Extra/ExtraAddons.js +0 -82
  299. package/Extra/ExtraFindUID.js +0 -62
  300. package/Extra/ExtraGetThread.js +0 -365
  301. package/Extra/ExtraScreenShot.js +0 -430
  302. package/Extra/ExtraUptimeRobot.js +0 -38
  303. package/Extra/Html/Classic/script.js +0 -119
  304. package/Extra/Html/Classic/style.css +0 -8
  305. package/Extra/Security/Base/Step_1.js +0 -6
  306. package/Extra/Security/Base/Step_2.js +0 -22
  307. package/Extra/Security/Base/Step_3.js +0 -22
  308. package/Extra/Security/Base/index.js +0 -191
  309. package/Extra/Security/Index.js +0 -5
  310. package/Extra/Security/Step_1.js +0 -6
  311. package/Extra/Security/Step_2.js +0 -22
  312. package/Extra/Security/Step_3.js +0 -22
  313. package/Extra/Src/Change_Environment.js +0 -24
  314. package/Extra/Src/Check_Update.js +0 -67
  315. package/Extra/Src/History.js +0 -115
  316. package/Extra/Src/Instant_Update.js +0 -65
  317. package/Extra/Src/Last-Run.js +0 -65
  318. package/Extra/Src/Premium.js +0 -81
  319. package/Extra/Src/Release_Memory.js +0 -160
  320. package/Extra/Src/Websocket.js +0 -213
  321. package/Extra/Src/image/checkmate.jpg +0 -0
  322. package/Extra/Src/test.js +0 -28
  323. package/Extra/Src/uuid.js +0 -137
  324. package/Func/AcceptAgreement.js +0 -31
  325. package/Func/ClearCache.js +0 -64
  326. package/Func/ReportV1.js +0 -54
  327. package/LICENSE +0 -678
  328. package/Language/index.json +0 -228
  329. package/Main.js +0 -1444
  330. package/SECURITY.md +0 -18
  331. package/broadcast.js +0 -44
  332. package/logger.js +0 -66
  333. package/src/Dev_Horizon_Data.js +0 -125
  334. package/src/Dev_getThreadInfoOLD.js +0 -422
  335. package/src/Dev_shareTest2.js +0 -68
  336. package/src/Dev_shareTest3.js +0 -71
  337. package/src/Premium.js +0 -25
  338. package/src/Screenshot.js +0 -83
  339. package/src/getAccessToken.js +0 -28
  340. package/src/getThreadInfoOLD.js +0 -422
  341. package/src/getThreadMain.js +0 -220
  342. package/src/getUserInfoMain.js +0 -65
  343. package/src/getUserInfoV2.js +0 -32
  344. package/src/getUserInfoV3.js +0 -63
  345. package/src/getUserInfoV4.js +0 -55
  346. package/src/getUserInfoV5.js +0 -61
  347. package/src/listenMqttV1.js +0 -846
  348. package/src/sendMqttMessage.js +0 -71
  349. package/src/unsendMqttMessage.js +0 -66
  350. package/test/Database_Test.js +0 -4
  351. package/test/Db2.js +0 -530
  352. package/test/Shankar_Database/A_README.md +0 -1
  353. package/test/Shankar_Database/Database.db +0 -0
  354. package/test/data/shareAttach.js +0 -146
  355. package/test/data/something.mov +0 -0
  356. package/test/data/test.png +0 -0
  357. package/test/data/test.txt +0 -7
  358. package/test/env/.env +0 -0
  359. package/test/example-db.db +0 -0
  360. package/test/memoryleak.js +0 -18
  361. package/test/testname.js +0 -1342
  362. package/test/testv2.js +0 -3
  363. /package/{Extra/Security/AES_256_GCM/index.js → .cache/nix/binary-cache-v6.sqlite-journal} +0 -0
package/src/listenMqtt.js CHANGED
@@ -1,94 +1,44 @@
1
- /* eslint-disable linebreak-style */
2
- 'use strict';
3
-
4
- const utils = require('../utils');
5
- const log = require('npmlog');
6
- const mqtt = require('mqtt');
7
- const WebSocket = require('ws');
8
- const HttpsProxyAgent = require('https-proxy-agent');
1
+ "use strict";
2
+ var utils = require("../utils");
3
+ // @NethWs3Dev
4
+ var mqtt = require('mqtt');
5
+ var websocket = require('websocket-stream');
6
+ var HttpsProxyAgent = require('https-proxy-agent');
9
7
  const EventEmitter = require('events');
10
- const Duplexify = require('duplexify');
11
- const {
12
- Transform
13
- } = require('stream');
8
+
14
9
  var identity = function() {};
15
10
  var form = {};
16
11
  var getSeqID = function() {};
17
- global.Fca.Data.MsgCount = new Map();
18
- global.Fca.Data.event = new Map();
19
-
20
- const topics = ['/ls_req', '/ls_resp', '/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'];
21
-
22
- let WebSocket_Global;
23
-
24
- function buildProxy() {
25
- const Proxy = new Transform({
26
- objectMode: false,
27
- transform(chunk, enc, next) {
28
- if (WebSocket_Global.readyState !== WebSocket_Global.OPEN) {
29
- return next();
30
- }
31
-
32
- let data;
33
- if (typeof chunk === 'string') {
34
- data = Buffer.from(chunk, 'utf8');
35
- } else {
36
- data = chunk;
37
- }
38
-
39
- WebSocket_Global.send(data);
40
- next();
41
- },
42
- flush(done) {
43
- WebSocket_Global.close();
44
- done();
45
- },
46
- writev(chunks, cb) {
47
- const buffers = chunks.map(({ chunk }) => {
48
- if (typeof chunk === 'string') {
49
- return Buffer.from(chunk, 'utf8');
50
- }
51
- return chunk;
52
- });
53
- this._write(Buffer.concat(buffers), 'binary', cb);
54
- },
55
- });
56
- return Proxy;
57
- }
58
-
59
- function buildStream(options, WebSocket, Proxy) {
60
- const Stream = Duplexify(undefined, undefined, options);
61
- Stream.socket = WebSocket;
62
-
63
- WebSocket.onclose = () => {
64
- Stream.end();
65
- Stream.destroy();
66
- };
67
-
68
- WebSocket.onerror = (err) => {
69
- Stream.destroy(err);
70
- };
71
12
 
72
- WebSocket.onmessage = (event) => {
73
- const data = event.data instanceof ArrayBuffer ? Buffer.from(event.data) : Buffer.from(event.data, 'utf8');
74
- Stream.push(data);
75
- };
76
-
77
- WebSocket.onopen = () => {
78
- Stream.setReadable(Proxy);
79
- Stream.setWritable(Proxy);
80
- Stream.emit('connect');
81
- };
82
-
83
- WebSocket_Global = WebSocket;
84
- Proxy.on('close', () => WebSocket.close());
85
-
86
- return Stream;
87
- }
13
+ var topics = [
14
+ "/legacy_web",
15
+ "/webrtc",
16
+ "/rtc_multi",
17
+ "/onevc",
18
+ "/br_sr", //Notification
19
+ //Need to publish /br_sr right after this
20
+ "/sr_res",
21
+ "/t_ms",
22
+ "/thread_typing",
23
+ "/orca_typing_notifications",
24
+ "/notify_disconnect",
25
+ //Need to publish /messenger_sync_create_queue right after this
26
+ "/orca_presence",
27
+ //Will receive /sr_res right here.
28
+
29
+ "/inbox",
30
+ "/mercury",
31
+ "/messaging_events",
32
+ "/orca_message_notifications",
33
+ "/pp",
34
+ "/webrtc_response",
35
+ ];
88
36
 
89
37
  function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
90
- const chatOn = ctx.globalOptions.online;
91
- const foreground = false;
38
+ //Don't really know what this does but I think it's for the active state?
39
+ //TODO: Move to ctx when implemented
40
+ var chatOn = ctx.globalOptions.online;
41
+ var foreground = false;
92
42
 
93
43
  const sessionID = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER) + 1;
94
44
  const GUID = utils.getGUID()
@@ -110,7 +60,9 @@ function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
110
60
  no_auto_fg: true,
111
61
  gas: null,
112
62
  pack: [],
63
+ a: ctx.globalOptions.userAgent,
113
64
  p: null,
65
+ aids: null,
114
66
  php_override: ""
115
67
  };
116
68
 
@@ -118,11 +70,11 @@ function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
118
70
 
119
71
  let host;
120
72
  if (ctx.mqttEndpoint) {
121
- host = `${ctx.mqttEndpoint}&sid=${sessionID}&cid=${GUID}`;
73
+ host = `${ctx.mqttEndpoint}&sid=${sessionID}`;
122
74
  } else if (ctx.region) {
123
- host = `wss://edge-chat.facebook.com/chat?region=${ctx.region.toLowerCase()}&sid=${sessionID}&cid=${GUID}`;
75
+ host = `wss://edge-chat.facebook.com/chat?region=${ctx.region.toLowerCase()}&sid=${sessionID}`;
124
76
  } else {
125
- host = `wss://edge-chat.facebook.com/chat?sid=${sessionID}&cid=${GUID}`;
77
+ host = `wss://edge-chat.facebook.com/chat?sid=${sessionID}`;
126
78
  }
127
79
 
128
80
  const options = {
@@ -135,7 +87,7 @@ function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
135
87
  headers: {
136
88
  Cookie: cookies,
137
89
  Origin: 'https://www.facebook.com',
138
- 'User-Agent': ctx.globalOptions.userAgent,
90
+ 'User-Agent': ctx.globalOptions.userAgent || 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36',
139
91
  Referer: 'https://www.facebook.com/',
140
92
  Host: new URL(host).hostname,
141
93
  },
@@ -148,111 +100,65 @@ function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
148
100
  reconnectPeriod: 3,
149
101
  };
150
102
 
151
- if (ctx.globalOptions.proxy !== undefined) {
152
- const agent = new HttpsProxyAgent(ctx.globalOptions.proxy);
103
+ if (typeof ctx.globalOptions.proxy != "undefined") {
104
+ var agent = new HttpsProxyAgent(ctx.globalOptions.proxy);
153
105
  options.wsOptions.agent = agent;
154
106
  }
155
107
 
156
- ctx.mqttClient = new mqtt.Client(() => buildStream(options, new WebSocket(host, options.wsOptions), buildProxy()), options);
157
- global.mqttClient = ctx.mqttClient;
108
+ ctx.mqttClient = new mqtt.Client(_ => websocket(host, options.wsOptions), options);
158
109
 
159
- global.mqttClient.on('error', (err) => {
160
- log.error('listenMqtt', err);
161
- global.mqttClient.end();
110
+ var mqttClient = ctx.mqttClient;
162
111
 
112
+
113
+ function stopListening() {
114
+ if (mqttClient) {
115
+ mqttClient.unsubscribe("/webrtc");
116
+ mqttClient.unsubscribe("/rtc_multi");
117
+ mqttClient.unsubscribe("/onevc");
118
+ mqttClient.publish("/browser_close", "{}");
119
+ mqttClient.end(false, function(...data) {
120
+ ctx.mqttClient = null; mqttClient = null;
121
+ });
122
+ }
123
+ }
124
+
125
+ mqttClient.on('error', function(err) {
126
+ stopListening();
163
127
  if (ctx.globalOptions.autoReconnect) {
164
128
  getSeqID();
165
129
  } else {
166
- globalCallback({
167
- type: 'stop_listen',
168
- error: 'Server Đã Sập - Auto Restart'
169
- }, null);
170
- return process.exit(1);
130
+ globalCallback({ type: "stop_listen", error: "Connection refused: Server unavailable" }, null);
171
131
  }
132
+ console.warn("login", "Error detected. Will relogin automatically...");
133
+ api.ws3.relogin();
134
+ return;
172
135
  });
173
136
 
174
- global.mqttClient.on('connect', () => {
175
- if (!global.Fca.Data.Setup || global.Fca.Data.Setup === undefined) {
176
- if (global.Fca.Require.FastConfig.RestartMQTT_Minutes !== 0 && global.Fca.Data.StopListening !== true) {
177
- global.Fca.Data.Setup = true;
178
- setTimeout(() => {
179
- global.Fca.Require.logger.Warning('Closing MQTT Client...');
180
- ctx.mqttClient.end();
181
- global.Fca.Require.logger.Warning('Reconnecting MQTT Client...');
182
- global.Fca.Data.Setup = false;
183
- getSeqID();
184
- }, Number(global.Fca.Require.FastConfig.RestartMQTT_Minutes) * 60 * 1000);
185
- }
186
- }
187
-
188
- if (process.env.OnStatus === undefined) {
189
- global.Fca.Require.logger.Normal('Bạn Đang Sài Phiên Bản: Premium Access');
190
-
191
- if (Number(global.Fca.Require.FastConfig.AutoRestartMinutes) === 0) {
192
- // something
193
- } else if (Number(global.Fca.Require.FastConfig.AutoRestartMinutes) < 10) {
194
- log.warn('AutoRestartMinutes', 'The number of minutes to automatically restart must be more than 10 minutes');
195
- } else if (Number(global.Fca.Require.FastConfig.AutoRestartMinutes) < 0) {
196
- log.warn('AutoRestartMinutes', 'Invalid auto-restart minutes!');
197
- } else {
198
- global.Fca.Require.logger.Normal(global.Fca.getText(global.Fca.Require.Language.Src.AutoRestart, global.Fca.Require.FastConfig.AutoRestartMinutes));
199
- global.Fca.Require.logger.Normal(`Auto Restart MQTT Client After: ${global.Fca.Require.FastConfig.RestartMQTT_Minutes} Minutes`);
200
- setTimeout(() => {
201
- global.Fca.Require.logger.Normal(global.Fca.Require.Language.Src.OnRestart);
202
- process.exit(1);
203
- }, Number(global.Fca.Require.FastConfig.AutoRestartMinutes) * 60000);
204
- }
205
- require('../broadcast').startBroadcasting();
206
- const MemoryManager = require('../Extra/Src/Release_Memory');
207
- const path = require('path');
208
-
209
- const SettingMemoryManager = {
210
- warningThreshold: 0.7,
211
- releaseThreshold: 0.8,
212
- maxThreshold: 0.9,
213
- interval: 300 * 1000,
214
- logLevel: 'warn',
215
- logFile: path.join(process.cwd(), 'Horizon_Database' ,'memory.log'),
216
- smartReleaseEnabled: true,
217
- allowLog: (global.Fca.Require.FastConfig.AntiStuckAndMemoryLeak.LogFile.Use || false)
218
- };
219
-
220
- const memoryManager = new MemoryManager(SettingMemoryManager);
221
-
222
- memoryManager.autoStart(60 * 60 * 1000);
223
-
224
- if (global.Fca.Require.FastConfig.AntiStuckAndMemoryLeak.AutoRestart.Use) {
225
- memoryManager.onMaxMemory(function() {
226
- global.Fca.Require.logger.Warning('Memory Usage >= 90% - Auto Restart Avoid Crash');
227
- process.exit(1);
228
- });
229
- }
230
- process.env.OnStatus = true;
231
- }
232
-
233
- topics.forEach((topicsub) => global.mqttClient.subscribe(topicsub));
234
-
235
-
236
- let topic;
237
- const queue = {
238
- sync_api_version: 11,
239
- max_deltas_able_to_process: 100,
137
+ mqttClient.on('connect', function() {
138
+ topics.forEach(topicsub => mqttClient.subscribe(topicsub));
139
+ var topic;
140
+ var queue = {
141
+ sync_api_version: 10,
142
+ max_deltas_able_to_process: 1000,
240
143
  delta_batch_size: 500,
241
- encoding: 'JSON',
144
+ encoding: "JSON",
242
145
  entity_fbid: ctx.userID,
243
146
  };
244
147
 
245
- topic = "/messenger_sync_create_queue";
246
- queue.initial_titan_sequence_id = ctx.lastSeqId;
247
- queue.device_params = null;
248
-
249
- global.mqttClient.publish(topic, JSON.stringify(queue), {
250
- qos: 1,
251
- retain: false
252
- });
148
+ if (ctx.syncToken) {
149
+ topic = "/messenger_sync_get_diffs";
150
+ queue.last_seq_id = ctx.lastSeqId;
151
+ queue.sync_token = ctx.syncToken;
152
+ } else {
153
+ topic = "/messenger_sync_create_queue";
154
+ queue.initial_titan_sequence_id = ctx.lastSeqId;
155
+ queue.device_params = null;
156
+ }
253
157
 
158
+ mqttClient.publish(topic, JSON.stringify(queue), { qos: 1, retain: false });
159
+ mqttClient.publish("/foreground_state", JSON.stringify({ "foreground": chatOn }), { qos: 1 });
254
160
  var rTimeout = setTimeout(function() {
255
- global.mqttClient.end();
161
+ mqttClient.end();
256
162
  getSeqID();
257
163
  }, 3000);
258
164
 
@@ -261,13 +167,17 @@ function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
261
167
  ctx.globalOptions.emitReady ? globalCallback({
262
168
  type: "ready",
263
169
  error: null
264
- }) : '';
170
+ }) : "";
265
171
  delete ctx.tmsWait;
266
172
  };
267
173
  });
268
174
 
269
- const HandleMessage = function(topic, message, _packet) {
270
- const jsonMessage = JSON.parse(message.toString());
175
+ mqttClient.on('message', function(topic, message, _packet) {
176
+ try {
177
+ var jsonMessage = JSON.parse(message);
178
+ } catch (ex) {
179
+ return console.error("listenMqtt", ex);
180
+ }
271
181
  if (topic === "/t_ms") {
272
182
  if (ctx.tmsWait && typeof ctx.tmsWait == "function") ctx.tmsWait();
273
183
 
@@ -277,31 +187,11 @@ function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
277
187
  }
278
188
 
279
189
  if (jsonMessage.lastIssuedSeqId) ctx.lastSeqId = parseInt(jsonMessage.lastIssuedSeqId);
190
+
280
191
  //If it contains more than 1 delta
281
192
  for (var i in jsonMessage.deltas) {
282
193
  var delta = jsonMessage.deltas[i];
283
- parseDelta(defaultFuncs, api, ctx, globalCallback, {
284
- "delta": delta
285
- });
286
- }
287
- } else if (topic === "/ls_resp") {
288
- const payload = JSON.parse(jsonMessage.payload); //'{"name":null,"step":[1,[1,[4,0,1,[5,"taskExists",[19,"415"]]],[23,[2,0],[1,[5,"replaceOptimsiticMessage","7192532113093667880","mid.$gABfX5li9LA6VdUymnWPRAdlkiawo"]]]],[1,[4,0,1,[5,"taskExists",[19,"415"]]],[23,[2,0],[1,[5,"mailboxTaskCompletionApiOnTaskCompletion",[19,"415"],true]]]],[1,[4,0,1,[5,"taskExists",[19,"415"]]],[23,[2,0],[1,[5,"removeTask",[19,"415"],[9]]]]]]}'
289
- const request_ID = jsonMessage.request_id;
290
-
291
- if (ctx.callback_Task[request_ID] != undefined && ctx.callback_Task[request_ID].type != undefined) {
292
- const {
293
- callback,
294
- type
295
- } = ctx.callback_Task[request_ID];
296
- const Data = new getRespData(type, payload);
297
- if (!callback) {
298
- return;
299
- }
300
- else if (!Data) {
301
- callback("Something went wrong 🐳", null);
302
- } else {
303
- callback(null, Data);
304
- }
194
+ parseDelta(defaultFuncs, api, ctx, globalCallback, { "delta": delta });
305
195
  }
306
196
  } else if (topic === "/thread_typing" || topic === "/orca_typing_notifications") {
307
197
  var typ = {
@@ -310,9 +200,7 @@ function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
310
200
  from: jsonMessage.sender_fbid.toString(),
311
201
  threadID: utils.formatID((jsonMessage.thread || jsonMessage.sender_fbid).toString())
312
202
  };
313
- (function() {
314
- globalCallback(null, typ);
315
- })();
203
+ (function() { globalCallback(null, typ); })();
316
204
  } else if (topic === "/orca_presence") {
317
205
  if (!ctx.globalOptions.updatePresence) {
318
206
  for (var i in jsonMessage.list) {
@@ -326,517 +214,421 @@ function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
326
214
  timestamp: data["l"] * 1000,
327
215
  statuses: data["p"]
328
216
  };
329
- (function() {
330
- globalCallback(null, presence);
331
- })();
217
+ (function() { globalCallback(null, presence); })();
332
218
  }
333
219
  }
334
220
  }
335
221
 
336
- };
337
-
338
- global.mqttClient.on('message', HandleMessage);
339
-
340
- process.on('SIGINT', () => {
341
- LogUptime();
342
- process.kill(process.pid);
343
222
  });
344
223
 
345
- process.on('exit', LogUptime);
346
-
347
-
348
- }
349
-
350
- function getRespData(Type, payload) {
351
- try {
352
- switch (Type) {
353
- case "sendMqttMessage": {
354
- return {
355
- type: Type,
356
- threadID: payload.step[1][2][2][1][2], //this is sick bro
357
- messageID: payload.step[1][2][2][1][3],
358
- payload: payload.step[1][2]
359
- };
360
- }
361
- default: { //!very LAZY :> cook yourself
362
- return {
363
- Data: payload.step[1][2][2][1],
364
- type: Type,
365
- payload: payload.step[1][2]
366
- };
367
- }
368
- }
369
- } catch (e) {
370
- return null;
371
- }
372
- }
373
-
374
- function LogUptime() {
375
- const uptime = process.uptime();
376
- const {
377
- join
378
- } = require('path');
379
- const filePath = join(__dirname, '../CountTime.json');
380
-
381
- let time1;
382
- if (global.Fca.Require.fs.existsSync(filePath)) {
383
- time1 = Number(global.Fca.Require.fs.readFileSync(filePath, 'utf8')) || 0;
384
- } else {
385
- time1 = 0;
386
- }
387
-
388
- global.Fca.Require.fs.writeFileSync(filePath, String(Number(uptime) + time1), 'utf8');
389
- }
390
-
391
- if (global.Fca.Require.FastConfig.AntiGetInfo.AntiGetThreadInfo) {
392
- setInterval(() => {
393
- try {
394
- const { updateMessageCount, getData, hasData } = require('../Extra/ExtraGetThread');
395
- const Data = global.Fca.Data.MsgCount;
396
- const Arr = Array.from(Data.keys());
397
- for (let i of Arr) {
398
- const Count = parseInt(Data.get(i));
399
- if (hasData(i)) {
400
- let x = getData(i);
401
- x.messageCount += Count;
402
- updateMessageCount(i, x);
403
- Data.delete(i);
404
- }
405
- }
406
-
407
- } catch (e) {
408
- console.log(e);
409
- }
410
- }, 30 * 1000);
224
+ mqttClient.on('close', function() {
225
+ //(function () { globalCallback("Connection closed."); })();
226
+ // client.end();
227
+ });
411
228
  }
412
229
 
413
- function parseDelta(defaultFuncs, api, ctx, globalCallback, {
414
- delta
415
- }) {
416
- if (delta.class === 'NewMessage') {
417
- if (ctx.globalOptions.pageID && ctx.globalOptions.pageID !== delta.queue) return;
230
+ function parseDelta(defaultFuncs, api, ctx, globalCallback, v) {
231
+ if (v.delta.class == "NewMessage") {
232
+ //Not tested for pages
233
+ if (ctx.globalOptions.pageID && ctx.globalOptions.pageID != v.queue) return;
418
234
 
419
- const resolveAttachmentUrl = (i) => {
420
- if (!delta.attachments || i === delta.attachments.length || utils.getType(delta.attachments) !== 'Array') {
421
- let fmtMsg;
235
+ (function resolveAttachmentUrl(i) {
236
+ if (v.delta.attachments && (i == v.delta.attachments.length)) {
237
+ var fmtMsg;
422
238
  try {
423
- fmtMsg = utils.formatDeltaMessage(delta);
239
+ fmtMsg = utils.formatDeltaMessage(v);
424
240
  } catch (err) {
425
- return log.error('Lỗi Nhẹ', err);
241
+ return globalCallback({
242
+ error: "Problem parsing message object. Please open an issue at https://github.com/Schmavery/facebook-chat-api/issues.",
243
+ detail: err,
244
+ res: v,
245
+ type: "parse_error"
246
+ });
426
247
  }
427
-
428
- if (fmtMsg) {
429
- const isGroup = fmtMsg.isGroup;
430
- const threadID = fmtMsg.threadID;
431
- const messageID = fmtMsg.messageID;
432
-
433
- global.Fca.Data.event.set("Data", {
434
- isGroup,
435
- threadID,
436
- messageID
437
- });
438
-
439
- if (global.Fca.Require.FastConfig.AntiGetInfo.AntiGetThreadInfo) {
440
- global.Fca.Data.MsgCount.set(fmtMsg.threadID, ((global.Fca.Data.MsgCount.get(fmtMsg.threadID)) + 1 || 1));
441
- }
442
-
443
- if (ctx.globalOptions.autoMarkDelivery) {
444
- markDelivery(ctx, api, fmtMsg.threadID, fmtMsg.messageID);
445
- }
248
+ if (fmtMsg)
249
+ if (ctx.globalOptions.autoMarkDelivery) markDelivery(ctx, api, fmtMsg.threadID, fmtMsg.messageID);
446
250
 
447
- if (!ctx.globalOptions.selfListen && fmtMsg.senderID === ctx.userID) return;
448
- globalCallback(null, fmtMsg);
449
- }
251
+ return !ctx.globalOptions.selfListen && fmtMsg.senderID === ctx.userID ? undefined : (function() { globalCallback(null, fmtMsg); })();
450
252
  } else {
451
- const attachment = delta.attachments[i];
452
- if (attachment.mercury.attach_type === 'photo') {
453
- api.resolvePhotoUrl(attachment.fbid, (err, url) => {
454
- if (!err) attachment.mercury.metadata.url = url;
455
- resolveAttachmentUrl(i + 1);
253
+ if (v.delta.attachments && (v.delta.attachments[i].mercury.attach_type == "photo")) {
254
+ api.resolvePhotoUrl(v.delta.attachments[i].fbid, (err, url) => {
255
+ if (!err) v.delta.attachments[i].mercury.metadata.url = url;
256
+ return resolveAttachmentUrl(i + 1);
456
257
  });
457
- } else {
458
- resolveAttachmentUrl(i + 1);
459
- }
258
+ } else return resolveAttachmentUrl(i + 1);
460
259
  }
461
- };
260
+ })(0);
261
+ }
462
262
 
463
- resolveAttachmentUrl(0);
464
- } else if (delta.class === 'ClientPayload') {
465
- const clientPayload = utils.decodeClientPayload(delta.payload);
263
+ if (v.delta.class == "ClientPayload") {
264
+ var clientPayload = utils.decodeClientPayload(v.delta.payload);
466
265
  if (clientPayload && clientPayload.deltas) {
467
- for (const delta of clientPayload.deltas) {
266
+ for (var i in clientPayload.deltas) {
267
+ var delta = clientPayload.deltas[i];
468
268
  if (delta.deltaMessageReaction && !!ctx.globalOptions.listenEvents) {
469
- const messageReaction = {
470
- type: 'message_reaction',
471
- threadID: (delta.deltaMessageReaction.threadKey.threadFbId ? delta.deltaMessageReaction.threadKey.threadFbId : delta.deltaMessageReaction.threadKey.otherUserFbId).toString(),
472
- messageID: delta.deltaMessageReaction.messageId,
473
- reaction: delta.deltaMessageReaction.reaction,
474
- senderID: delta.deltaMessageReaction.senderId.toString(),
475
- userID: delta.deltaMessageReaction.userId.toString(),
476
- };
477
- globalCallback(null, messageReaction);
269
+ (function() {
270
+ globalCallback(null, {
271
+ type: "message_reaction",
272
+ threadID: (delta.deltaMessageReaction.threadKey.threadFbId ? delta.deltaMessageReaction.threadKey.threadFbId : delta.deltaMessageReaction.threadKey.otherUserFbId).toString(),
273
+ messageID: delta.deltaMessageReaction.messageId,
274
+ reaction: delta.deltaMessageReaction.reaction,
275
+ senderID: delta.deltaMessageReaction.senderId.toString(),
276
+ userID: delta.deltaMessageReaction.userId.toString()
277
+ });
278
+ })();
478
279
  } else if (delta.deltaRecallMessageData && !!ctx.globalOptions.listenEvents) {
479
- const messageUnsend = {
480
- type: 'message_unsend',
481
- threadID: (delta.deltaRecallMessageData.threadKey.threadFbId ? delta.deltaRecallMessageData.threadKey.threadFbId : delta.deltaRecallMessageData.threadKey.otherUserFbId).toString(),
482
- messageID: delta.deltaRecallMessageData.messageID,
483
- senderID: delta.deltaRecallMessageData.senderID.toString(),
484
- deletionTimestamp: delta.deltaRecallMessageData.deletionTimestamp,
485
- timestamp: delta.deltaRecallMessageData.timestamp,
486
- };
487
- globalCallback(null, messageUnsend);
280
+ (function() {
281
+ globalCallback(null, {
282
+ type: "message_unsend",
283
+ threadID: (delta.deltaRecallMessageData.threadKey.threadFbId ? delta.deltaRecallMessageData.threadKey.threadFbId : delta.deltaRecallMessageData.threadKey.otherUserFbId).toString(),
284
+ messageID: delta.deltaRecallMessageData.messageID,
285
+ senderID: delta.deltaRecallMessageData.senderID.toString(),
286
+ deletionTimestamp: delta.deltaRecallMessageData.deletionTimestamp,
287
+ timestamp: delta.deltaRecallMessageData.timestamp
288
+ });
289
+ })();
488
290
  } else if (delta.deltaMessageReply) {
489
- const mdata =
490
- delta.deltaMessageReply.message === undefined ?
491
- [] :
492
- delta.deltaMessageReply.message.data === undefined ?
493
- [] :
494
- delta.deltaMessageReply.message.data.prng === undefined ?
495
- [] :
291
+ //Mention block - #1
292
+ var mdata =
293
+ delta.deltaMessageReply.message === undefined ? [] :
294
+ delta.deltaMessageReply.message.data === undefined ? [] :
295
+ delta.deltaMessageReply.message.data.prng === undefined ? [] :
496
296
  JSON.parse(delta.deltaMessageReply.message.data.prng);
297
+ var m_id = mdata.map(u => u.i);
298
+ var m_offset = mdata.map(u => u.o);
299
+ var m_length = mdata.map(u => u.l);
497
300
 
498
- const m_id = mdata.map((u) => u.i);
499
- const m_offset = mdata.map((u) => u.o);
500
- const m_length = mdata.map((u) => u.l);
301
+ var mentions = {};
501
302
 
502
- const mentions = {};
503
- for (let i = 0; i < m_id.length; i++) {
504
- mentions[m_id[i]] = (delta.deltaMessageReply.message.body || '').substring(m_offset[i], m_offset[i] + m_length[i]);
505
- }
506
-
507
- const callbackToReturn = {
508
- type: 'message_reply',
303
+ 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]);
304
+ //Mention block - 1#
305
+ var callbackToReturn = {
306
+ type: "message_reply",
509
307
  threadID: (delta.deltaMessageReply.message.messageMetadata.threadKey.threadFbId ? delta.deltaMessageReply.message.messageMetadata.threadKey.threadFbId : delta.deltaMessageReply.message.messageMetadata.threadKey.otherUserFbId).toString(),
510
308
  messageID: delta.deltaMessageReply.message.messageMetadata.messageId,
511
309
  senderID: delta.deltaMessageReply.message.messageMetadata.actorFbId.toString(),
512
- attachments: ( delta.deltaMessageReply.message.attachments || [] )
513
- .map((att) => {
514
- const mercury = JSON.parse(att.mercuryJSON);
515
- Object.assign(att, mercury);
516
- return att;
517
- })
518
- .map((att) => {
519
- let x;
520
- try {
521
- x = utils._formatAttachment(att);
522
- } catch (ex) {
523
- x = att;
524
- x.error = ex;
525
- x.type = 'unknown';
526
- }
527
- return x;
528
- }),
529
- args: (delta.deltaMessageReply.message.body || '').trim().split(/\s+/),
530
- body: delta.deltaMessageReply.message.body || '',
310
+ attachments: delta.deltaMessageReply.message.attachments.map(function(att) {
311
+ var mercury = JSON.parse(att.mercuryJSON);
312
+ Object.assign(att, mercury);
313
+ return att;
314
+ }).map(att => {
315
+ var x;
316
+ try {
317
+ x = utils._formatAttachment(att);
318
+ } catch (ex) {
319
+ x = att;
320
+ x.error = ex;
321
+ x.type = "unknown";
322
+ }
323
+ return x;
324
+ }),
325
+ args: (delta.deltaMessageReply.message.body || "").trim().split(/\s+/),
326
+ body: (delta.deltaMessageReply.message.body || ""),
531
327
  isGroup: !!delta.deltaMessageReply.message.messageMetadata.threadKey.threadFbId,
532
- mentions,
533
- timestamp: parseInt(delta.deltaMessageReply.message.messageMetadata.timestamp),
534
- participantIDs: (delta.deltaMessageReply.message.participants || []).map((e) => e.toString()),
328
+ mentions: mentions,
329
+ timestamp: delta.deltaMessageReply.message.messageMetadata.timestamp,
330
+ participantIDs: (delta.deltaMessageReply.message.participants || []).map(e => e.toString())
535
331
  };
536
332
 
537
333
  if (delta.deltaMessageReply.repliedToMessage) {
538
- const mdata =
539
- delta.deltaMessageReply.repliedToMessage === undefined ?
540
- [] :
541
- delta.deltaMessageReply.repliedToMessage.data === undefined ?
542
- [] :
543
- delta.deltaMessageReply.repliedToMessage.data.prng === undefined ?
544
- [] :
334
+ //Mention block - #2
335
+ mdata =
336
+ delta.deltaMessageReply.repliedToMessage === undefined ? [] :
337
+ delta.deltaMessageReply.repliedToMessage.data === undefined ? [] :
338
+ delta.deltaMessageReply.repliedToMessage.data.prng === undefined ? [] :
545
339
  JSON.parse(delta.deltaMessageReply.repliedToMessage.data.prng);
340
+ m_id = mdata.map(u => u.i);
341
+ m_offset = mdata.map(u => u.o);
342
+ m_length = mdata.map(u => u.l);
546
343
 
547
- const m_id = mdata.map((u) => u.i);
548
- const m_offset = mdata.map((u) => u.o);
549
- const m_length = mdata.map((u) => u.l);
550
-
551
- const rmentions = {};
552
- for (let i = 0; i < m_id.length; i++) {
553
- rmentions[m_id[i]] = (delta.deltaMessageReply.repliedToMessage.body || '').substring(m_offset[i], m_offset[i] + m_length[i]);
554
- }
344
+ var rmentions = {};
555
345
 
346
+ 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]);
347
+ //Mention block - 2#
556
348
  callbackToReturn.messageReply = {
557
349
  threadID: (delta.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.threadFbId ? delta.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.threadFbId : delta.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.otherUserFbId).toString(),
558
350
  messageID: delta.deltaMessageReply.repliedToMessage.messageMetadata.messageId,
559
351
  senderID: delta.deltaMessageReply.repliedToMessage.messageMetadata.actorFbId.toString(),
560
- attachments: delta.deltaMessageReply.repliedToMessage.attachments
561
- .map((att) => {
562
- let mercury;
563
- try {
564
- mercury = JSON.parse(att.mercuryJSON);
565
- Object.assign(att, mercury);
566
- } catch (ex) {
567
- mercury = {};
568
- }
352
+ attachments: delta.deltaMessageReply.repliedToMessage.attachments.map(function(att) {
353
+ var mercury = JSON.parse(att.mercuryJSON);
354
+ Object.assign(att, mercury);
569
355
  return att;
570
- })
571
- .map((att) => {
572
- let x;
356
+ }).map(att => {
357
+ var x;
573
358
  try {
574
359
  x = utils._formatAttachment(att);
575
360
  } catch (ex) {
576
361
  x = att;
577
362
  x.error = ex;
578
- x.type = 'unknown';
363
+ x.type = "unknown";
579
364
  }
580
365
  return x;
581
366
  }),
582
- args: (delta.deltaMessageReply.repliedToMessage.body || '').trim().split(/\s+/),
583
- body: delta.deltaMessageReply.repliedToMessage.body || '',
367
+ args: (delta.deltaMessageReply.repliedToMessage.body || "").trim().split(/\s+/),
368
+ body: delta.deltaMessageReply.repliedToMessage.body || "",
584
369
  isGroup: !!delta.deltaMessageReply.repliedToMessage.messageMetadata.threadKey.threadFbId,
585
370
  mentions: rmentions,
586
- timestamp: parseInt(delta.deltaMessageReply.repliedToMessage.messageMetadata.timestamp),
587
- participantIDs: (delta.deltaMessageReply.repliedToMessage.participants || []).map((e) => e.toString()),
371
+ timestamp: delta.deltaMessageReply.repliedToMessage.messageMetadata.timestamp,
372
+ participantIDs: (delta.deltaMessageReply.repliedToMessage.participants || []).map(e => e.toString())
588
373
  };
589
374
  } else if (delta.deltaMessageReply.replyToMessageId) {
590
375
  return defaultFuncs
591
- .post('https://www.facebook.com/api/graphqlbatch/', ctx.jar, {
592
- av: ctx.globalOptions.pageID,
593
- queries: JSON.stringify({
594
- o0: {
595
- doc_id: '2848441488556444',
596
- query_params: {
597
- thread_and_message_id: {
598
- thread_id: callbackToReturn.threadID,
599
- message_id: delta.deltaMessageReply.replyToMessageId.id,
600
- },
601
- },
602
- },
603
- }),
376
+ .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, {
377
+ "av": ctx.globalOptions.pageID,
378
+ "queries": JSON.stringify({
379
+ "o0": {
380
+ //Using the same doc_id as forcedFetch
381
+ "doc_id": "2848441488556444",
382
+ "query_params": {
383
+ "thread_and_message_id": {
384
+ "thread_id": callbackToReturn.threadID,
385
+ "message_id": delta.deltaMessageReply.replyToMessageId.id,
386
+ }
387
+ }
388
+ }
389
+ })
604
390
  })
605
391
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
606
392
  .then((resData) => {
607
- if (resData[resData.length - 1].error_results > 0) throw resData[0].o0.errors;
608
- if (resData[resData.length - 1].successful_results === 0) throw {
609
- error: 'forcedFetch: there was no successful_results',
610
- res: resData
611
- };
612
- const fetchData = resData[0].o0.data.message;
613
- const mobj = {};
614
-
615
- for (const n in fetchData.message.ranges) {
616
- mobj[fetchData.message.ranges[n].entity.id] = (fetchData.message.text || '').substr(fetchData.message.ranges[n].offset, fetchData.message.ranges[n].length);
393
+ if (resData[resData.length - 1].error_results > 0) {
394
+ const errorL = resData[0].o0.errors;
395
+ throw errorL;
617
396
  }
397
+ if (resData[resData.length - 1].successful_results === 0) throw { error: "forcedFetch: there was no successful_results", res: resData };
398
+ var fetchData = resData[0].o0.data.message;
399
+ var mobj = {};
400
+ 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);
401
+
618
402
  callbackToReturn.messageReply = {
619
- type: 'Message',
620
403
  threadID: callbackToReturn.threadID,
621
404
  messageID: fetchData.message_id,
622
405
  senderID: fetchData.message_sender.id.toString(),
623
- attachments: fetchData.message.blob_attachment.map((att) => utils._formatAttachment({
624
- blob_attachment: att
625
- })),
626
- args: (fetchData.message.text || '').trim().split(/\s+/) || [],
627
- body: fetchData.message.text || '',
406
+ attachments: fetchData.message.blob_attachment.map(att => {
407
+ var x;
408
+ try {
409
+ x = utils._formatAttachment({ blob_attachment: att });
410
+ } catch (ex) {
411
+ x = att;
412
+ x.error = ex;
413
+ x.type = "unknown";
414
+ }
415
+ return x;
416
+ }),
417
+ args: (fetchData.message.text || "").trim().split(/\s+/) || [],
418
+ body: fetchData.message.text || "",
628
419
  isGroup: callbackToReturn.isGroup,
629
420
  mentions: mobj,
630
- timestamp: parseInt(fetchData.timestamp_precise),
421
+ timestamp: parseInt(fetchData.timestamp_precise)
631
422
  };
632
423
  })
633
-
634
- .catch((err) => log.error('forcedFetch', err))
635
- .finally(() => {
636
- if (ctx.globalOptions.autoMarkDelivery) {
637
- markDelivery(ctx, api, callbackToReturn.threadID, callbackToReturn.messageID);
638
- }
639
-
640
- if (!ctx.globalOptions.selfListen && callbackToReturn.senderID === ctx.userID) return;
641
- globalCallback(null, callbackToReturn);
424
+ .catch(err => console.error("forcedFetch", err))
425
+ .finally(function() {
426
+ if (ctx.globalOptions.autoMarkDelivery) markDelivery(ctx, api, callbackToReturn.threadID, callbackToReturn.messageID);
427
+ !ctx.globalOptions.selfListen && callbackToReturn.senderID === ctx.userID ? undefined : (function() { globalCallback(null, callbackToReturn); })();
642
428
  });
643
- } else {
644
- callbackToReturn.delta = delta;
645
- }
646
- if (ctx.globalOptions.autoMarkDelivery) {
647
- markDelivery(ctx, api, callbackToReturn.threadID, callbackToReturn.messageID);
648
- }
429
+ } else callbackToReturn.delta = delta;
430
+
431
+ if (ctx.globalOptions.autoMarkDelivery) markDelivery(ctx, api, callbackToReturn.threadID, callbackToReturn.messageID);
649
432
 
650
- if (!ctx.globalOptions.selfListen && callbackToReturn.senderID === ctx.userID) return;
651
- globalCallback(null, callbackToReturn);
433
+ return !ctx.globalOptions.selfListen && callbackToReturn.senderID === ctx.userID ? undefined : (function() { globalCallback(null, callbackToReturn); })();
652
434
  }
653
435
  }
654
-
655
436
  return;
656
437
  }
657
438
  }
658
- switch (delta.class) {
659
- case 'ReadReceipt': {
660
- let fmtMsg;
439
+
440
+ if (v.delta.class !== "NewMessage" && !ctx.globalOptions.listenEvents) return;
441
+ switch (v.delta.class) {
442
+ case "ReadReceipt":
443
+ var fmtMsg;
661
444
  try {
662
- fmtMsg = utils.formatDeltaReadReceipt(delta);
445
+ fmtMsg = utils.formatDeltaReadReceipt(v.delta);
663
446
  } catch (err) {
664
- return log.error('Lỗi Nhẹ', err);
447
+ return globalCallback({
448
+ error: "Problem parsing message object. Please open an issue at https://github.com/Schmavery/facebook-chat-api/issues.",
449
+ detail: err,
450
+ res: v.delta,
451
+ type: "parse_error"
452
+ });
665
453
  }
666
- globalCallback(null, fmtMsg);
667
- break;
668
- }
669
- case 'AdminTextMessage': {
670
- switch (delta.type) {
671
- case 'joinable_group_link_mode_change':
672
- case 'magic_words':
673
- case 'pin_messages_v2':
674
- case 'change_thread_theme':
675
- case 'change_thread_icon':
676
- case 'change_thread_nickname':
677
- case 'change_thread_admins':
678
- case 'change_thread_approval_mode':
679
- case 'group_poll':
680
- case 'messenger_call_log':
681
- case 'participant_joined_group_call': {
682
- let fmtMsg;
454
+ return (function() { globalCallback(null, fmtMsg); })();
455
+ case "AdminTextMessage":
456
+ switch (v.delta.type) {
457
+ case "change_thread_theme":
458
+ case "change_thread_nickname":
459
+ case "change_thread_admins":
460
+ case "change_thread_approval_mode":
461
+ case "joinable_group_link_mode_change":
462
+ case "rtc_call_log":
463
+ case "group_poll":
464
+ case "update_vote":
465
+ case "magic_words":
466
+ case "messenger_call_log":
467
+ case "participant_joined_group_call":
468
+ var fmtMsg;
683
469
  try {
684
- fmtMsg = utils.formatDeltaEvent(delta);
470
+ fmtMsg = utils.formatDeltaEvent(v.delta);
685
471
  } catch (err) {
686
- console.log(delta);
687
- return log.error('Lỗi Nhẹ', err);
472
+ return globalCallback({
473
+ error: "Problem parsing message object. Please open an issue at https://github.com/Schmavery/facebook-chat-api/issues.",
474
+ detail: err,
475
+ res: v.delta,
476
+ type: "parse_error"
477
+ });
688
478
  }
689
- globalCallback(null, fmtMsg);
690
- break;
691
- }
479
+ return (function() { globalCallback(null, fmtMsg); })();
480
+ default:
481
+ return;
692
482
  }
693
483
  break;
694
- }
695
-
696
- //For group images
697
- case 'ForcedFetch': {
698
- if (!delta.threadKey) return;
699
- const mid = delta.messageId;
700
- const tid = delta.threadKey.threadFbId;
701
-
484
+ //For group images
485
+ case "ForcedFetch":
486
+ if (!v.delta.threadKey) return;
487
+ var mid = v.delta.messageId;
488
+ var tid = v.delta.threadKey.threadFbId;
702
489
  if (mid && tid) {
703
490
  const form = {
704
- av: ctx.globalOptions.pageID,
705
- queries: JSON.stringify({
706
- o0: {
707
- doc_id: '2848441488556444',
708
- query_params: {
709
- thread_and_message_id: {
710
- thread_id: tid.toString(),
711
- message_id: mid,
712
- },
713
- },
714
- },
715
- }),
491
+ "av": ctx.globalOptions.pageID,
492
+ "queries": JSON.stringify({
493
+ "o0": {
494
+ //This doc_id is valid as of March 25, 2020
495
+ "doc_id": "2848441488556444",
496
+ "query_params": {
497
+ "thread_and_message_id": {
498
+ "thread_id": tid.toString(),
499
+ "message_id": mid,
500
+ }
501
+ }
502
+ }
503
+ })
716
504
  };
505
+
717
506
  defaultFuncs
718
- .post('https://www.facebook.com/api/graphqlbatch/', ctx.jar, form)
507
+ .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
719
508
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
720
509
  .then((resData) => {
721
- if (resData[resData.length - 1].error_results > 0) throw resData[0].o0.errors;
510
+ if (resData[resData.length - 1].error_results > 0) {
511
+ const errorL = resData[0].o0.errors;
512
+ throw errorL;
513
+ }
722
514
 
723
- if (resData[resData.length - 1].successful_results === 0) throw {
724
- error: 'forcedFetch: there was no successful_results',
725
- res: resData
726
- };
515
+ if (resData[resData.length - 1].successful_results === 0) throw { error: "forcedFetch: there was no successful_results", res: resData };
727
516
 
728
- const fetchData = resData[0].o0.data.message;
517
+ var fetchData = resData[0].o0.data.message;
729
518
 
730
- if (utils.getType(fetchData) === 'Object') {
731
- log.info('forcedFetch', fetchData);
519
+ if (utils.getType(fetchData) == "Object") {
520
+ console.log("forcedFetch", fetchData);
732
521
  switch (fetchData.__typename) {
733
- case 'ThreadImageMessage':
734
- if (!ctx.globalOptions.selfListen && fetchData.message_sender.id.toString() === ctx.userID) return;
735
- if (!ctx.loggedIn) return;
736
-
737
- globalCallback(null, {
738
- type: 'change_thread_image',
739
- threadID: utils.formatID(tid.toString()),
740
- snippet: fetchData.snippet,
741
- timestamp: fetchData.timestamp_precise,
742
- author: fetchData.message_sender.id,
743
- image: {
744
- attachmentID: fetchData.image_with_metadata && fetchData.image_with_metadata.legacy_attachment_id,
745
- width: fetchData.image_with_metadata && fetchData.image_with_metadata.original_dimensions.x,
746
- height: fetchData.image_with_metadata && fetchData.image_with_metadata.original_dimensions.y,
747
- url: fetchData.image_with_metadata && fetchData.image_with_metadata.preview.uri,
748
- },
749
- });
522
+ case "ThreadImageMessage":
523
+ (!ctx.globalOptions.selfListen &&
524
+ fetchData.message_sender.id.toString() === ctx.userID) ||
525
+ !ctx.loggedIn ?
526
+ undefined :
527
+ (function() {
528
+ globalCallback(null, {
529
+ type: "change_thread_image",
530
+ threadID: utils.formatID(tid.toString()),
531
+ snippet: fetchData.snippet,
532
+ timestamp: fetchData.timestamp_precise,
533
+ author: fetchData.message_sender.id,
534
+ image: {
535
+ attachmentID: fetchData.image_with_metadata && fetchData.image_with_metadata.legacy_attachment_id,
536
+ width: fetchData.image_with_metadata && fetchData.image_with_metadata.original_dimensions.x,
537
+ height: fetchData.image_with_metadata && fetchData.image_with_metadata.original_dimensions.y,
538
+ url: fetchData.image_with_metadata && fetchData.image_with_metadata.preview.uri
539
+ }
540
+ });
541
+ })();
750
542
  break;
751
- case 'UserMessage': {
752
- const event = {
753
- type: 'message',
543
+ case "UserMessage":
544
+ console.log("ff-Return", {
545
+ type: "message",
754
546
  senderID: utils.formatID(fetchData.message_sender.id),
755
- body: fetchData.message.text || '',
547
+ body: fetchData.message.text || "",
756
548
  threadID: utils.formatID(tid.toString()),
757
549
  messageID: fetchData.message_id,
758
550
  attachments: [{
759
- type: 'share',
551
+ type: "share",
760
552
  ID: fetchData.extensible_attachment.legacy_attachment_id,
761
553
  url: fetchData.extensible_attachment.story_attachment.url,
554
+
762
555
  title: fetchData.extensible_attachment.story_attachment.title_with_entities.text,
763
556
  description: fetchData.extensible_attachment.story_attachment.description.text,
764
557
  source: fetchData.extensible_attachment.story_attachment.source,
558
+
765
559
  image: ((fetchData.extensible_attachment.story_attachment.media || {}).image || {}).uri,
766
560
  width: ((fetchData.extensible_attachment.story_attachment.media || {}).image || {}).width,
767
561
  height: ((fetchData.extensible_attachment.story_attachment.media || {}).image || {}).height,
768
562
  playable: (fetchData.extensible_attachment.story_attachment.media || {}).is_playable || false,
769
563
  duration: (fetchData.extensible_attachment.story_attachment.media || {}).playable_duration_in_ms || 0,
564
+
770
565
  subattachments: fetchData.extensible_attachment.subattachments,
771
566
  properties: fetchData.extensible_attachment.story_attachment.properties,
772
- }],
567
+ }],
773
568
  mentions: {},
774
569
  timestamp: parseInt(fetchData.timestamp_precise),
775
- isGroup: (fetchData.message_sender.id !== tid.toString()),
776
- };
570
+ isGroup: (fetchData.message_sender.id != tid.toString())
571
+ });
572
+ globalCallback(null, {
573
+ type: "message",
574
+ senderID: utils.formatID(fetchData.message_sender.id),
575
+ body: fetchData.message.text || "",
576
+ threadID: utils.formatID(tid.toString()),
577
+ messageID: fetchData.message_id,
578
+ attachments: [{
579
+ type: "share",
580
+ ID: fetchData.extensible_attachment.legacy_attachment_id,
581
+ url: fetchData.extensible_attachment.story_attachment.url,
777
582
 
778
- log.info('ff-Return', event);
779
- globalCallback(null, event);
780
- break;
781
- }
782
- default:
783
- log.error('forcedFetch', fetchData);
583
+ title: fetchData.extensible_attachment.story_attachment.title_with_entities.text,
584
+ description: fetchData.extensible_attachment.story_attachment.description.text,
585
+ source: fetchData.extensible_attachment.story_attachment.source,
586
+
587
+ image: ((fetchData.extensible_attachment.story_attachment.media || {}).image || {}).uri,
588
+ width: ((fetchData.extensible_attachment.story_attachment.media || {}).image || {}).width,
589
+ height: ((fetchData.extensible_attachment.story_attachment.media || {}).image || {}).height,
590
+ playable: (fetchData.extensible_attachment.story_attachment.media || {}).is_playable || false,
591
+ duration: (fetchData.extensible_attachment.story_attachment.media || {}).playable_duration_in_ms || 0,
592
+
593
+ subattachments: fetchData.extensible_attachment.subattachments,
594
+ properties: fetchData.extensible_attachment.story_attachment.properties,
595
+ }],
596
+ mentions: {},
597
+ timestamp: parseInt(fetchData.timestamp_precise),
598
+ isGroup: (fetchData.message_sender.id != tid.toString())
599
+ });
784
600
  }
785
- } else {
786
- log.error('forcedFetch', fetchData);
787
- }
601
+ } else console.error("forcedFetch", fetchData);
788
602
  })
789
- .catch((err) => log.error('forcedFetch', err));
603
+ .catch((err) => console.error("forcedFetch", err));
790
604
  }
791
605
  break;
792
- }
793
- case 'ThreadName':
794
- case 'ParticipantsAddedToGroupThread':
795
- case 'ParticipantLeftGroupThread': {
796
- let formattedEvent;
606
+ case "ThreadName":
607
+ case "ParticipantsAddedToGroupThread":
608
+ case "ParticipantLeftGroupThread":
609
+ var formattedEvent;
797
610
  try {
798
- formattedEvent = utils.formatDeltaEvent(delta);
611
+ formattedEvent = utils.formatDeltaEvent(v.delta);
799
612
  } catch (err) {
800
- console.log(err);
801
- return log.error('Lỗi Nhẹ', err);
802
- }
803
-
804
- if (!ctx.globalOptions.selfListen && formattedEvent.author.toString() === ctx.userID) return;
805
- if (!ctx.loggedIn) return;
806
- globalCallback(null, formattedEvent);
807
- break;
808
- }
809
- case 'NewMessage': {
810
- const hasLiveLocation = delta => {
811
- const attachment = delta.attachments?.[0]?.mercury?.extensible_attachment;
812
- const storyAttachment = attachment?.story_attachment;
813
- return storyAttachment?.style_list?.includes('message_live_location');
814
- };
815
-
816
- if (delta.attachments?.length === 1 && hasLiveLocation(delta)) {
817
- delta.class = 'UserLocation';
818
-
819
- try {
820
- const fmtMsg = utils.formatDeltaEvent(delta);
821
- globalCallback(null, fmtMsg);
822
- } catch (err) {
823
- console.log(delta);
824
- log.error('Lỗi Nhẹ', err);
825
- }
613
+ return globalCallback({
614
+ error: "Problem parsing message object. Please open an issue at https://github.com/Schmavery/facebook-chat-api/issues.",
615
+ detail: err,
616
+ res: v.delta,
617
+ type: "parse_error"
618
+ });
826
619
  }
827
- break;
828
- }
620
+ return (!ctx.globalOptions.selfListen && formattedEvent.author.toString() === ctx.userID) || !ctx.loggedIn ? undefined : (function() { globalCallback(null, formattedEvent); })();
829
621
  }
830
622
  }
831
623
 
832
624
  function markDelivery(ctx, api, threadID, messageID) {
833
625
  if (threadID && messageID) {
834
626
  api.markAsDelivered(threadID, messageID, (err) => {
835
- if (err) log.error('markAsDelivered', err);
627
+ if (err) console.error("markAsDelivered", err);
836
628
  else {
837
629
  if (ctx.globalOptions.autoMarkRead) {
838
630
  api.markAsRead(threadID, (err) => {
839
- if (err) log.error('markAsDelivered', err);
631
+ if (err) console.error("markAsDelivered", err);
840
632
  });
841
633
  }
842
634
  }
@@ -844,81 +636,37 @@ function markDelivery(ctx, api, threadID, messageID) {
844
636
  }
845
637
  }
846
638
 
847
-
848
-
849
639
  module.exports = function(defaultFuncs, api, ctx) {
850
640
  var globalCallback = identity;
851
- var okeoke;
852
641
  getSeqID = function getSeqID() {
853
642
  ctx.t_mqttCalled = false;
854
643
  defaultFuncs
855
644
  .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
856
- .then(res => {
857
- okeoke = res;
858
- return res;
859
- })
860
645
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
861
646
  .then((resData) => {
862
- if (utils.getType(resData) != "Array") {
863
- if (okeoke.request.uri && okeoke.request.uri.href.includes("https://www.facebook.com/checkpoint/")) {
864
- if (okeoke.request.uri.href.includes('601051028565049')) {
865
- return global.Fca.BypassAutomationNotification(undefined, ctx.jar, ctx.globalOptions, undefined ,process.env.UID)
866
- }
867
- }
868
- if (global.Fca.Require.FastConfig.AutoLogin) {
869
- return global.Fca.Require.logger.Warning(global.Fca.Require.Language.Index.AutoLogin, function() {
870
- return global.Fca.Action('AutoLogin');
871
- });
872
- } else if (!global.Fca.Require.FastConfig.AutoLogin) {
873
- return global.Fca.Require.logger.Error(global.Fca.Require.Language.Index.ErrAppState);
874
- }
875
- return;
876
- } else {
877
- if (resData && resData[resData.length - 1].error_results > 0) throw resData[0].o0.errors;
878
- if (resData[resData.length - 1].successful_results === 0) throw {
879
- error: "getSeqId: there was no successful_results",
880
- res: resData
881
- };
882
- if (resData[0].o0.data.viewer.message_threads.sync_sequence_id) {
883
- ctx.lastSeqId = resData[0].o0.data.viewer.message_threads.sync_sequence_id;
884
- listenMqtt(defaultFuncs, api, ctx, globalCallback);
885
- } else throw {
886
- error: "getSeqId: no sync_sequence_id found.",
887
- res: resData
888
- };
647
+ if (utils.getType(resData) != "Array")
648
+ throw { error: "Not logged in", res: resData };
649
+ if (resData[resData.length - 1].error_results > 0) {
650
+ const errorL = resData[0].o0.errors;
651
+ throw errorL;
889
652
  }
653
+ if (resData[resData.length - 1].successful_results === 0) throw { error: "getSeqId: there was no successful_results", res: resData };
654
+ if (resData[0].o0.data.viewer.message_threads.sync_sequence_id) {
655
+ ctx.lastSeqId = resData[0].o0.data.viewer.message_threads.sync_sequence_id;
656
+ listenMqtt(defaultFuncs, api, ctx, globalCallback);
657
+ } else throw { error: "getSeqId: no sync_sequence_id found.", res: resData };
890
658
  })
891
659
  .catch((err) => {
892
- log.error("getSeqId", err);
893
- if (okeoke.request.uri && okeoke.request.uri.href.includes("https://www.facebook.com/checkpoint/")) {
894
- if (okeoke.request.uri.href.includes('601051028565049')) {
895
- return global.Fca.BypassAutomationNotification(undefined, ctx.jar, ctx.globalOptions, undefined ,process.env.UID)
896
- }
897
- }
898
- if (utils.getType(err) == "Object" && err.error === global.Fca.Require.Language.Index.ErrAppState) ctx.loggedIn = false;
660
+ if (utils.getType(err) == "Object" && err.error === "Not logged in") {
661
+ ctx.loggedIn = false;
662
+ }
899
663
  return globalCallback(err);
900
664
  });
901
665
  };
902
666
 
903
- return function(callback) {
904
- class MessageEmitter extends EventEmitter {
905
- stopListening(callback) {
906
- callback = callback || (() => {});
907
- globalCallback = identity;
908
- if (ctx.mqttClient) {
909
- ctx.mqttClient.unsubscribe("/webrtc");
910
- ctx.mqttClient.unsubscribe("/rtc_multi");
911
- ctx.mqttClient.unsubscribe("/onevc");
912
- ctx.mqttClient.publish("/browser_close", "{}");
913
- ctx.mqttClient.end(false, function(...data) {
914
- ctx.mqttClient = undefined;
915
- });
916
- }
917
- global.Fca.Data.StopListening = true;
918
- }
919
- }
667
+ return async function(callback) {
920
668
 
921
- var msgEmitter = new MessageEmitter();
669
+ var msgEmitter = new EventEmitter();
922
670
  globalCallback = (callback || function(error, message) {
923
671
  if (error) return msgEmitter.emit("error", error);
924
672
  msgEmitter.emit("message", message);
@@ -928,29 +676,28 @@ module.exports = function(defaultFuncs, api, ctx) {
928
676
  if (!ctx.firstListen) ctx.lastSeqId = null;
929
677
  ctx.syncToken = undefined;
930
678
  ctx.t_mqttCalled = false;
931
-
932
679
  //Same request as getThreadList
933
680
  form = {
934
- av: ctx.globalOptions.pageID,
935
- queries: JSON.stringify({
936
- o0: {
937
- doc_id: '3336396659757871',
938
- query_params: {
939
- limit: 1,
940
- before: null,
941
- tags: ['INBOX'],
942
- includeDeliveryReceipts: false,
943
- includeSeqID: true,
944
- },
945
- },
946
- }),
681
+ "av": ctx.globalOptions.pageID,
682
+ "queries": JSON.stringify({
683
+ "o0": {
684
+ "doc_id": "3336396659757871",
685
+ "query_params": {
686
+ "limit": 1,
687
+ "before": null,
688
+ "tags": ["INBOX"],
689
+ "includeDeliveryReceipts": false,
690
+ "includeSeqID": true
691
+ }
692
+ }
693
+ })
947
694
  };
948
695
 
949
-
950
696
  if (!ctx.firstListen || !ctx.lastSeqId) getSeqID();
951
- else listenMqtt(defaultFuncs, api, ctx, globalCallback);
697
+ else {
698
+ listenMqtt(defaultFuncs, api, ctx, globalCallback);
699
+ }
952
700
  ctx.firstListen = false;
953
-
954
701
  return msgEmitter;
955
702
  };
956
703
  };