fca-riyad 37.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 (242) hide show
  1. package/CHANGELOG.md +325 -0
  2. package/DOCS.md +2712 -0
  3. package/README.md +410 -0
  4. package/func/checkUpdate.js +7 -0
  5. package/func/logAdapter.js +33 -0
  6. package/func/logger.js +48 -0
  7. package/index.d.ts +751 -0
  8. package/index.js +22 -0
  9. package/module/config.js +40 -0
  10. package/module/login.js +133 -0
  11. package/module/loginHelper.js +1359 -0
  12. package/module/options.js +44 -0
  13. package/package.json +95 -0
  14. package/src/api/action/addExternalModule.js +25 -0
  15. package/src/api/action/changeAvatar.js +137 -0
  16. package/src/api/action/changeBio.js +75 -0
  17. package/src/api/action/enableAutoSaveAppState.js +73 -0
  18. package/src/api/action/getCurrentUserID.js +7 -0
  19. package/src/api/action/handleFriendRequest.js +57 -0
  20. package/src/api/action/logout.js +76 -0
  21. package/src/api/action/refreshFb_dtsg.js +48 -0
  22. package/src/api/action/setPostReaction.js +106 -0
  23. package/src/api/action/unfriend.js +54 -0
  24. package/src/api/http/httpGet.js +46 -0
  25. package/src/api/http/httpPost.js +52 -0
  26. package/src/api/http/postFormData.js +47 -0
  27. package/src/api/messaging/addUserToGroup.js +68 -0
  28. package/src/api/messaging/changeAdminStatus.js +126 -0
  29. package/src/api/messaging/changeArchivedStatus.js +55 -0
  30. package/src/api/messaging/changeBlockedStatus.js +48 -0
  31. package/src/api/messaging/changeGroupImage.js +91 -0
  32. package/src/api/messaging/changeNickname.js +70 -0
  33. package/src/api/messaging/changeThreadColor.js +79 -0
  34. package/src/api/messaging/changeThreadEmoji.js +111 -0
  35. package/src/api/messaging/createNewGroup.js +88 -0
  36. package/src/api/messaging/createPoll.js +46 -0
  37. package/src/api/messaging/createThemeAI.js +98 -0
  38. package/src/api/messaging/deleteMessage.js +136 -0
  39. package/src/api/messaging/deleteThread.js +56 -0
  40. package/src/api/messaging/editMessage.js +90 -0
  41. package/src/api/messaging/forwardAttachment.js +57 -0
  42. package/src/api/messaging/forwardMessage.js +134 -0
  43. package/src/api/messaging/getEmojiUrl.js +29 -0
  44. package/src/api/messaging/getFriendsList.js +82 -0
  45. package/src/api/messaging/getMessage.js +829 -0
  46. package/src/api/messaging/getThemePictures.js +62 -0
  47. package/src/api/messaging/handleMessageRequest.js +65 -0
  48. package/src/api/messaging/markAsDelivered.js +57 -0
  49. package/src/api/messaging/markAsRead.js +88 -0
  50. package/src/api/messaging/markAsReadAll.js +49 -0
  51. package/src/api/messaging/markAsSeen.js +61 -0
  52. package/src/api/messaging/muteThread.js +50 -0
  53. package/src/api/messaging/pinMessage.js +115 -0
  54. package/src/api/messaging/removeUserFromGroup.js +62 -0
  55. package/src/api/messaging/resolvePhotoUrl.js +43 -0
  56. package/src/api/messaging/scheduler.js +264 -0
  57. package/src/api/messaging/searchForThread.js +53 -0
  58. package/src/api/messaging/sendBroadcast.js +93 -0
  59. package/src/api/messaging/sendMessage.js +269 -0
  60. package/src/api/messaging/sendTypingIndicator.js +74 -0
  61. package/src/api/messaging/sessionGuard.js +130 -0
  62. package/src/api/messaging/setMessageReaction.js +95 -0
  63. package/src/api/messaging/setTitle.js +124 -0
  64. package/src/api/messaging/shareContact.js +49 -0
  65. package/src/api/messaging/threadColors.js +128 -0
  66. package/src/api/messaging/unsendMessage.js +81 -0
  67. package/src/api/messaging/uploadAttachment.js +492 -0
  68. package/src/api/socket/OldMessage.js +186 -0
  69. package/src/api/socket/core/connectMqtt.js +269 -0
  70. package/src/api/socket/core/emitAuth.js +103 -0
  71. package/src/api/socket/core/getSeqID.js +321 -0
  72. package/src/api/socket/core/getTaskResponseData.js +25 -0
  73. package/src/api/socket/core/parseDelta.js +387 -0
  74. package/src/api/socket/detail/buildStream.js +215 -0
  75. package/src/api/socket/detail/constants.js +28 -0
  76. package/src/api/socket/e2ee/crypto.js +173 -0
  77. package/src/api/socket/e2ee/e2ee/crypto.js +173 -0
  78. package/src/api/socket/e2ee/e2ee/index.js +421 -0
  79. package/src/api/socket/e2ee/e2ee/proto/ArmadilloApplication.proto +281 -0
  80. package/src/api/socket/e2ee/e2ee/proto/ArmadilloICDC.proto +14 -0
  81. package/src/api/socket/e2ee/e2ee/proto/ConsumerApplication.proto +232 -0
  82. package/src/api/socket/e2ee/e2ee/proto/MessageApplication.proto +82 -0
  83. package/src/api/socket/e2ee/e2ee/proto/MessageTransport.proto +77 -0
  84. package/src/api/socket/e2ee/e2ee/proto/WACommon.proto +66 -0
  85. package/src/api/socket/e2ee/e2ee/proto/WAMediaTransport.proto +176 -0
  86. package/src/api/socket/e2ee/e2ee/proto/proto-writer.ts +76 -0
  87. package/src/api/socket/e2ee/e2ee/protocol.js +196 -0
  88. package/src/api/socket/e2ee/e2ee/ratchet.js +219 -0
  89. package/src/api/socket/e2ee/e2ee/store.js +182 -0
  90. package/src/api/socket/e2ee/e2ee/vendor/fb-e2ee.cjs +9162 -0
  91. package/src/api/socket/e2ee/e2ee/vendor/proto/ArmadilloApplication.proto +281 -0
  92. package/src/api/socket/e2ee/e2ee/vendor/proto/ArmadilloICDC.proto +14 -0
  93. package/src/api/socket/e2ee/e2ee/vendor/proto/ConsumerApplication.proto +232 -0
  94. package/src/api/socket/e2ee/e2ee/vendor/proto/MessageApplication.proto +82 -0
  95. package/src/api/socket/e2ee/e2ee/vendor/proto/MessageTransport.proto +77 -0
  96. package/src/api/socket/e2ee/e2ee/vendor/proto/WACommon.proto +66 -0
  97. package/src/api/socket/e2ee/e2ee/vendor/proto/WAMediaTransport.proto +176 -0
  98. package/src/api/socket/e2ee/e2ee/vendor/proto/proto-writer.ts +76 -0
  99. package/src/api/socket/e2ee/index.js +437 -0
  100. package/src/api/socket/e2ee/proto/ArmadilloApplication.proto +281 -0
  101. package/src/api/socket/e2ee/proto/ArmadilloICDC.proto +14 -0
  102. package/src/api/socket/e2ee/proto/ConsumerApplication.proto +232 -0
  103. package/src/api/socket/e2ee/proto/MessageApplication.proto +82 -0
  104. package/src/api/socket/e2ee/proto/MessageTransport.proto +77 -0
  105. package/src/api/socket/e2ee/proto/WACommon.proto +66 -0
  106. package/src/api/socket/e2ee/proto/WAMediaTransport.proto +176 -0
  107. package/src/api/socket/e2ee/proto/proto-writer.ts +76 -0
  108. package/src/api/socket/e2ee/protocol.js +196 -0
  109. package/src/api/socket/e2ee/ratchet.js +219 -0
  110. package/src/api/socket/e2ee/store.js +182 -0
  111. package/src/api/socket/e2ee/vendor/fb-e2ee.cjs +9162 -0
  112. package/src/api/socket/e2ee/vendor/proto/ArmadilloApplication.proto +281 -0
  113. package/src/api/socket/e2ee/vendor/proto/ArmadilloICDC.proto +14 -0
  114. package/src/api/socket/e2ee/vendor/proto/ConsumerApplication.proto +232 -0
  115. package/src/api/socket/e2ee/vendor/proto/MessageApplication.proto +82 -0
  116. package/src/api/socket/e2ee/vendor/proto/MessageTransport.proto +77 -0
  117. package/src/api/socket/e2ee/vendor/proto/WACommon.proto +66 -0
  118. package/src/api/socket/e2ee/vendor/proto/WAMediaTransport.proto +176 -0
  119. package/src/api/socket/e2ee/vendor/proto/proto-writer.ts +76 -0
  120. package/src/api/socket/listenE2EE.js +75 -0
  121. package/src/api/socket/listenMqtt.js +388 -0
  122. package/src/api/socket/middleware/index.js +216 -0
  123. package/src/api/socket/sendMessage.js +309 -0
  124. package/src/api/socket/sendMessageMqtt.js +69 -0
  125. package/src/api/threads/getThreadHistory.js +664 -0
  126. package/src/api/threads/getThreadInfo.js +296 -0
  127. package/src/api/threads/getThreadList.js +293 -0
  128. package/src/api/threads/getThreadPictures.js +78 -0
  129. package/src/api/users/getUserID.js +65 -0
  130. package/src/api/users/getUserInfo.js +402 -0
  131. package/src/api/users/getUserInfoV2.js +134 -0
  132. package/src/app/MessengerBot.js +209 -0
  133. package/src/app/MessengerContext.js +32 -0
  134. package/src/app/createFcaClient.js +136 -0
  135. package/src/app/threadInfoRealtimeSync.js +284 -0
  136. package/src/core/sendReqMqtt.js +96 -0
  137. package/src/database/helpers.js +53 -0
  138. package/src/database/models/index.js +88 -0
  139. package/src/database/models/thread.js +50 -0
  140. package/src/database/models/user.js +46 -0
  141. package/src/database/threadData.js +94 -0
  142. package/src/database/userData.js +98 -0
  143. package/src/remote/remoteClient.js +123 -0
  144. package/src/utils/broadcast.js +51 -0
  145. package/src/utils/client.js +10 -0
  146. package/src/utils/constants.js +23 -0
  147. package/src/utils/cookies.js +68 -0
  148. package/src/utils/format/attachment.js +357 -0
  149. package/src/utils/format/cookie.js +9 -0
  150. package/src/utils/format/date.js +50 -0
  151. package/src/utils/format/decode.js +44 -0
  152. package/src/utils/format/delta.js +194 -0
  153. package/src/utils/format/ids.js +64 -0
  154. package/src/utils/format/index.js +64 -0
  155. package/src/utils/format/message.js +88 -0
  156. package/src/utils/format/presence.js +132 -0
  157. package/src/utils/format/readTyp.js +44 -0
  158. package/src/utils/format/thread.js +42 -0
  159. package/src/utils/format/utils.js +141 -0
  160. package/src/utils/headers.js +115 -0
  161. package/src/utils/loginParser/autoLogin.js +125 -0
  162. package/src/utils/loginParser/helpers.js +43 -0
  163. package/src/utils/loginParser/index.js +10 -0
  164. package/src/utils/loginParser/parseAndCheckLogin.js +220 -0
  165. package/src/utils/loginParser/textUtils.js +28 -0
  166. package/src/utils/nexca-logger.js +144 -0
  167. package/src/utils/nexca-utils.js +686 -0
  168. package/src/utils/request/client.js +26 -0
  169. package/src/utils/request/config.js +23 -0
  170. package/src/utils/request/defaults.js +46 -0
  171. package/src/utils/request/helpers.js +46 -0
  172. package/src/utils/request/index.js +17 -0
  173. package/src/utils/request/methods.js +163 -0
  174. package/src/utils/request/proxy.js +21 -0
  175. package/src/utils/request/retry.js +77 -0
  176. package/src/utils/request/sanitize.js +49 -0
  177. package/src/utils/versionCheck.js +47 -0
  178. package/src/vendor/fca-unofficial/.github/workflows/nodejs.yml +26 -0
  179. package/src/vendor/fca-unofficial/.github/workflows/npmpublish.yml +30 -0
  180. package/src/vendor/fca-unofficial/.travis.yml +6 -0
  181. package/src/vendor/fca-unofficial/DOCS.md +1731 -0
  182. package/src/vendor/fca-unofficial/LICENSE-MIT +21 -0
  183. package/src/vendor/fca-unofficial/README.md +225 -0
  184. package/src/vendor/fca-unofficial/index.js +619 -0
  185. package/src/vendor/fca-unofficial/package.json +76 -0
  186. package/src/vendor/fca-unofficial/src/addExternalModule.js +19 -0
  187. package/src/vendor/fca-unofficial/src/addUserToGroup.js +113 -0
  188. package/src/vendor/fca-unofficial/src/changeAdminStatus.js +79 -0
  189. package/src/vendor/fca-unofficial/src/changeArchivedStatus.js +55 -0
  190. package/src/vendor/fca-unofficial/src/changeBio.js +77 -0
  191. package/src/vendor/fca-unofficial/src/changeBlockedStatus.js +47 -0
  192. package/src/vendor/fca-unofficial/src/changeGroupImage.js +129 -0
  193. package/src/vendor/fca-unofficial/src/changeNickname.js +59 -0
  194. package/src/vendor/fca-unofficial/src/changeThreadColor.js +71 -0
  195. package/src/vendor/fca-unofficial/src/changeThreadEmoji.js +55 -0
  196. package/src/vendor/fca-unofficial/src/createNewGroup.js +86 -0
  197. package/src/vendor/fca-unofficial/src/createPoll.js +71 -0
  198. package/src/vendor/fca-unofficial/src/deleteMessage.js +56 -0
  199. package/src/vendor/fca-unofficial/src/deleteThread.js +56 -0
  200. package/src/vendor/fca-unofficial/src/forwardAttachment.js +60 -0
  201. package/src/vendor/fca-unofficial/src/getCurrentUserID.js +7 -0
  202. package/src/vendor/fca-unofficial/src/getEmojiUrl.js +29 -0
  203. package/src/vendor/fca-unofficial/src/getFriendsList.js +84 -0
  204. package/src/vendor/fca-unofficial/src/getThreadHistory.js +645 -0
  205. package/src/vendor/fca-unofficial/src/getThreadHistoryDeprecated.js +93 -0
  206. package/src/vendor/fca-unofficial/src/getThreadInfo.js +201 -0
  207. package/src/vendor/fca-unofficial/src/getThreadInfoDeprecated.js +80 -0
  208. package/src/vendor/fca-unofficial/src/getThreadList.js +238 -0
  209. package/src/vendor/fca-unofficial/src/getThreadListDeprecated.js +75 -0
  210. package/src/vendor/fca-unofficial/src/getThreadPictures.js +79 -0
  211. package/src/vendor/fca-unofficial/src/getUserID.js +66 -0
  212. package/src/vendor/fca-unofficial/src/getUserInfo.js +72 -0
  213. package/src/vendor/fca-unofficial/src/handleFriendRequest.js +61 -0
  214. package/src/vendor/fca-unofficial/src/handleMessageRequest.js +65 -0
  215. package/src/vendor/fca-unofficial/src/httpGet.js +52 -0
  216. package/src/vendor/fca-unofficial/src/httpPost.js +52 -0
  217. package/src/vendor/fca-unofficial/src/listenMqtt.js +788 -0
  218. package/src/vendor/fca-unofficial/src/logout.js +75 -0
  219. package/src/vendor/fca-unofficial/src/markAsDelivered.js +58 -0
  220. package/src/vendor/fca-unofficial/src/markAsRead.js +80 -0
  221. package/src/vendor/fca-unofficial/src/markAsReadAll.js +50 -0
  222. package/src/vendor/fca-unofficial/src/markAsSeen.js +59 -0
  223. package/src/vendor/fca-unofficial/src/muteThread.js +52 -0
  224. package/src/vendor/fca-unofficial/src/removeUserFromGroup.js +79 -0
  225. package/src/vendor/fca-unofficial/src/resolvePhotoUrl.js +45 -0
  226. package/src/vendor/fca-unofficial/src/searchForThread.js +53 -0
  227. package/src/vendor/fca-unofficial/src/sendMessage.js +459 -0
  228. package/src/vendor/fca-unofficial/src/sendTypingIndicator.js +103 -0
  229. package/src/vendor/fca-unofficial/src/setMessageReaction.js +117 -0
  230. package/src/vendor/fca-unofficial/src/setPostReaction.js +76 -0
  231. package/src/vendor/fca-unofficial/src/setTitle.js +86 -0
  232. package/src/vendor/fca-unofficial/src/threadColors.js +57 -0
  233. package/src/vendor/fca-unofficial/src/unfriend.js +52 -0
  234. package/src/vendor/fca-unofficial/src/unsendMessage.js +49 -0
  235. package/src/vendor/fca-unofficial/test/data/shareAttach.js +146 -0
  236. package/src/vendor/fca-unofficial/test/data/something.mov +0 -0
  237. package/src/vendor/fca-unofficial/test/data/test.png +0 -0
  238. package/src/vendor/fca-unofficial/test/data/test.txt +7 -0
  239. package/src/vendor/fca-unofficial/test/example-config.json +18 -0
  240. package/src/vendor/fca-unofficial/test/test-page.js +140 -0
  241. package/src/vendor/fca-unofficial/test/test.js +385 -0
  242. package/src/vendor/fca-unofficial/utils.js +1358 -0
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ const { getType } = require("../../utils/format");
3
+ module.exports = function (defaultFuncs, api, ctx) {
4
+ return function sendTyping(threadID, isTyping, options, callback) {
5
+ var resolveFunc = function () { };
6
+ var rejectFunc = function () { };
7
+ var returnPromise = new Promise(function (resolve, reject) {
8
+ resolveFunc = resolve;
9
+ rejectFunc = reject;
10
+ });
11
+ if (getType(options) == "Function" || getType(options) == "AsyncFunction") {
12
+ callback = options;
13
+ options = {};
14
+ }
15
+ options = options || {};
16
+ if (!callback || getType(callback) != "Function" && getType(callback) != "AsyncFunction") {
17
+ callback = function (err, data) {
18
+ if (err) return rejectFunc(err);
19
+ resolveFunc(data);
20
+ };
21
+ }
22
+ if (!threadID) {
23
+ return callback(new Error("threadID is required"));
24
+ }
25
+ if (!ctx.mqttClient) {
26
+ const err = new Error("Not connected to MQTT");
27
+ callback(err);
28
+ rejectFunc(err);
29
+ return returnPromise;
30
+ }
31
+ if (typeof ctx.wsReqNumber !== "number") ctx.wsReqNumber = 0;
32
+ const threadIDs = Array.isArray(threadID) ? threadID : [threadID];
33
+ threadIDs.forEach(tid => {
34
+ var isGroupThread = getType(tid) === "Array" ? 0 : 1;
35
+ var threadType = isGroupThread ? 2 : 1;
36
+ var duration = options.duration || 10000;
37
+ var autoStop = options.autoStop !== false;
38
+ var attribution = options.type || 0;
39
+ const publishTypingStatus = (isTypingStatus) => {
40
+ ctx.mqttClient.publish('/ls_req',
41
+ JSON.stringify({
42
+ app_id: "772021112871879",
43
+ payload: JSON.stringify({
44
+ label: "3",
45
+ payload: JSON.stringify({
46
+ "thread_key": parseInt(tid),
47
+ "is_group_thread": isGroupThread,
48
+ "is_typing": isTypingStatus ? 1 : 0,
49
+ "attribution": attribution,
50
+ "sync_group": 1,
51
+ "thread_type": threadType
52
+ }),
53
+ version: "8965252033599983"
54
+ }),
55
+ request_id: ++ctx.wsReqNumber,
56
+ type: 4
57
+ }),
58
+ {
59
+ qos: 1,
60
+ retain: false,
61
+ }
62
+ );
63
+ };
64
+ publishTypingStatus(isTyping);
65
+ if (isTyping && autoStop) {
66
+ setTimeout(() => {
67
+ publishTypingStatus(false);
68
+ }, duration);
69
+ }
70
+ });
71
+ callback(null, true);
72
+ return returnPromise;
73
+ };
74
+ };
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * SessionGuard — Protects the appstate (session) from corruption and silent logouts.
5
+ *
6
+ * Features:
7
+ * • Auto-saves appstate to disk periodically (default every 5 min)
8
+ * • Saves on every successful message send (debounced, 30s cooldown)
9
+ * • Backs up the previous appstate before overwriting (.bak file)
10
+ * • Detects logout/checkpoint events from listen stream and alerts
11
+ * • Provides api.saveSession([path]) for manual save at any time
12
+ * • Never overwrites with a shorter/smaller appstate (corruption guard)
13
+ */
14
+
15
+ var fs = require("fs");
16
+ var path = require("path");
17
+ var logger = require("../../utils/nexca-logger");
18
+
19
+ var SAVE_INTERVAL_MS = 5 * 60 * 1000; // 5 minutes
20
+ var DEBOUNCE_MS = 30 * 1000; // 30 seconds cooldown between auto-saves
21
+ var MIN_COOKIES = 5; // minimum cookie count we consider "valid"
22
+
23
+ module.exports = function (defaultFuncs, api, ctx) {
24
+
25
+ function getState() {
26
+ try { return api.getAppState(); } catch (_) { return null; }
27
+ }
28
+
29
+ function saveToDisk(filePath) {
30
+ var state = getState();
31
+ if (!state || !Array.isArray(state) || state.length < MIN_COOKIES) {
32
+ logger.warn("SessionGuard", "Skipped save — state looks empty or invalid (" + (state ? state.length : 0) + " cookies).");
33
+ return false;
34
+ }
35
+
36
+ // Corruption guard: never write a smaller appstate than what's already on disk
37
+ if (fs.existsSync(filePath)) {
38
+ try {
39
+ var existing = JSON.parse(fs.readFileSync(filePath, "utf8"));
40
+ if (Array.isArray(existing) && state.length < existing.length * 0.8) {
41
+ logger.warn("SessionGuard", "Skipped save — new state has " + state.length + " cookies vs " + existing.length + " on disk (possible truncation).");
42
+ return false;
43
+ }
44
+ // Backup the current valid state before overwriting
45
+ fs.writeFileSync(filePath + ".bak", JSON.stringify(existing, null, 2), "utf8");
46
+ } catch (_) {}
47
+ }
48
+
49
+ fs.writeFileSync(filePath, JSON.stringify(state, null, 2), "utf8");
50
+ logger.success("SessionGuard", "Session saved → " + filePath + " (" + state.length + " cookies)");
51
+ return true;
52
+ }
53
+
54
+ return function sessionGuard(appStatePath, options) {
55
+ options = options || {};
56
+ var interval = options.interval !== undefined ? options.interval : SAVE_INTERVAL_MS;
57
+ var debounce = options.debounce !== undefined ? options.debounce : DEBOUNCE_MS;
58
+
59
+ appStatePath = appStatePath || path.join(process.cwd(), "appstate.json");
60
+
61
+ var lastSave = 0;
62
+ var intervalRef = null;
63
+
64
+ // Periodic save
65
+ if (interval > 0) {
66
+ intervalRef = setInterval(function () {
67
+ logger.info("SessionGuard", "Periodic save...");
68
+ saveToDisk(appStatePath);
69
+ lastSave = Date.now();
70
+ }, interval);
71
+ if (intervalRef.unref) intervalRef.unref(); // don't block process exit
72
+ }
73
+
74
+ // Debounced on-send save
75
+ // Patch sendMessage to auto-save appstate after a successful send
76
+ var originalSendMessage = api.sendMessage;
77
+ api.sendMessage = function () {
78
+ var result = originalSendMessage.apply(this, arguments);
79
+ // After send, debounce-save
80
+ Promise.resolve(result).then(function () {
81
+ if (Date.now() - lastSave > debounce) {
82
+ saveToDisk(appStatePath);
83
+ lastSave = Date.now();
84
+ }
85
+ }).catch(function () {});
86
+ return result;
87
+ };
88
+
89
+ // Expose manual save
90
+ api.saveSession = function (customPath) {
91
+ return saveToDisk(customPath || appStatePath);
92
+ };
93
+
94
+ // Expose restore from backup
95
+ api.restoreSessionBackup = function (customPath) {
96
+ var bakPath = (customPath || appStatePath) + ".bak";
97
+ if (!fs.existsSync(bakPath)) {
98
+ logger.warn("SessionGuard", "No backup file found at " + bakPath);
99
+ return false;
100
+ }
101
+ try {
102
+ var bak = fs.readFileSync(bakPath, "utf8");
103
+ fs.writeFileSync(customPath || appStatePath, bak, "utf8");
104
+ logger.success("SessionGuard", "Backup restored from " + bakPath);
105
+ return true;
106
+ } catch (e) {
107
+ logger.error("SessionGuard", "Restore failed: " + e.message);
108
+ return false;
109
+ }
110
+ };
111
+
112
+ // Expose stop
113
+ api.stopSessionGuard = function () {
114
+ if (intervalRef) clearInterval(intervalRef);
115
+ api.sendMessage = originalSendMessage;
116
+ logger.info("SessionGuard", "Stopped.");
117
+ };
118
+
119
+ logger.success(
120
+ "SessionGuard",
121
+ "Active — auto-save every " + Math.round(interval / 60000) + " min → " + appStatePath
122
+ );
123
+
124
+ return {
125
+ save: function (p) { return saveToDisk(p || appStatePath); },
126
+ stop: api.stopSessionGuard,
127
+ restore: api.restoreSessionBackup
128
+ };
129
+ };
130
+ };
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+
3
+ const logger = require("../../../func/logger");
4
+ const { generateOfflineThreadingID, getCurrentTimestamp } = require("../../utils/format");
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return function setMessageReaction(reaction, messageID, threadID, callback, forceCustomReaction) {
8
+ // ✅ Riyad Fix: threadID is now optional (backward compatible)
9
+ if (typeof threadID === "function") {
10
+ forceCustomReaction = callback;
11
+ callback = threadID;
12
+ threadID = null;
13
+ } else if (typeof threadID === "boolean") {
14
+ forceCustomReaction = threadID;
15
+ callback = undefined;
16
+ threadID = null;
17
+ } else if (typeof callback === "boolean") {
18
+ forceCustomReaction = callback;
19
+ callback = undefined;
20
+ }
21
+ const cb = typeof callback === "function" ? callback : undefined;
22
+
23
+ // threadID না থাকলে ctx থেকে নেওয়ার চেষ্টা
24
+ const finalThreadID = threadID || ctx.lastThreadID || "0";
25
+
26
+ return new Promise((resolve, reject) => {
27
+ if (!ctx.mqttClient) {
28
+ const err = new Error("MQTT client not connected");
29
+ if (cb) cb(err);
30
+ return reject(err);
31
+ }
32
+ if (reaction === undefined || reaction === null || !messageID) {
33
+ const err = new Error("Missing required parameters (reaction, messageID)");
34
+ if (cb) cb(err);
35
+ return reject(err);
36
+ }
37
+ if (typeof ctx.wsReqNumber !== "number") ctx.wsReqNumber = 0;
38
+ if (typeof ctx.wsTaskNumber !== "number") ctx.wsTaskNumber = 0;
39
+ const reqID = ++ctx.wsReqNumber;
40
+ const taskID = ++ctx.wsTaskNumber;
41
+ const taskPayload = {
42
+ thread_key: finalThreadID,
43
+ timestamp_ms: getCurrentTimestamp(),
44
+ message_id: messageID,
45
+ reaction: reaction,
46
+ actor_id: ctx.userID,
47
+ reaction_style: forceCustomReaction ? 1 : null,
48
+ sync_group: 1,
49
+ send_attribution: 65537,
50
+ dataclass_params: null,
51
+ attachment_fbid: null
52
+ };
53
+ const task = {
54
+ failure_count: null,
55
+ label: "29",
56
+ payload: JSON.stringify(taskPayload),
57
+ queue_name: "reaction:" + messageID,
58
+ task_id: taskID,
59
+ };
60
+ const mqttForm = {
61
+ app_id: "2220391788200892",
62
+ payload: JSON.stringify({
63
+ epoch_id: parseInt(generateOfflineThreadingID()),
64
+ tasks: [task],
65
+ version_id: "24585299697835063"
66
+ }),
67
+ request_id: reqID,
68
+ type: 3
69
+ };
70
+ const handleResponse = (topic, message) => {
71
+ if (topic !== "/ls_resp") return;
72
+ let json;
73
+ try {
74
+ json = JSON.parse(message.toString());
75
+ json.payload = JSON.parse(json.payload);
76
+ } catch {
77
+ return;
78
+ }
79
+ if (json.request_id !== reqID) return;
80
+ ctx.mqttClient.removeListener("message", handleResponse);
81
+ if (cb) cb(null, { success: true });
82
+ return resolve({ success: true });
83
+ };
84
+ ctx.mqttClient.on("message", handleResponse);
85
+ ctx.mqttClient.publish("/ls_req", JSON.stringify(mqttForm), { qos: 1, retain: false }, (err) => {
86
+ if (err) {
87
+ ctx.mqttClient.removeListener("message", handleResponse);
88
+ logger("setMessageReaction" + err, "error");
89
+ if (cb) cb(err);
90
+ return reject(err);
91
+ }
92
+ });
93
+ });
94
+ };
95
+ };
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+
3
+ const { getType, generateOfflineThreadingID, generateTimestampRelative, generateThreadingID, getCurrentTimestamp } = require("../../utils/format");
4
+ const { parseAndCheckLogin } = require("../../utils/client");
5
+ const log = require("../../../func/logAdapter");
6
+
7
+ module.exports = function (defaultFuncs, api, ctx) {
8
+ function setTitleNoMqtt(newTitle, threadID, callback) {
9
+ if (!callback && (getType(threadID) === "Function" || getType(threadID) === "AsyncFunction")) throw { error: "please pass a threadID as a second argument." };
10
+ var resolveFunc = function () { };
11
+ var rejectFunc = function () { };
12
+ var returnPromise = new Promise(function (resolve, reject) {
13
+ resolveFunc = resolve;
14
+ rejectFunc = reject;
15
+ });
16
+ if (!callback) {
17
+ callback = function (err, data) {
18
+ if (err) return rejectFunc(err);
19
+ resolveFunc(data);
20
+ };
21
+ }
22
+ var messageAndOTID = generateOfflineThreadingID();
23
+ var form = {
24
+ client: "mercury",
25
+ action_type: "ma-type:log-message",
26
+ author: "fbid:" + ctx.userID,
27
+ author_email: "",
28
+ coordinates: "",
29
+ timestamp: Date.now(),
30
+ timestamp_absolute: "Today",
31
+ timestamp_relative: generateTimestampRelative(),
32
+ timestamp_time_passed: "0",
33
+ is_unread: false,
34
+ is_cleared: false,
35
+ is_forward: false,
36
+ is_filtered_content: false,
37
+ is_spoof_warning: false,
38
+ source: "source:chat:web",
39
+ "source_tags[0]": "source:chat",
40
+ status: "0",
41
+ offline_threading_id: messageAndOTID,
42
+ message_id: messageAndOTID,
43
+ threading_id: generateThreadingID(ctx.clientID),
44
+ manual_retry_cnt: "0",
45
+ thread_fbid: threadID,
46
+ thread_name: newTitle,
47
+ thread_id: threadID,
48
+ log_message_type: "log:thread-name"
49
+ };
50
+ defaultFuncs
51
+ .post("https://www.facebook.com/messaging/set_thread_name/", ctx.jar, form)
52
+ .then(parseAndCheckLogin(ctx, defaultFuncs))
53
+ .then(function (resData) {
54
+ if (resData.error && resData.error === 1545012) throw { error: "Cannot change chat title: Not member of chat." };
55
+ if (resData.error && resData.error === 1545003) throw { error: "Cannot set title of single-user chat." };
56
+ if (resData.error) throw resData;
57
+ return callback();
58
+ })
59
+ .catch(function (err) {
60
+ log.error("setTitle", err);
61
+ return callback(err);
62
+ });
63
+ return returnPromise;
64
+ };
65
+ function setTitleMqtt(newTitle, threadID, callback) {
66
+ if (!ctx.mqttClient) {
67
+ throw new Error("Not connected to MQTT");
68
+ }
69
+ if (typeof ctx.wsReqNumber !== "number") ctx.wsReqNumber = 0;
70
+ const reqID = ++ctx.wsReqNumber;
71
+ var resolveFunc = function () { };
72
+ var rejectFunc = function () { };
73
+ var returnPromise = new Promise(function (resolve, reject) {
74
+ resolveFunc = resolve;
75
+ rejectFunc = reject;
76
+ });
77
+ const done = (err, data) => {
78
+ if (err) {
79
+ if (callback) callback(err);
80
+ return rejectFunc(err);
81
+ }
82
+ if (callback) callback(null, data);
83
+ resolveFunc(data);
84
+ };
85
+ var form = JSON.stringify({
86
+ "app_id": "2220391788200892",
87
+ "payload": JSON.stringify({
88
+ epoch_id: generateOfflineThreadingID(),
89
+ tasks: [
90
+ {
91
+ failure_count: null,
92
+ label: '32',
93
+ payload: JSON.stringify({
94
+ "thread_key": threadID,
95
+ "thread_name": newTitle,
96
+ "sync_group": 1
97
+ }),
98
+ queue_name: threadID,
99
+ task_id: Math.random() * 1001 << 0
100
+ }
101
+ ],
102
+ version_id: '8798795233522156'
103
+ }),
104
+ "request_id": reqID,
105
+ "type": 3
106
+ });
107
+ ctx.mqttClient.publish("/ls_req", form, { qos: 1, retain: false }, (err) => {
108
+ if (err) return done(err);
109
+ done(null, { success: true });
110
+ });
111
+ return returnPromise;
112
+ };
113
+ return function setTitle(newTitle, threadID, callback) {
114
+ if (ctx.mqttClient) {
115
+ try {
116
+ return setTitleMqtt(newTitle, threadID, callback);
117
+ } catch (e) {
118
+ return setTitleNoMqtt(newTitle, threadID, callback);
119
+ }
120
+ } else {
121
+ return setTitleNoMqtt(newTitle, threadID, callback);
122
+ }
123
+ };
124
+ };
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ const { generateOfflineThreadingID } = require("../../utils/format");
4
+ module.exports = function(defaultFuncs, api, ctx) {
5
+ return function shareContact(text, senderID, threadID, callback) {
6
+ if (!text) {
7
+ text = "";
8
+ }
9
+ var resolveFunc = function() {};
10
+ var rejectFunc = function() {};
11
+ var returnPromise = new Promise(function(resolve, reject) {
12
+ resolveFunc = resolve;
13
+ rejectFunc = reject;
14
+ });
15
+ if (!callback) {
16
+ callback = function(err, data) {
17
+ if (err) return rejectFunc(err);
18
+ resolveFunc(data);
19
+ data;
20
+ };
21
+ }
22
+ let count_req = 0;
23
+ var form = JSON.stringify({
24
+ app_id: "2220391788200892",
25
+ payload: JSON.stringify({
26
+ tasks: [
27
+ {
28
+ label: "359",
29
+ payload: JSON.stringify({
30
+ contact_id: senderID,
31
+ sync_group: 1,
32
+ text: text || "",
33
+ thread_id: threadID
34
+ }),
35
+ queue_name: "messenger_contact_sharing",
36
+ task_id: (Math.random() * 1001) << 0,
37
+ failure_count: null
38
+ }
39
+ ],
40
+ epoch_id: generateOfflineThreadingID(),
41
+ version_id: "7214102258676893"
42
+ }),
43
+ request_id: ++count_req,
44
+ type: 3
45
+ });
46
+ ctx.mqttClient.publish("/ls_req", form);
47
+ return returnPromise;
48
+ };
49
+ };
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+
3
+ module.exports = function(_defaultFuncs, _api, _ctx) {
4
+ // Currently the only colors that can be passed to api.changeThreadColor(); may change if Facebook adds more
5
+ return {
6
+ //Old hex colors.
7
+ ////MessengerBlue: null,
8
+ ////Viking: "#44bec7",
9
+ ////GoldenPoppy: "#ffc300",
10
+ ////RadicalRed: "#fa3c4c",
11
+ ////Shocking: "#d696bb",
12
+ ////PictonBlue: "#6699cc",
13
+ ////FreeSpeechGreen: "#13cf13",
14
+ ////Pumpkin: "#ff7e29",
15
+ ////LightCoral: "#e68585",
16
+ ////MediumSlateBlue: "#7646ff",
17
+ ////DeepSkyBlue: "#20cef5",
18
+ ////Fern: "#67b868",
19
+ ////Cameo: "#d4a88c",
20
+ ////BrilliantRose: "#ff5ca1",
21
+ ////BilobaFlower: "#a695c7"
22
+
23
+ //#region This part is for backward compatibly
24
+ //trying to match the color one-by-one. kill me plz
25
+ MessengerBlue: "196241301102133", //DefaultBlue
26
+ Viking: "1928399724138152", //TealBlue
27
+ GoldenPoppy: "174636906462322", //Yellow
28
+ RadicalRed: "2129984390566328", //Red
29
+ Shocking: "2058653964378557", //LavenderPurple
30
+ FreeSpeechGreen: "2136751179887052", //Green
31
+ Pumpkin: "175615189761153", //Orange
32
+ LightCoral: "980963458735625", //CoralPink
33
+ MediumSlateBlue: "234137870477637", //BrightPurple
34
+ DeepSkyBlue: "2442142322678320", //AquaBlue
35
+ BrilliantRose: "169463077092846", //HotPink
36
+ DefaultBlue: "196241301102133",
37
+ HotPink: "169463077092846",
38
+ AquaBlue: "2442142322678320",
39
+ BrightPurple: "234137870477637",
40
+ CoralPink: "980963458735625",
41
+ Orange: "175615189761153",
42
+ Green: "2136751179887052",
43
+ LavenderPurple: "2058653964378557",
44
+ Red: "2129984390566328",
45
+ Yellow: "174636906462322",
46
+ TealBlue: "1928399724138152",
47
+ Aqua: "417639218648241",
48
+ Mango: "930060997172551",
49
+ Berry: "164535220883264",
50
+ Citrus: "370940413392601",
51
+ Candy: "205488546921017",
52
+
53
+ /**
54
+ * July 06, 2022
55
+ * added by @NTKhang
56
+ */
57
+ Earth: "1833559466821043",
58
+ Support: "365557122117011",
59
+ Music: "339021464972092",
60
+ Pride: "1652456634878319",
61
+ DoctorStrange: "538280997628317",
62
+ LoFi: "1060619084701625",
63
+ Sky: "3190514984517598",
64
+ LunarNewYear: "357833546030778",
65
+ Celebration: "627144732056021",
66
+ Chill: "390127158985345",
67
+ StrangerThings: "1059859811490132",
68
+ Dune: "1455149831518874",
69
+ Care: "275041734441112",
70
+ Astrology: "3082966625307060",
71
+ JBalvin: "184305226956268",
72
+ Birthday: "621630955405500",
73
+ Cottagecore: "539927563794799",
74
+ Ocean: "736591620215564",
75
+ Love: "741311439775765",
76
+ TieDye: "230032715012014",
77
+ Monochrome: "788274591712841",
78
+ Default: "3259963564026002",
79
+ Rocket: "582065306070020",
80
+ Berry2: "724096885023603",
81
+ Candy2: "624266884847972",
82
+ Unicorn: "273728810607574",
83
+ Tropical: "262191918210707",
84
+ Maple: "2533652183614000",
85
+ Sushi: "909695489504566",
86
+ Citrus2: "557344741607350",
87
+ Lollipop: "280333826736184",
88
+ Shadow: "271607034185782",
89
+ Rose: "1257453361255152",
90
+ Lavender: "571193503540759",
91
+ Tulip: "2873642949430623",
92
+ Classic: "3273938616164733",
93
+ Peach: "3022526817824329",
94
+ Honey: "672058580051520",
95
+ Kiwi: "3151463484918004",
96
+ Grape: "193497045377796",
97
+
98
+ /**
99
+ * July 15, 2022
100
+ * added by @NTKhang
101
+ */
102
+ NonBinary: "737761000603635",
103
+
104
+ /**
105
+ * November 25, 2022
106
+ * added by @NTKhang
107
+ */
108
+ ThankfulForFriends: "1318983195536293",
109
+ Transgender: "504518465021637",
110
+ TaylorSwift: "769129927636836",
111
+ NationalComingOutDay: "788102625833584",
112
+ Autumn: "822549609168155",
113
+ Cyberpunk2077: "780962576430091",
114
+
115
+ /**
116
+ * May 13, 2023
117
+ */
118
+ MothersDay: "1288506208402340",
119
+ APAHM: "121771470870245",
120
+ Parenthood: "810978360551741",
121
+ StarWars: "1438011086532622",
122
+ GuardianOfTheGalaxy: "101275642962533",
123
+ Bloom: "158263147151440",
124
+ BubbleTea: "195296273246380",
125
+ Basketball: "6026716157422736",
126
+ ElephantsAndFlowers: "693996545771691"
127
+ };
128
+ };
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+
3
+ const { generateOfflineThreadingID } = require("../../utils/format");
4
+ const log = require("../../../func/logAdapter");
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return function unsendMessage(messageID, threadID, callback) {
8
+ return new Promise((resolve, reject) => {
9
+ if (!ctx.mqttClient) {
10
+ const err = new Error("Not connected to MQTT");
11
+ callback?.(err);
12
+ return reject(err);
13
+ }
14
+ const reqID = ++ctx.wsReqNumber;
15
+ const taskID = ++ctx.wsTaskNumber;
16
+ const taskPayload = {
17
+ message_id: messageID,
18
+ thread_key: threadID,
19
+ sync_group: 1,
20
+ };
21
+ const task = {
22
+ failure_count: null,
23
+ label: "33",
24
+ payload: JSON.stringify(taskPayload),
25
+ queue_name: "unsend_message",
26
+ task_id: taskID,
27
+ };
28
+ const content = {
29
+ app_id: "2220391788200892",
30
+ payload: JSON.stringify({
31
+ tasks: [task],
32
+ epoch_id: parseInt(generateOfflineThreadingID()),
33
+ version_id: "25393437286970779",
34
+ }),
35
+ request_id: reqID,
36
+ type: 3,
37
+ };
38
+ try {
39
+ ctx.mqttClient.publish("/ls_req", JSON.stringify(content), {
40
+ qos: 1,
41
+ retain: false
42
+ });
43
+ } catch (err) {
44
+ log.error("unsendMessage (MQTT publish failed)", err);
45
+ callback?.(err);
46
+ return reject(err);
47
+ }
48
+ const handleRes = (topic, message) => {
49
+ if (topic !== "/ls_resp") return;
50
+ let jsonMsg;
51
+ try {
52
+ jsonMsg = JSON.parse(message.toString());
53
+ jsonMsg.payload = JSON.parse(jsonMsg.payload);
54
+ } catch (err) {
55
+ return;
56
+ }
57
+ if (jsonMsg.request_id !== reqID) return;
58
+ ctx.mqttClient.removeListener("message", handleRes);
59
+ try {
60
+ const msgID = jsonMsg.payload.step?.[1]?.[2]?.[2]?.[1]?.[2];
61
+ const msgReplace = jsonMsg.payload.step?.[1]?.[2]?.[2]?.[1]?.[4];
62
+ if (msgID && msgReplace) {
63
+ const bodies = {
64
+ body: msgReplace,
65
+ messageID: msgID
66
+ };
67
+ callback?.(null, bodies);
68
+ return resolve(bodies);
69
+ } else {
70
+ callback?.(null, { success: true });
71
+ return resolve({ success: true });
72
+ }
73
+ } catch (err) {
74
+ callback?.(null, { success: true });
75
+ return resolve({ success: true });
76
+ }
77
+ };
78
+ ctx.mqttClient.on("message", handleRes);
79
+ });
80
+ };
81
+ };