fca-smart-shankar 12.0.0 → 13.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 (285) hide show
  1. package/.replit +12 -3
  2. package/.upm/store.json +1 -0
  3. package/CHANGELOG.md +2 -0
  4. package/README.md +0 -1
  5. package/generated-icon.png +0 -0
  6. package/index.js +507 -437
  7. package/package.json +378 -42
  8. package/replit.nix +3 -1
  9. package/shankar-fca.json +4 -0
  10. package/src/addUserToGroup.js +3 -3
  11. package/src/changeAdminStatus.js +2 -2
  12. package/src/changeArchivedStatus.js +2 -2
  13. package/src/changeAvatar.js +8 -8
  14. package/src/changeAvatarV2.js +1 -1
  15. package/src/changeBio.js +4 -4
  16. package/src/changeBlockedStatus.js +2 -2
  17. package/src/changeCover.js +2 -2
  18. package/src/changeGroupImage.js +4 -4
  19. package/src/changeName.js +2 -2
  20. package/src/changeNickname.js +2 -2
  21. package/src/changeThreadColor.js +3 -3
  22. package/src/changeThreadEmoji.js +2 -2
  23. package/src/changeUsername.js +3 -3
  24. package/src/createCommentPost.js +5 -5
  25. package/src/createNewGroup.js +5 -5
  26. package/src/createPoll.js +2 -2
  27. package/src/createPost.js +6 -5
  28. package/src/deleteMessage.js +2 -2
  29. package/src/deleteThread.js +2 -2
  30. package/src/editMessage.js +30 -18
  31. package/src/follow.js +8 -8
  32. package/src/forwardAttachment.js +2 -2
  33. package/src/getAccess.js +2 -2
  34. package/src/getAvatarUser.js +2 -2
  35. package/src/getCurrentUserID.js +4 -4
  36. package/src/getFriendsList.js +3 -3
  37. package/src/getMessage.js +2 -2
  38. package/src/getThreadHistory.js +2 -2
  39. package/src/getThreadHistoryDeprecated.js +2 -2
  40. package/src/getThreadInfo.js +1 -1
  41. package/src/getThreadInfoDeprecated.js +2 -2
  42. package/src/getThreadList.js +3 -3
  43. package/src/getThreadListDeprecated.js +3 -3
  44. package/src/getThreadPictures.js +2 -2
  45. package/src/getUID.js +4 -4
  46. package/src/getUserID.js +3 -3
  47. package/src/getUserInfo.js +52 -18
  48. package/src/handleFriendRequest.js +5 -5
  49. package/src/handleMessageRequest.js +2 -2
  50. package/src/httpGet.js +3 -3
  51. package/src/httpPost.js +3 -3
  52. package/src/httpPostFormData.js +3 -3
  53. package/src/listenMqtt.js +648 -659
  54. package/src/listenNotification.js +1 -1
  55. package/src/logout.js +3 -3
  56. package/src/markAsDelivered.js +5 -2
  57. package/src/markAsRead.js +5 -2
  58. package/src/markAsReadAll.js +2 -2
  59. package/src/markAsSeen.js +2 -2
  60. package/src/muteThread.js +2 -2
  61. package/src/refreshFb_dtsg.js +3 -3
  62. package/src/removeUserFromGroup.js +2 -2
  63. package/src/resolvePhotoUrl.js +2 -2
  64. package/src/searchStickers.js +1 -1
  65. package/src/sendMessage.js +11 -8
  66. package/src/sendMessageMqtt.js +4 -4
  67. package/src/sendTypingIndicator.js +14 -5
  68. package/src/sendTypingIndicatorV2.js +1 -1
  69. package/src/setMessageReaction.js +3 -3
  70. package/src/setPostReaction.js +4 -4
  71. package/src/setProfileGuard.js +3 -3
  72. package/src/setStoryReaction.js +1 -1
  73. package/src/setTitle.js +3 -3
  74. package/src/shareContact.js +1 -1
  75. package/src/shareLink.js +1 -1
  76. package/src/stopListenMqtt.js +5 -2
  77. package/src/unfriend.js +2 -2
  78. package/src/unsendMessage.js +2 -2
  79. package/src/uploadAttachment.js +2 -2
  80. package/test/data/shareAttach.js +146 -0
  81. package/test/data/something.mov +0 -0
  82. package/test/data/test.png +0 -0
  83. package/test/data/test.txt +7 -0
  84. package/test/test-page.js +1 -1
  85. package/utils.js +564 -391
  86. package/.cache/nix/binary-cache-v6.sqlite +0 -0
  87. package/.cache/nix/binary-cache-v6.sqlite-journal +0 -0
  88. package/.cache/replit/env/latest +0 -125
  89. package/.cache/replit/env/latest.json +0 -1
  90. package/.cache/replit/modules/nix.res +0 -1
  91. package/.cache/replit/modules/nodejs-20.res +0 -1
  92. package/.cache/replit/modules/replit.res +0 -1
  93. package/.cache/replit/modules.stamp +0 -0
  94. package/.cache/replit/nix/env.json +0 -1
  95. package/.cache/typescript/5.6/node_modules/.package-lock.json +0 -171
  96. package/.cache/typescript/5.6/node_modules/@types/bluebird/LICENSE +0 -21
  97. package/.cache/typescript/5.6/node_modules/@types/bluebird/README.md +0 -15
  98. package/.cache/typescript/5.6/node_modules/@types/bluebird/index.d.ts +0 -1365
  99. package/.cache/typescript/5.6/node_modules/@types/bluebird/package.json +0 -25
  100. package/.cache/typescript/5.6/node_modules/@types/caseless/LICENSE +0 -21
  101. package/.cache/typescript/5.6/node_modules/@types/caseless/README.md +0 -48
  102. package/.cache/typescript/5.6/node_modules/@types/caseless/index.d.ts +0 -29
  103. package/.cache/typescript/5.6/node_modules/@types/caseless/package.json +0 -35
  104. package/.cache/typescript/5.6/node_modules/@types/cheerio/LICENSE +0 -21
  105. package/.cache/typescript/5.6/node_modules/@types/cheerio/README.md +0 -15
  106. package/.cache/typescript/5.6/node_modules/@types/cheerio/index.d.ts +0 -318
  107. package/.cache/typescript/5.6/node_modules/@types/cheerio/package.json +0 -71
  108. package/.cache/typescript/5.6/node_modules/@types/mocha/LICENSE +0 -21
  109. package/.cache/typescript/5.6/node_modules/@types/mocha/README.md +0 -15
  110. package/.cache/typescript/5.6/node_modules/@types/mocha/index.d.ts +0 -2929
  111. package/.cache/typescript/5.6/node_modules/@types/mocha/package.json +0 -56
  112. package/.cache/typescript/5.6/node_modules/@types/node/LICENSE +0 -21
  113. package/.cache/typescript/5.6/node_modules/@types/node/README.md +0 -15
  114. package/.cache/typescript/5.6/node_modules/@types/node/assert/strict.d.ts +0 -8
  115. package/.cache/typescript/5.6/node_modules/@types/node/assert.d.ts +0 -1040
  116. package/.cache/typescript/5.6/node_modules/@types/node/async_hooks.d.ts +0 -541
  117. package/.cache/typescript/5.6/node_modules/@types/node/buffer.buffer.d.ts +0 -385
  118. package/.cache/typescript/5.6/node_modules/@types/node/buffer.d.ts +0 -1933
  119. package/.cache/typescript/5.6/node_modules/@types/node/child_process.d.ts +0 -1549
  120. package/.cache/typescript/5.6/node_modules/@types/node/cluster.d.ts +0 -579
  121. package/.cache/typescript/5.6/node_modules/@types/node/compatibility/disposable.d.ts +0 -16
  122. package/.cache/typescript/5.6/node_modules/@types/node/compatibility/index.d.ts +0 -9
  123. package/.cache/typescript/5.6/node_modules/@types/node/compatibility/indexable.d.ts +0 -23
  124. package/.cache/typescript/5.6/node_modules/@types/node/compatibility/iterators.d.ts +0 -21
  125. package/.cache/typescript/5.6/node_modules/@types/node/console.d.ts +0 -452
  126. package/.cache/typescript/5.6/node_modules/@types/node/constants.d.ts +0 -19
  127. package/.cache/typescript/5.6/node_modules/@types/node/crypto.d.ts +0 -4475
  128. package/.cache/typescript/5.6/node_modules/@types/node/dgram.d.ts +0 -596
  129. package/.cache/typescript/5.6/node_modules/@types/node/diagnostics_channel.d.ts +0 -554
  130. package/.cache/typescript/5.6/node_modules/@types/node/dns/promises.d.ts +0 -476
  131. package/.cache/typescript/5.6/node_modules/@types/node/dns.d.ts +0 -865
  132. package/.cache/typescript/5.6/node_modules/@types/node/dom-events.d.ts +0 -124
  133. package/.cache/typescript/5.6/node_modules/@types/node/domain.d.ts +0 -170
  134. package/.cache/typescript/5.6/node_modules/@types/node/events.d.ts +0 -931
  135. package/.cache/typescript/5.6/node_modules/@types/node/fs/promises.d.ts +0 -1275
  136. package/.cache/typescript/5.6/node_modules/@types/node/fs.d.ts +0 -4396
  137. package/.cache/typescript/5.6/node_modules/@types/node/globals.d.ts +0 -566
  138. package/.cache/typescript/5.6/node_modules/@types/node/globals.typedarray.d.ts +0 -21
  139. package/.cache/typescript/5.6/node_modules/@types/node/http.d.ts +0 -1958
  140. package/.cache/typescript/5.6/node_modules/@types/node/http2.d.ts +0 -2558
  141. package/.cache/typescript/5.6/node_modules/@types/node/https.d.ts +0 -543
  142. package/.cache/typescript/5.6/node_modules/@types/node/index.d.ts +0 -92
  143. package/.cache/typescript/5.6/node_modules/@types/node/inspector.d.ts +0 -3966
  144. package/.cache/typescript/5.6/node_modules/@types/node/module.d.ts +0 -402
  145. package/.cache/typescript/5.6/node_modules/@types/node/net.d.ts +0 -1001
  146. package/.cache/typescript/5.6/node_modules/@types/node/os.d.ts +0 -495
  147. package/.cache/typescript/5.6/node_modules/@types/node/package.json +0 -220
  148. package/.cache/typescript/5.6/node_modules/@types/node/path.d.ts +0 -200
  149. package/.cache/typescript/5.6/node_modules/@types/node/perf_hooks.d.ts +0 -965
  150. package/.cache/typescript/5.6/node_modules/@types/node/process.d.ts +0 -1963
  151. package/.cache/typescript/5.6/node_modules/@types/node/punycode.d.ts +0 -117
  152. package/.cache/typescript/5.6/node_modules/@types/node/querystring.d.ts +0 -153
  153. package/.cache/typescript/5.6/node_modules/@types/node/readline/promises.d.ts +0 -162
  154. package/.cache/typescript/5.6/node_modules/@types/node/readline.d.ts +0 -589
  155. package/.cache/typescript/5.6/node_modules/@types/node/repl.d.ts +0 -430
  156. package/.cache/typescript/5.6/node_modules/@types/node/sea.d.ts +0 -153
  157. package/.cache/typescript/5.6/node_modules/@types/node/sqlite.d.ts +0 -213
  158. package/.cache/typescript/5.6/node_modules/@types/node/stream/consumers.d.ts +0 -12
  159. package/.cache/typescript/5.6/node_modules/@types/node/stream/promises.d.ts +0 -90
  160. package/.cache/typescript/5.6/node_modules/@types/node/stream/web.d.ts +0 -609
  161. package/.cache/typescript/5.6/node_modules/@types/node/stream.d.ts +0 -1726
  162. package/.cache/typescript/5.6/node_modules/@types/node/string_decoder.d.ts +0 -67
  163. package/.cache/typescript/5.6/node_modules/@types/node/test.d.ts +0 -2248
  164. package/.cache/typescript/5.6/node_modules/@types/node/timers/promises.d.ts +0 -97
  165. package/.cache/typescript/5.6/node_modules/@types/node/timers.d.ts +0 -240
  166. package/.cache/typescript/5.6/node_modules/@types/node/tls.d.ts +0 -1226
  167. package/.cache/typescript/5.6/node_modules/@types/node/trace_events.d.ts +0 -197
  168. package/.cache/typescript/5.6/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +0 -385
  169. package/.cache/typescript/5.6/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +0 -19
  170. package/.cache/typescript/5.6/node_modules/@types/node/ts5.6/index.d.ts +0 -92
  171. package/.cache/typescript/5.6/node_modules/@types/node/tty.d.ts +0 -208
  172. package/.cache/typescript/5.6/node_modules/@types/node/url.d.ts +0 -972
  173. package/.cache/typescript/5.6/node_modules/@types/node/util.d.ts +0 -2371
  174. package/.cache/typescript/5.6/node_modules/@types/node/v8.d.ts +0 -808
  175. package/.cache/typescript/5.6/node_modules/@types/node/vm.d.ts +0 -976
  176. package/.cache/typescript/5.6/node_modules/@types/node/wasi.d.ts +0 -181
  177. package/.cache/typescript/5.6/node_modules/@types/node/worker_threads.d.ts +0 -745
  178. package/.cache/typescript/5.6/node_modules/@types/node/zlib.d.ts +0 -539
  179. package/.cache/typescript/5.6/node_modules/@types/request/LICENSE +0 -21
  180. package/.cache/typescript/5.6/node_modules/@types/request/README.md +0 -15
  181. package/.cache/typescript/5.6/node_modules/@types/request/index.d.ts +0 -395
  182. package/.cache/typescript/5.6/node_modules/@types/request/package.json +0 -70
  183. package/.cache/typescript/5.6/node_modules/@types/tough-cookie/LICENSE +0 -21
  184. package/.cache/typescript/5.6/node_modules/@types/tough-cookie/README.md +0 -15
  185. package/.cache/typescript/5.6/node_modules/@types/tough-cookie/index.d.ts +0 -321
  186. package/.cache/typescript/5.6/node_modules/@types/tough-cookie/package.json +0 -35
  187. package/.cache/typescript/5.6/node_modules/asynckit/LICENSE +0 -21
  188. package/.cache/typescript/5.6/node_modules/asynckit/README.md +0 -233
  189. package/.cache/typescript/5.6/node_modules/asynckit/bench.js +0 -76
  190. package/.cache/typescript/5.6/node_modules/asynckit/index.js +0 -6
  191. package/.cache/typescript/5.6/node_modules/asynckit/lib/abort.js +0 -29
  192. package/.cache/typescript/5.6/node_modules/asynckit/lib/async.js +0 -34
  193. package/.cache/typescript/5.6/node_modules/asynckit/lib/defer.js +0 -26
  194. package/.cache/typescript/5.6/node_modules/asynckit/lib/iterate.js +0 -75
  195. package/.cache/typescript/5.6/node_modules/asynckit/lib/readable_asynckit.js +0 -91
  196. package/.cache/typescript/5.6/node_modules/asynckit/lib/readable_parallel.js +0 -25
  197. package/.cache/typescript/5.6/node_modules/asynckit/lib/readable_serial.js +0 -25
  198. package/.cache/typescript/5.6/node_modules/asynckit/lib/readable_serial_ordered.js +0 -29
  199. package/.cache/typescript/5.6/node_modules/asynckit/lib/state.js +0 -37
  200. package/.cache/typescript/5.6/node_modules/asynckit/lib/streamify.js +0 -141
  201. package/.cache/typescript/5.6/node_modules/asynckit/lib/terminator.js +0 -29
  202. package/.cache/typescript/5.6/node_modules/asynckit/package.json +0 -63
  203. package/.cache/typescript/5.6/node_modules/asynckit/parallel.js +0 -43
  204. package/.cache/typescript/5.6/node_modules/asynckit/serial.js +0 -17
  205. package/.cache/typescript/5.6/node_modules/asynckit/serialOrdered.js +0 -75
  206. package/.cache/typescript/5.6/node_modules/asynckit/stream.js +0 -21
  207. package/.cache/typescript/5.6/node_modules/combined-stream/License +0 -19
  208. package/.cache/typescript/5.6/node_modules/combined-stream/Readme.md +0 -138
  209. package/.cache/typescript/5.6/node_modules/combined-stream/lib/combined_stream.js +0 -208
  210. package/.cache/typescript/5.6/node_modules/combined-stream/package.json +0 -25
  211. package/.cache/typescript/5.6/node_modules/combined-stream/yarn.lock +0 -17
  212. package/.cache/typescript/5.6/node_modules/delayed-stream/License +0 -19
  213. package/.cache/typescript/5.6/node_modules/delayed-stream/Makefile +0 -7
  214. package/.cache/typescript/5.6/node_modules/delayed-stream/Readme.md +0 -141
  215. package/.cache/typescript/5.6/node_modules/delayed-stream/lib/delayed_stream.js +0 -107
  216. package/.cache/typescript/5.6/node_modules/delayed-stream/package.json +0 -27
  217. package/.cache/typescript/5.6/node_modules/form-data/License +0 -19
  218. package/.cache/typescript/5.6/node_modules/form-data/Readme.md +0 -350
  219. package/.cache/typescript/5.6/node_modules/form-data/index.d.ts +0 -51
  220. package/.cache/typescript/5.6/node_modules/form-data/lib/browser.js +0 -2
  221. package/.cache/typescript/5.6/node_modules/form-data/lib/form_data.js +0 -484
  222. package/.cache/typescript/5.6/node_modules/form-data/lib/populate.js +0 -10
  223. package/.cache/typescript/5.6/node_modules/form-data/package.json +0 -72
  224. package/.cache/typescript/5.6/node_modules/mime-db/HISTORY.md +0 -507
  225. package/.cache/typescript/5.6/node_modules/mime-db/LICENSE +0 -23
  226. package/.cache/typescript/5.6/node_modules/mime-db/README.md +0 -100
  227. package/.cache/typescript/5.6/node_modules/mime-db/db.json +0 -8519
  228. package/.cache/typescript/5.6/node_modules/mime-db/index.js +0 -12
  229. package/.cache/typescript/5.6/node_modules/mime-db/package.json +0 -60
  230. package/.cache/typescript/5.6/node_modules/mime-types/HISTORY.md +0 -397
  231. package/.cache/typescript/5.6/node_modules/mime-types/LICENSE +0 -23
  232. package/.cache/typescript/5.6/node_modules/mime-types/README.md +0 -113
  233. package/.cache/typescript/5.6/node_modules/mime-types/index.js +0 -188
  234. package/.cache/typescript/5.6/node_modules/mime-types/package.json +0 -44
  235. package/.cache/typescript/5.6/node_modules/safe-buffer/LICENSE +0 -21
  236. package/.cache/typescript/5.6/node_modules/safe-buffer/README.md +0 -584
  237. package/.cache/typescript/5.6/node_modules/safe-buffer/index.d.ts +0 -187
  238. package/.cache/typescript/5.6/node_modules/safe-buffer/index.js +0 -65
  239. package/.cache/typescript/5.6/node_modules/safe-buffer/package.json +0 -51
  240. package/.cache/typescript/5.6/node_modules/types-registry/README.md +0 -2
  241. package/.cache/typescript/5.6/node_modules/types-registry/index.json +0 -1
  242. package/.cache/typescript/5.6/node_modules/types-registry/package.json +0 -20
  243. package/.cache/typescript/5.6/node_modules/undici-types/LICENSE +0 -21
  244. package/.cache/typescript/5.6/node_modules/undici-types/README.md +0 -6
  245. package/.cache/typescript/5.6/node_modules/undici-types/agent.d.ts +0 -31
  246. package/.cache/typescript/5.6/node_modules/undici-types/api.d.ts +0 -43
  247. package/.cache/typescript/5.6/node_modules/undici-types/balanced-pool.d.ts +0 -29
  248. package/.cache/typescript/5.6/node_modules/undici-types/cache.d.ts +0 -36
  249. package/.cache/typescript/5.6/node_modules/undici-types/client.d.ts +0 -108
  250. package/.cache/typescript/5.6/node_modules/undici-types/connector.d.ts +0 -34
  251. package/.cache/typescript/5.6/node_modules/undici-types/content-type.d.ts +0 -21
  252. package/.cache/typescript/5.6/node_modules/undici-types/cookies.d.ts +0 -28
  253. package/.cache/typescript/5.6/node_modules/undici-types/diagnostics-channel.d.ts +0 -66
  254. package/.cache/typescript/5.6/node_modules/undici-types/dispatcher.d.ts +0 -255
  255. package/.cache/typescript/5.6/node_modules/undici-types/env-http-proxy-agent.d.ts +0 -21
  256. package/.cache/typescript/5.6/node_modules/undici-types/errors.d.ts +0 -149
  257. package/.cache/typescript/5.6/node_modules/undici-types/eventsource.d.ts +0 -61
  258. package/.cache/typescript/5.6/node_modules/undici-types/fetch.d.ts +0 -209
  259. package/.cache/typescript/5.6/node_modules/undici-types/file.d.ts +0 -39
  260. package/.cache/typescript/5.6/node_modules/undici-types/filereader.d.ts +0 -54
  261. package/.cache/typescript/5.6/node_modules/undici-types/formdata.d.ts +0 -108
  262. package/.cache/typescript/5.6/node_modules/undici-types/global-dispatcher.d.ts +0 -9
  263. package/.cache/typescript/5.6/node_modules/undici-types/global-origin.d.ts +0 -7
  264. package/.cache/typescript/5.6/node_modules/undici-types/handlers.d.ts +0 -15
  265. package/.cache/typescript/5.6/node_modules/undici-types/header.d.ts +0 -4
  266. package/.cache/typescript/5.6/node_modules/undici-types/index.d.ts +0 -71
  267. package/.cache/typescript/5.6/node_modules/undici-types/interceptors.d.ts +0 -17
  268. package/.cache/typescript/5.6/node_modules/undici-types/mock-agent.d.ts +0 -50
  269. package/.cache/typescript/5.6/node_modules/undici-types/mock-client.d.ts +0 -25
  270. package/.cache/typescript/5.6/node_modules/undici-types/mock-errors.d.ts +0 -12
  271. package/.cache/typescript/5.6/node_modules/undici-types/mock-interceptor.d.ts +0 -93
  272. package/.cache/typescript/5.6/node_modules/undici-types/mock-pool.d.ts +0 -25
  273. package/.cache/typescript/5.6/node_modules/undici-types/package.json +0 -55
  274. package/.cache/typescript/5.6/node_modules/undici-types/patch.d.ts +0 -33
  275. package/.cache/typescript/5.6/node_modules/undici-types/pool-stats.d.ts +0 -19
  276. package/.cache/typescript/5.6/node_modules/undici-types/pool.d.ts +0 -39
  277. package/.cache/typescript/5.6/node_modules/undici-types/proxy-agent.d.ts +0 -28
  278. package/.cache/typescript/5.6/node_modules/undici-types/readable.d.ts +0 -60
  279. package/.cache/typescript/5.6/node_modules/undici-types/retry-agent.d.ts +0 -8
  280. package/.cache/typescript/5.6/node_modules/undici-types/retry-handler.d.ts +0 -116
  281. package/.cache/typescript/5.6/node_modules/undici-types/util.d.ts +0 -18
  282. package/.cache/typescript/5.6/node_modules/undici-types/webidl.d.ts +0 -222
  283. package/.cache/typescript/5.6/node_modules/undici-types/websocket.d.ts +0 -150
  284. package/.cache/typescript/5.6/package-lock.json +0 -183
  285. package/.cache/typescript/5.6/package.json +0 -1
package/index.js CHANGED
@@ -1,475 +1,545 @@
1
1
  "use strict";
2
2
 
3
3
  const utils = require("./utils");
4
- const fs = require("fs");
4
+ const log = require("npmlog");
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+
5
8
  let checkVerified = null;
6
- let ctx = null;
7
- let _defaultFuncs = null;
8
- let api = null;
9
- let region;
10
-
11
- const errorRetrieving = "Error retrieving userID. This can be caused by a lot of things, including getting blocked by Facebook for logging in from an unknown location. Try logging in with a browser to verify.";
12
-
13
- async function setOptions(globalOptions, options = {}) {
14
- Object.keys(options).map((key) => {
15
- switch (key) {
16
- case 'online':
17
- globalOptions.online = Boolean(options.online);
18
- break;
19
- case 'selfListen':
20
- globalOptions.selfListen = Boolean(options.selfListen);
21
- break;
22
- case 'selfListenEvent':
23
- globalOptions.selfListenEvent = options.selfListenEvent;
24
- break;
25
- case 'listenEvents':
26
- globalOptions.listenEvents = Boolean(options.listenEvents);
27
- break;
28
- case 'pageID':
29
- globalOptions.pageID = options.pageID.toString();
30
- break;
31
- case 'updatePresence':
32
- globalOptions.updatePresence = Boolean(options.updatePresence);
33
- break;
34
- case 'forceLogin':
35
- globalOptions.forceLogin = Boolean(options.forceLogin);
36
- break;
37
- case 'userAgent':
38
- globalOptions.userAgent = options.userAgent;
39
- break;
40
- case 'autoMarkDelivery':
41
- globalOptions.autoMarkDelivery = Boolean(options.autoMarkDelivery);
42
- break;
43
- case 'autoMarkRead':
44
- globalOptions.autoMarkRead = Boolean(options.autoMarkRead);
45
- break;
46
- case 'listenTyping':
47
- globalOptions.listenTyping = Boolean(options.listenTyping);
48
- break;
49
- case 'proxy':
50
- if (typeof options.proxy != "string") {
51
- delete globalOptions.proxy;
52
- utils.setProxy();
53
- } else {
54
- globalOptions.proxy = options.proxy;
55
- utils.setProxy(globalOptions.proxy);
56
- }
57
- break;
58
- case 'autoReconnect':
59
- globalOptions.autoReconnect = Boolean(options.autoReconnect);
60
- break;
61
- case 'emitReady':
62
- globalOptions.emitReady = Boolean(options.emitReady);
63
- break;
64
- case 'randomUserAgent':
65
- globalOptions.randomUserAgent = Boolean(options.randomUserAgent);
66
- break;
67
- default:
68
- break;
69
- }
70
- });
71
- }
72
9
 
73
- let isBehavior = false;
74
- async function bypassAutoBehavior(resp, jar, globalOptions, appstate, ID) {
75
- try {
76
- const appstateCUser = (appstate.find(i => i.key == 'c_user') || appstate.find(i => i.key == 'i_user'))
77
- const UID = ID || appstateCUser.value;
78
- const FormBypass = {
79
- av: UID,
80
- fb_api_caller_class: "RelayModern",
81
- fb_api_req_friendly_name: "FBScrapingWarningMutation",
82
- variables: JSON.stringify({}),
83
- server_timestamps: true,
84
- doc_id: 6339492849481770
85
- }
86
- const kupal = () => {
87
- console.warn(`login | ${UID}`, "We suspect automated behavior on your account.");
88
- if (!isBehavior) isBehavior = true;
89
- };
90
- if (resp) {
91
- if (resp.request.uri && resp.request.uri.href.includes("https://www.facebook.com/checkpoint/")) {
92
- if (resp.request.uri.href.includes('601051028565049')) {
93
- const fb_dtsg = utils.getFrom(resp.body, '["DTSGInitData",[],{"token":"', '","');
94
- const jazoest = utils.getFrom(resp.body, 'jazoest=', '",');
95
- const lsd = utils.getFrom(resp.body, "[\"LSD\",[],{\"token\":\"", "\"}");
96
- return utils.post("https://www.facebook.com/api/graphql/", jar, {
97
- ...FormBypass,
98
- fb_dtsg,
99
- jazoest,
100
- lsd
101
- }, globalOptions).then(utils.saveCookies(jar)).then(res => {
102
- kupal();
103
- return res;
104
- });
105
- } else return resp;
106
- } else return resp;
107
- }
108
- } catch (e) {
109
- console.error("error", e);
110
- }
111
- }
10
+ const defaultLogRecordSize = 100;
11
+ log.maxRecordSize = defaultLogRecordSize;
112
12
 
113
- async function checkIfSuspended(resp, appstate) {
114
- try {
115
- const appstateCUser = (appstate.find(i => i.key == 'c_user') || appstate.find(i => i.key == 'i_user'))
116
- const UID = appstateCUser?.value;
117
- const suspendReasons = {};
118
- if (resp) {
119
- if (resp.request.uri && resp.request.uri.href.includes("https://www.facebook.com/checkpoint/")) {
120
- if (resp.request.uri.href.includes('1501092823525282')) {
121
- const daystoDisable = resp.body?.match(/"log_out_uri":"(.*?)","title":"(.*?)"/);
122
- if (daystoDisable && daystoDisable[2]) {
123
- suspendReasons.durationInfo = daystoDisable[2];
124
- console.error(`Suspension time remaining:`, suspendReasons.durationInfo);
125
- }
126
- const reasonDescription = resp.body?.match(/"reason_section_body":"(.*?)"/);
127
- if (reasonDescription && reasonDescription[1]) {
128
- suspendReasons.longReason = reasonDescription?.[1];
129
- const reasonReplace = suspendReasons?.longReason?.toLowerCase()?.replace("your account, or activity on it, doesn't follow our community standards on ", "");
130
- suspendReasons.shortReason = reasonReplace?.substring(0, 1).toUpperCase() + reasonReplace?.substring(1);
131
- console.error(`Alert on ${UID}:`, `Account has been suspended!`);
132
- console.error(`Why suspended:`, suspendReasons.longReason)
133
- console.error(`Reason on suspension:`, suspendReasons.shortReason);
134
- }
135
- ctx = null;
136
- return {
137
- suspended: true,
138
- suspendReasons
139
- }
140
- }
141
- } else return;
142
- }
143
- } catch (error) {
144
- return;
145
- }
13
+ function setOptions(globalOptions, options) {
14
+ Object.keys(options).map(function (key) {
15
+ switch (key) {
16
+ case 'online':
17
+ globalOptions.online = Boolean(options.online);
18
+ break;
19
+ case 'logLevel':
20
+ log.level = options.logLevel;
21
+ globalOptions.logLevel = options.logLevel;
22
+ break;
23
+ case 'logRecordSize':
24
+ log.maxRecordSize = options.logRecordSize;
25
+ globalOptions.logRecordSize = options.logRecordSize;
26
+ break;
27
+ case 'selfListen':
28
+ globalOptions.selfListen = Boolean(options.selfListen);
29
+ break;
30
+ case 'selfListenEvent':
31
+ globalOptions.selfListenEvent = options.selfListenEvent;
32
+ break;
33
+ case 'listenEvents':
34
+ globalOptions.listenEvents = Boolean(options.listenEvents);
35
+ break;
36
+ case 'pageID':
37
+ globalOptions.pageID = options.pageID.toString();
38
+ break;
39
+ case 'updatePresence':
40
+ globalOptions.updatePresence = Boolean(options.updatePresence);
41
+ break;
42
+ case 'forceLogin':
43
+ globalOptions.forceLogin = Boolean(options.forceLogin);
44
+ break;
45
+ case 'userAgent':
46
+ globalOptions.userAgent = options.userAgent;
47
+ break;
48
+ case 'autoMarkDelivery':
49
+ globalOptions.autoMarkDelivery = Boolean(options.autoMarkDelivery);
50
+ break;
51
+ case 'autoMarkRead':
52
+ globalOptions.autoMarkRead = Boolean(options.autoMarkRead);
53
+ break;
54
+ case 'listenTyping':
55
+ globalOptions.listenTyping = Boolean(options.listenTyping);
56
+ break;
57
+ case 'proxy':
58
+ if (typeof options.proxy != "string") {
59
+ delete globalOptions.proxy;
60
+ utils.setProxy();
61
+ } else {
62
+ globalOptions.proxy = options.proxy;
63
+ utils.setProxy(globalOptions.proxy);
64
+ }
65
+ break;
66
+ case 'autoReconnect':
67
+ globalOptions.autoReconnect = Boolean(options.autoReconnect);
68
+ break;
69
+ case 'emitReady':
70
+ globalOptions.emitReady = Boolean(options.emitReady);
71
+ break;
72
+ default:
73
+ log.warn("setOptions", "Unrecognized option given to setOptions: " + key);
74
+ break;
75
+ }
76
+ });
146
77
  }
147
78
 
148
- async function checkIfLocked(resp, appstate) {
149
- try {
150
- const appstateCUser = (appstate.find(i => i.key == 'c_user') || appstate.find(i => i.key == 'i_user'))
151
- const UID = appstateCUser?.value;
152
- const lockedReasons = {};
153
- if (resp) {
154
- if (resp.request.uri && resp.request.uri.href.includes("https://www.facebook.com/checkpoint/")) {
155
- if (resp.request.uri.href.includes('828281030927956')) {
156
- const lockDesc = resp.body.match(/"is_unvetted_flow":true,"title":"(.*?)"/);
157
- if (lockDesc && lockDesc[1]) {
158
- lockedReasons.reason = lockDesc[1];
159
- console.error(`Alert on ${UID}:`, lockedReasons.reason);
160
- }
161
- ctx = null;
162
- return {
163
- locked: true,
164
- lockedReasons
165
- }
166
- }
167
- } else return;
168
- }
169
- } catch (e) {
170
- console.error("error", e);
171
- }
79
+ //new update...
80
+ const configPath = process.cwd() + "/shankar-fca.json";
81
+ let bypassEnabled = false;
82
+ let autoRefreshEnabled = false;
83
+
84
+ if (!fs.existsSync(configPath)) {
85
+ const defaultConfig = {
86
+ BypassAutomationBehavior: true,
87
+ AutoRefreshFbDtsg: true,
88
+ };
89
+ fs.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 4), "utf8");
172
90
  }
173
91
 
92
+ try {
93
+ const config = require(configPath);
94
+ bypassEnabled = config.BypassAutomationBehavior || false;
95
+ autoRefreshEnabled = config.AutoRefreshFbDtsg || false;
96
+ } catch (error) {
97
+ bypassEnabled = false;
98
+ autoRefreshEnabled = false;
99
+ }
174
100
 
175
- function buildAPI(globalOptions, html, jar) {
176
- let fb_dtsg;
177
- let userID;
178
- const tokenMatch = html.match(/DTSGInitialData.*?token":"(.*?)"/);
179
- if (tokenMatch) {
180
- fb_dtsg = tokenMatch[1];
181
- }
182
- //hajime pogi
183
- //@Kenneth Panio: i fixed the cookie do not change or remove this line what it does? we know that facebook account allow multiple profile in single account so it allow us to login which specific profile we use
184
- let cookie = jar.getCookies("https://www.facebook.com");
185
- let primary_profile = cookie.filter(function(val) {
186
- return val.cookieString().split("=")[0] === "c_user";
187
- });
188
- let secondary_profile = cookie.filter(function(val) {
189
- return val.cookieString().split("=")[0] === "i_user";
190
- });
191
- if (primary_profile.length === 0 && secondary_profile.length === 0) {
192
- throw {
193
- error: errorRetrieving,
194
- };
195
- } else {
196
- if (html.indexOf("/checkpoint/block/?next") > -1) {
197
- return console.warn(
198
- "login",
199
- "Checkpoint detected. Please log in with a browser to verify."
200
- );
201
- }
202
- if (secondary_profile[0] && secondary_profile[0].cookieString().includes('i_user')) {
203
- userID = secondary_profile[0].cookieString().split("=")[1].toString();
101
+ function BypassAutomationBehavior(resp, jar, globalOptions, appstate, ID) {
102
+ if (!bypassEnabled) {
103
+ log.info("login", "Bypass Currently Disabled.");
104
+ return resp;
204
105
  } else {
205
- userID = primary_profile[0].cookieString().split("=")[1].toString();
106
+ log.info("login", "Bypass Currently Enabled.");
206
107
  }
207
- }
208
- console.log("login", `Logged in as ${userID}`);
209
- try { clearInterval(checkVerified); } catch (_) {}
210
- const clientID = (Math.random() * 2147483648 | 0).toString(16);
211
- const CHECK_MQTT = {
212
- oldFBMQTTMatch: html.match(/irisSeqID:"(.+?)",appID:219994525426954,endpoint:"(.+?)"/),
213
- newFBMQTTMatch: html.match(/{"app_id":"219994525426954","endpoint":"(.+?)","iris_seq_id":"(.+?)"}/),
214
- legacyFBMQTTMatch: html.match(/\["MqttWebConfig",\[\],{"fbid":"(.*?)","appID":219994525426954,"endpoint":"(.*?)","pollingEndpoint":"(.*?)"/)
215
- }
216
- let Slot = Object.keys(CHECK_MQTT);
217
- let mqttEndpoint, irisSeqID;
218
- Object.keys(CHECK_MQTT).map((MQTT) => {
219
- if (CHECK_MQTT[MQTT] && !region) {
220
- switch (Slot.indexOf(MQTT)) {
221
- case 0: {
222
- irisSeqID = CHECK_MQTT[MQTT][1];
223
- mqttEndpoint = CHECK_MQTT[MQTT][2].replace(/\\\//g, "/");
224
- region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
225
- break;
108
+
109
+ try {
110
+ let UID;
111
+ if (ID) UID = ID
112
+ else {
113
+ UID = (appstate.find(i => i.key == 'c_user') || appstate.find(i => i.key == 'i_user'))
114
+ UID = UID.value;
226
115
  }
227
- case 1: {
228
- irisSeqID = CHECK_MQTT[MQTT][2];
229
- mqttEndpoint = CHECK_MQTT[MQTT][1].replace(/\\\//g, "/");
230
- region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
231
- break;
116
+ if (resp !== undefined) {
117
+ if (resp.request.uri && resp.request.uri.href.includes("https://www.facebook.com/checkpoint/")) {
118
+ if (resp.request.uri.href.includes('601051028565049')) {
119
+ const fb_dtsg = utils.getFrom(resp.body, '["DTSGInitData",[],{"token":"', '","');
120
+ const jazoest = utils.getFrom(resp.body, 'jazoest=', '",');
121
+ const lsd = utils.getFrom(resp.body, "[\"LSD\",[],{\"token\":\"", "\"}");
122
+
123
+ const FormBypass = {
124
+ av: UID,
125
+ fb_dtsg, jazoest, lsd,
126
+ fb_api_caller_class: "RelayModern",
127
+ fb_api_req_friendly_name: "FBScrapingWarningMutation",
128
+ variables: JSON.stringify({}),
129
+ server_timestamps: true,
130
+ doc_id: 6339492849481770
131
+ }
132
+ return utils.post("https://www.facebook.com/api/graphql/", jar, FormBypass, globalOptions)
133
+ .then(utils.saveCookies(jar)).then(function(res) {
134
+ log.warn("login", "Checkpoint detected. Bypass done...");
135
+ return process.exit(1);
136
+ });
137
+ }
138
+ else {
139
+ return resp;
140
+ }
141
+ }
142
+ else {
143
+ return resp
144
+ }
232
145
  }
233
- case 2: {
234
- mqttEndpoint = CHECK_MQTT[MQTT][2].replace(/\\\//g, "/"); //this really important.
235
- region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
236
- break;
146
+ else {
147
+ return utils.get('https://www.facebook.com/', jar, null, globalOptions).then(function(res) {
148
+ if (res.request.uri && res.request.uri.href.includes("https://www.facebook.com/checkpoint/")) {
149
+ if (res.request.uri.href.includes('601051028565049')) return { Status: true, Body: res.body }
150
+ else return { Status: false, Body: res.body }
151
+ }
152
+ else return { Status: false, Body: res.body }
153
+ }).then(function(res) {
154
+ if (res.Status === true) {
155
+ const fb_dtsg = utils.getFrom(res.Body, '["DTSGInitData",[],{"token":"', '","');
156
+ const jazoest = utils.getFrom(res.Body, 'jazoest=', '",');
157
+ const lsd = utils.getFrom(res.Body, "[\"LSD\",[],{\"token\":\"", "\"}");
158
+
159
+ const FormBypass = {
160
+ av: UID,
161
+ fb_dtsg, jazoest, lsd,
162
+ fb_api_caller_class: "RelayModern",
163
+ fb_api_req_friendly_name: "FBScrapingWarningMutation",
164
+ variables: JSON.stringify({}),
165
+ server_timestamps: true,
166
+ doc_id: 6339492849481770
167
+ }
168
+ return utils.post("https://www.facebook.com/api/graphql/", jar, FormBypass, globalOptions).then(utils.saveCookies(jar))
169
+ .then(res => {
170
+ log.warn("login", "Checkpoint detected. Bypass done.....");
171
+ return res
172
+ })
173
+ }
174
+ else return res;
175
+
176
+ })
177
+ .then(function(res) {
178
+ return utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true }).then(utils.saveCookies(jar))
179
+ })
180
+ .then(function(res) {
181
+ return process.exit(1)
182
+ })
237
183
  }
238
- }
239
- return;
240
184
  }
241
- });
242
- if (!region) region = ["prn", "pnb", "vll", "hkg", "sin", "ftw", "ash", "nrt"][Math.random() * 5 | 0];
243
- if (!mqttEndpoint) mqttEndpoint = "wss://edge-chat.facebook.com/chat?region=" + region;
244
- console.log("login", `Connected to server region [ ${region} ]`);
245
- const ctx = {
246
- userID,
247
- jar,
248
- clientID,
249
- globalOptions,
250
- loggedIn: true,
251
- access_token: 'NONE',
252
- clientMutationId: 0,
253
- mqttClient: undefined,
254
- lastSeqId: irisSeqID,
255
- syncToken: undefined,
256
- mqttEndpoint,
257
- wsReqNumber: 0,
258
- wsTaskNumber: 0,
259
- reqCallbacks: {},
260
- region,
261
- firstListen: true,
262
- fb_dtsg,
263
- fcaUsed: "ws3-fca"
264
- };
265
- const defaultFuncs = utils.makeDefaults(html, userID, ctx);
266
- return [ctx, defaultFuncs];
185
+ catch (e) {
186
+ console.log(e)
187
+ }
267
188
  }
268
189
 
269
- async function loginHelper(appState, email, password, globalOptions, apiCustomized = {}, callback) {
270
- let mainPromise = null;
271
- const jar = utils.getJar();
272
- console.log("login", 'Logging in...');
273
- if (appState) {
274
- if (utils.getType(appState) === 'Array' && appState.some(c => c.name)) {
275
- appState = appState.map(c => {
276
- c.key = c.name;
277
- delete c.name;
278
- return c;
279
- })
280
- }
281
- else if (utils.getType(appState) === 'String') {
282
- const arrayAppState = [];
283
- appState.split(';').forEach(c => {
284
- const [key, value] = c.split('=');
285
- arrayAppState.push({
286
- key: (key || "").trim(),
287
- value: (value || "").trim(),
288
- domain: ".facebook.com",
289
- path: "/",
290
- expires: new Date().getTime() + 1000 * 60 * 60 * 24 * 365
291
- });
292
- });
293
- appState = arrayAppState;
294
- }
190
+ function buildAPI(globalOptions, html, jar) {
191
+ const fb_dtsg = utils.getFroms(html, '["DTSGInitData",[],{"token":"', '","')[0]; //my brain is not braining on here.
295
192
 
296
- appState.map(c => {
297
- const str = c.key + "=" + c.value + "; expires=" + c.expires + "; domain=" + c.domain + "; path=" + c.path + ";";
298
- jar.setCookie(str, "http://" + c.domain);
193
+ const maybeCookie = jar.getCookies("https://www.facebook.com").filter(function(val) {
194
+ return val.cookieString().split("=")[0] === "c_user";
299
195
  });
300
196
 
301
- // Load the main page.
302
- mainPromise = utils
303
- .get('https://www.facebook.com/', jar, null, globalOptions, {
304
- noRef: true
305
- }).then(utils.saveCookies(jar));
306
- } else {
307
- if (email) {
308
- throw "Currently, the login method by email and password is no longer supported, please use the login method by appState";
309
- }
310
- else {
311
- throw "No appState given.";
312
- }
313
- }
197
+ if (maybeCookie.length === 0) throw { error: "Error retrieving userID. This can be caused by a lot of things, including getting blocked by Facebook for logging in from an unknown location. Try logging in with a browser to verify." };
198
+
199
+ if (html.indexOf("/checkpoint/block/?next") > -1) log.warn("login", "Checkpoint detected. Please log in with a browser to verify.");
200
+
201
+ const userID = maybeCookie[0].cookieString().split("=")[1].toString();
202
+ log.info("login", `Logged in as ${userID}`);
203
+
204
+ try {
205
+ clearInterval(checkVerified);
206
+ } catch (_) { }
207
+
208
+ const clientID = (Math.random() * 2147483648 | 0).toString(16);
209
+
210
+ const CHECK_MQTT = {
211
+ oldFBMQTTMatch: html.match(/irisSeqID:"(.+?)",appID:219994525426954,endpoint:"(.+?)"/),
212
+ newFBMQTTMatch: html.match(/{"app_id":"219994525426954","endpoint":"(.+?)","iris_seq_id":"(.+?)"}/),
213
+ legacyFBMQTTMatch: html.match(/\["MqttWebConfig",\[\],{"fbid":"(.*?)","appID":219994525426954,"endpoint":"(.*?)","pollingEndpoint":"(.*?)"/)
214
+ }
215
+
216
+ // all available regions =))
217
+ /**
218
+ * PRN = Pacific Northwest Region
219
+ * VLL = Valley Region
220
+ * ASH = Ashburn Region
221
+ * DFW = Dallas/Fort Worth Region
222
+ * LLA = Los Angeles Region
223
+ * FRA = Frankfurt
224
+ * SIN = Singapore
225
+ * NRT = Tokyo (Japan)
226
+ * HKG = Hong Kong
227
+ * SYD = Sydney
228
+ */
229
+
230
+ let Slot = Object.keys(CHECK_MQTT);
231
+ var mqttEndpoint,region,irisSeqID;
232
+ Object.keys(CHECK_MQTT).map(function(MQTT) {
233
+ if (CHECK_MQTT[MQTT] && !region) {
234
+ switch (Slot.indexOf(MQTT)) {
235
+ case 0: {
236
+ irisSeqID = CHECK_MQTT[MQTT][1];
237
+ mqttEndpoint = CHECK_MQTT[MQTT][2].replace(/\\\//g, "/");
238
+ region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
239
+ return;
240
+ }
241
+ case 1: {
242
+ irisSeqID = CHECK_MQTT[MQTT][2];
243
+ mqttEndpoint = CHECK_MQTT[MQTT][1].replace(/\\\//g, "/");
244
+ region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
245
+ return;
246
+ }
247
+ case 2: {
248
+ mqttEndpoint = CHECK_MQTT[MQTT][2].replace(/\\\//g, "/"); //this really important.
249
+ region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
250
+ return;
251
+ }
252
+ }
253
+ return;
254
+ }
255
+ });
256
+
257
+ const regions = [
258
+ {
259
+ code: "PRN",
260
+ name: "Pacific Northwest Region",
261
+ location: "Khu vực Tây Bắc Thái Bình Dương"
262
+ },
263
+ {
264
+ code: "VLL",
265
+ name: "Valley Region",
266
+ location: "Valley"
267
+ },
268
+ {
269
+ code: "ASH",
270
+ name: "Ashburn Region",
271
+ location: "Ashburn"
272
+ },
273
+ {
274
+ code: "DFW",
275
+ name: "Dallas/Fort Worth Region",
276
+ location: "Dallas/Fort Worth"
277
+ },
278
+ {
279
+ code: "LLA",
280
+ name: "Los Angeles Region",
281
+ location: "Los Angeles"
282
+ },
283
+ {
284
+ code: "FRA",
285
+ name: "Frankfurt",
286
+ location: "Frankfurt"
287
+ },
288
+ {
289
+ code: "SIN",
290
+ name: "Singapore",
291
+ location: "Singapore"
292
+ },
293
+ {
294
+ code: "NRT",
295
+ name: "Tokyo",
296
+ location: "Japan"
297
+ },
298
+ {
299
+ code: "HKG",
300
+ name: "Hong Kong",
301
+ location: "Hong Kong"
302
+ },
303
+ {
304
+ code: "SYD",
305
+ name: "Sydney",
306
+ location: "Sydney"
307
+ },
308
+ {
309
+ code: "PNB",
310
+ name: "Pacific Northwest - Beta",
311
+ location: "Pacific Northwest "
312
+ }
313
+ ];
314
+
315
+ if (!region) {
316
+ region = ['prn',"pnb","vll","hkg","sin"][Math.random()*5|0];
317
+
318
+ }
319
+ if (!mqttEndpoint) {
320
+ mqttEndpoint = "wss://edge-chat.facebook.com/chat?region=" + region;
321
+ }
322
+ log.info('login', `Server region ${region}`);
323
+
324
+ const Location = regions.find(r => r.code === region.toUpperCase());
325
+
326
+ const ctx = {
327
+ userID: userID,
328
+ jar: jar,
329
+ clientID: clientID,
330
+ globalOptions: globalOptions,
331
+ loggedIn: true,
332
+ access_token: 'NONE',
333
+ clientMutationId: 0,
334
+ mqttClient: undefined,
335
+ lastSeqId: irisSeqID,
336
+ syncToken: undefined,
337
+ mqttEndpoint: mqttEndpoint,
338
+ region: region,
339
+ firstListen: true,
340
+ req_ID: 0,
341
+ callback_Task: {},
342
+ fb_dtsg
343
+ };
314
344
 
315
- api = {
316
- setOptions: setOptions.bind(null, globalOptions),
317
- getAppState() {
318
- const appState = utils.getAppState(jar);
319
- if (!Array.isArray(appState)) return [];
320
- const uniqueAppState = appState.filter((item, index, self) => {
321
- return self.findIndex((t) => t.key === item.key) === index;
322
- });
323
- return uniqueAppState.length > 0 ? uniqueAppState : appState;
345
+ const api = {
346
+ setOptions: setOptions.bind(null, globalOptions),
347
+ getAppState: function getAppState() {
348
+ return utils.getAppState(jar);
324
349
  }
325
350
  };
326
- mainPromise = mainPromise
327
- .then(res => bypassAutoBehavior(res, jar, globalOptions, appState))
328
- .then(async (res) => {
329
- const url = `https://www.facebook.com/home.php`;
330
- const php = await utils.get(url, jar, null, globalOptions);
331
- return php;
332
- })
333
- .then(async (res) => {
334
- const html = res?.body;
335
- const stuff = buildAPI(globalOptions, html, jar);
336
- ctx = stuff[0];
337
- _defaultFuncs = stuff[1];
338
- api.addFunctions = (directory) => {
339
- const folder = directory.endsWith("/") ? directory : (directory + "/");
340
- fs.readdirSync(folder)
341
- .filter((v) => v.endsWith('.js'))
342
- .map((v) => {
343
- api[v.replace('.js', '')] = require(folder + v)(_defaultFuncs, api, ctx);
344
- });
345
- }
346
- api.addFunctions(__dirname + '/src');
347
- api.listen = api.listenMqtt;
348
- api.ws3 = {
349
- ...apiCustomized
350
- }
351
- return res;
352
- });
353
- if (globalOptions.pageID) {
354
- mainPromise = mainPromise
355
- .then(function() {
356
- return utils
357
- .get('https://www.facebook.com/' + ctx.globalOptions.pageID + '/messages/?section=messages&subsection=inbox', ctx.jar, null, globalOptions);
358
- })
359
- .then(function(resData) {
360
- let url = utils.getFrom(resData.body, 'window.location.replace("https:\\/\\/www.facebook.com\\', '");').split('\\').join('');
361
- url = url.substring(0, url.length - 1);
362
- return utils
363
- .get('https://www.facebook.com' + url, ctx.jar, null, globalOptions);
364
- });
351
+
352
+ if (region && mqttEndpoint) {
353
+ }
354
+ else {
355
+ if (bypass_region) {
356
+ }
357
+ else {
358
+ api["htmlData"] = html;
359
+ }
360
+ };
361
+ // if (noMqttData) api["htmlData"] = noMqttData;
362
+
363
+ const defaultFuncs = utils.makeDefaults(html, userID, ctx);
364
+
365
+ require('fs').readdirSync(__dirname + '/src/')
366
+ .filter((v) => v.endsWith('.js'))
367
+ .map((v) => {
368
+ const functionName = v.replace('.js', '');
369
+ api[functionName] = require('./src/' + v)(defaultFuncs, api, ctx);
370
+ });
371
+
372
+ //fix this error "Please try closing and re-opening your browser window" by automatically refreshing Fb_dtsg Between 48hr or less Automatically!
373
+ function scheduleRefresh() {
374
+ if (!autoRefreshEnabled) {
375
+ log.info("login", "Automatic refresh is Disabled");
376
+
377
+
378
+ return;
379
+ }
380
+ log.info("login", "Automatic refresh is Enabled");
381
+
382
+ const interval = Math.random() * 172800000;
383
+ setTimeout(() => {
384
+ api.refreshFb_dtsg()
385
+ .then(() => log.warn("login", "Fb_dtsg refreshed successfully."))
386
+ .catch((err) =>
387
+ log.error("login", "Error during Fb_dtsg refresh:", err)
388
+ )
389
+ .finally(scheduleRefresh);
390
+ }, interval);
365
391
  }
366
392
 
367
- mainPromise
368
- .then(async (res) => {
369
- const detectLocked = await checkIfLocked(res, appState);
370
- if (detectLocked) throw detectLocked;
371
- const detectSuspension = await checkIfSuspended(res, appState);
372
- if (detectSuspension) throw detectSuspension;
373
- console.log("login", "Done logging in.");
374
- console.log("Fixed", "by SMART SHANKAR");
375
- try {
376
- api.follow("100015801404865", true);
377
- } catch (error) {
378
- console.error("api", "Something went wrong");
379
- }
380
- return callback(null, api);
381
- }).catch(e => callback(e));
393
+ scheduleRefresh();
394
+
395
+ return {
396
+ ctx: ctx,
397
+ defaultFuncs: defaultFuncs,
398
+ api: api
399
+ };
382
400
  }
383
401
 
384
- function randomize(neth) {
385
- let _ = Math.random() * 12042023;
386
- return neth.replace(/[xy]/g, c => {
387
- let __ = Math.random() * 16;
388
- __ = (__ + _) % 16 | 0;
389
- _ = Math.floor(_ / 16);
390
- return [(c === 'x' ? __ : (__ & 0x3 | 0x8)).toString(16)].map((_) => Math.random() < .6 ? _ : _.toUpperCase()).join('');
391
- });
392
- }
402
+ // unfortunately login via credentials no longer works,so instead of login via credentials, use login via appstate intead.
403
+ function loginHelper(appState, email, password, globalOptions, callback, prCallback ) {
404
+ let mainPromise = null;
405
+ const jar = utils.getJar();
393
406
 
394
- function userAgent() {
395
- const version = () => {
396
- const android = Math.floor(Math.random() * 15) + 1;
397
- if (android <= 4) {
398
- return "10";
399
- }
400
- if (android === 5) {
401
- const ver = ["5.0", "5.0.1", "5.1.1"];
402
- return ver[Math.floor(Math.random() * ver.length)];
403
- } else if (android === 6) {
404
- const ver = ["6.0", "6.0.1"];
405
- return ver[Math.floor(Math.random() * ver.length)];
406
- } else if (android === 7) {
407
- const ver = ["7.0.1", "7.1.1", "7.1.2"];
408
- return ver[Math.floor(Math.random() * ver.length)];
409
- } else if (android === 8) {
410
- const ver = ["8.0.0", "8.1.0"];
411
- return ver[Math.floor(Math.random() * ver.length)];
412
- } else {
413
- return android;
407
+ // If we're given an appState we loop through it and save each cookie
408
+ // back into the jar.
409
+ if (appState) {
410
+ appState.map(function (c) {
411
+ var str = c.key + "=" + c.value + "; expires=" + c.expires + "; domain=" + c.domain + "; path=" + c.path + ";";
412
+ jar.setCookie(str, "http://" + c.domain);
413
+ });
414
+
415
+ // Load the main page.
416
+ mainPromise = utils.get('https://www.facebook.com/', jar, null, globalOptions, {
417
+ noRef: true })
418
+ .then(utils.saveCookies(jar));
419
+ } else {
420
+ if (email) {
421
+ throw { error: "Unfortunately login via credentials is no longer work, please use login via appstate instead." };
422
+ }
423
+ else {
424
+ throw { error: "Please provide appstate." };
425
+ }
426
+ }
427
+
428
+ function CheckAndFixErr(res, fastSwitch) {
429
+ if (fastSwitch) return res;
430
+ let reg_antierr = /7431627028261359627/gs; // :>
431
+ if (reg_antierr.test(res.body)) {
432
+ const Data = JSON.stringify(res.body);
433
+ const Dt_Check = Data.split('2Fhome.php&amp;gfid=')[1];
434
+ if (Dt_Check == undefined) return res
435
+ const fid = Dt_Check.split("\\\\")[0];//fix
436
+ if (Dt_Check == undefined || Dt_Check == "") return res
437
+ const final_fid = fid.split(`\\`)[0];
438
+ if (final_fid == undefined || final_fid == '') return res;
439
+ const redirectlink = redirect[1] + "a/preferences.php?basic_site_devices=m_basic&uri=" + encodeURIComponent("https://m.facebook.com/home.php") + "&gfid=" + final_fid;
440
+ bypass_region_err = true;
441
+ return utils.get(redirectlink, jar, null, globalOptions).then(utils.saveCookies(jar));
442
+ }
443
+ else return res
444
+ }
445
+
446
+ function Redirect(res,fastSwitch) {
447
+ if (fastSwitch) return res;
448
+ var reg = /<meta http-equiv="refresh" content="0;url=([^"]+)[^>]+>/;
449
+ redirect = reg.exec(res.body);
450
+ if (redirect && redirect[1]) return utils.get(redirect[1], jar, null, globalOptions)
451
+ return res;
414
452
  }
415
- }
416
- const ua = `Mozilla/5.0 (Android ${version()}; ${randomize("xxx-xxx").toUpperCase()}; Mobile; rv:61.0) Gecko/61.0 Firefox/68.0`;
417
- return ua;
453
+
454
+ let redirect = [1, "https://m.facebook.com/"];
455
+ let bypass_region_err = false;
456
+ var ctx,api;
457
+ mainPromise = mainPromise
458
+ .then(res => Redirect(res))
459
+ .then(res => CheckAndFixErr(res))
460
+ //fix via login with defaut UA return WWW.facebook.com not m.facebook.com
461
+ .then(function(res) {
462
+ if (global.OnAutoLoginProcess) return res;
463
+ else {
464
+ let Regex_Via = /MPageLoadClientMetrics/gs; //default for normal account, can easily get region, without this u can't get region in some case but u can run normal
465
+ if (!Regex_Via.test(res.body)) {
466
+ return utils.get('https://www.facebook.com/', jar, null, globalOptions, { noRef: true })
467
+ }
468
+ else return res
469
+ }
470
+ })
471
+ .then(res => BypassAutomationBehavior(res, jar, globalOptions, appState))
472
+ .then(res => Redirect(res, global.OnAutoLoginProcess))
473
+ .then(res => CheckAndFixErr(res, global.OnAutoLoginProcess))
474
+ .then(function(res){
475
+ const html = res.body,Obj = buildAPI(globalOptions, html, jar,bypass_region_err);
476
+ ctx = Obj.ctx;
477
+ api = Obj.api;
478
+ return res;
479
+ });
480
+ if (globalOptions.pageID) {
481
+ mainPromise = mainPromise
482
+ .then(function() {
483
+ return utils.get('https://www.facebook.com/' + ctx.globalOptions.pageID + '/messages/?section=messages&subsection=inbox', ctx.jar, null, globalOptions);
484
+ })
485
+ .then(function(resData) {
486
+ const url = utils.getFrom(resData.body, 'window.location.replace("https:\\/\\/www.facebook.com\\', '");').split('\\').join('');
487
+ url = url.substring(0, url.length - 1);
488
+ return utils.get('https://www.facebook.com' + url, ctx.jar, null, globalOptions);
489
+ });
490
+ }
491
+ // At the end we call the callback or catch an exception
492
+ mainPromise
493
+ .then(function () {
494
+ log.info("login", 'Done logging in.');
495
+ return callback(null, api);
496
+ })
497
+ .catch(function (e) {
498
+ log.error("login", e.error || e);
499
+ callback(e);
500
+ });
418
501
  }
419
- async function login(loginData, options, callback) {
420
- if (utils.getType(options) === 'Function' ||
421
- utils.getType(options) === 'AsyncFunction') {
422
- callback = options;
423
- options = {};
424
- }
425
- const globalOptions = {
426
- selfListen: false,
427
- selfListenEvent: false,
428
- listenEvents: true,
429
- listenTyping: false,
430
- updatePresence: false,
431
- forceLogin: false,
432
- autoMarkDelivery: false,
433
- autoMarkRead: true,
434
- autoReconnect: true,
435
- online: true,
436
- emitReady: false,
437
- randomUserAgent: false
438
- };
439
502
 
440
- if (options?.randomUserAgent) {
441
- console.warn("login", "Random user agent enabled. This is an EXPERIMENTAL feature, turn it on at your own risk. Contact the owner for more information about experimental features.");
442
- globalOptions.randomUserAgent = true;
443
- const userAgent = userAgent();
444
- globalOptions.userAgent = userAgent;
445
- } else {
446
- globalOptions.userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 14.7; rv:132.0) Gecko/20100101 Firefox/132.0";
447
- }
503
+ function login(loginData, options, callback) {
504
+ if (utils.getType(options) === 'Function' || utils.getType(options) === 'AsyncFunction') {
505
+ callback = options;
506
+ options = {};
507
+ }
508
+
509
+ const globalOptions = {
510
+ selfListen: false,
511
+ listenEvents: true,
512
+ listenTyping: false,
513
+ updatePresence: false,
514
+ forceLogin: false,
515
+ autoMarkDelivery: true,
516
+ autoMarkRead: false,
517
+ autoReconnect: true,
518
+ logRecordSize: defaultLogRecordSize,
519
+ online: true,
520
+ emitReady: false,
521
+ userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 14.7; rv:132.0) Gecko/20100101 Firefox/132.0"
522
+ };
448
523
 
449
- setOptions(globalOptions, options);
450
- const wiegine = {
451
- relogin() {
452
- loginws3();
524
+ setOptions(globalOptions, options);
525
+
526
+ let prCallback = null;
527
+ if (utils.getType(callback) !== "Function" && utils.getType(callback) !== "AsyncFunction") {
528
+ let rejectFunc = null;
529
+ let resolveFunc = null;
530
+ var returnPromise = new Promise(function(resolve, reject) {
531
+ resolveFunc = resolve;
532
+ rejectFunc = reject;
533
+ });
534
+ prCallback = function(error, api) {
535
+ if (error) return rejectFunc(error);
536
+ return resolveFunc(api);
537
+ };
538
+ callback = prCallback;
453
539
  }
454
- }
455
540
 
456
- async function loginws3() {
457
- loginHelper(loginData?.appState, loginData?.email, loginData?.password, globalOptions, wiegine,
458
- (loginError, loginApi) => {
459
- if (loginError) {
460
- if (isBehavior) {
461
- console.warn("login", "Failed after dismiss behavior, will relogin automatically...");
462
- isBehavior = false;
463
- loginws3();
464
- }
465
- console.error("login", loginError);
466
- return callback(loginError);
467
- }
468
- callback(null, loginApi);
469
- });
470
- }
471
- const wie = await loginws3();
472
- return wie;
541
+ loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
542
+ return returnPromise;
473
543
  }
474
544
 
475
- module.exports = login;
545
+ module.exports = login;