fca-nx 6.6.6

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 (196) hide show
  1. package/LICENCE +21 -0
  2. package/README.md +446 -0
  3. package/e2ee/config.json +0 -0
  4. package/e2ee/crypto.js +173 -0
  5. package/e2ee/index.js +1032 -0
  6. package/e2ee/proto/ArmadilloApplication.proto +281 -0
  7. package/e2ee/proto/ArmadilloICDC.proto +14 -0
  8. package/e2ee/proto/ConsumerApplication.proto +232 -0
  9. package/e2ee/proto/MessageApplication.proto +82 -0
  10. package/e2ee/proto/MessageTransport.proto +77 -0
  11. package/e2ee/proto/WACommon.proto +66 -0
  12. package/e2ee/proto/WAMediaTransport.proto +176 -0
  13. package/e2ee/protocol.js +196 -0
  14. package/e2ee/ratchet.js +219 -0
  15. package/e2ee/store.js +182 -0
  16. package/e2ee/vendor/fb-e2ee.cjs +9159 -0
  17. package/e2ee/vendor/proto/ArmadilloApplication.proto +281 -0
  18. package/e2ee/vendor/proto/ArmadilloICDC.proto +14 -0
  19. package/e2ee/vendor/proto/ConsumerApplication.proto +232 -0
  20. package/e2ee/vendor/proto/MessageApplication.proto +82 -0
  21. package/e2ee/vendor/proto/MessageTransport.proto +77 -0
  22. package/e2ee/vendor/proto/WACommon.proto +66 -0
  23. package/e2ee/vendor/proto/WAMediaTransport.proto +176 -0
  24. package/func/checkUpdate.js +7 -0
  25. package/func/logAdapter.js +33 -0
  26. package/func/logger.js +134 -0
  27. package/index.js +22 -0
  28. package/module/config.js +45 -0
  29. package/module/login.js +183 -0
  30. package/module/loginHelper.js +1382 -0
  31. package/module/options.js +52 -0
  32. package/package.json +101 -0
  33. package/src/api/action/addExternalModule.js +25 -0
  34. package/src/api/action/addFriend.js +145 -0
  35. package/src/api/action/changeAvatar.js +137 -0
  36. package/src/api/action/changeBio.js +75 -0
  37. package/src/api/action/changeCover.js +277 -0
  38. package/src/api/action/enableAutoSaveAppState.js +73 -0
  39. package/src/api/action/getCurrentUserID.js +7 -0
  40. package/src/api/action/handleFriendRequest.js +57 -0
  41. package/src/api/action/logout.js +76 -0
  42. package/src/api/action/refreshFb_dtsg.js +48 -0
  43. package/src/api/action/setPostReaction.js +106 -0
  44. package/src/api/action/unfriend.js +54 -0
  45. package/src/api/http/httpGet.js +46 -0
  46. package/src/api/http/httpPost.js +52 -0
  47. package/src/api/http/postFormData.js +47 -0
  48. package/src/api/messaging/addUserToGroup.js +68 -0
  49. package/src/api/messaging/changeAdminStatus.js +126 -0
  50. package/src/api/messaging/changeArchivedStatus.js +55 -0
  51. package/src/api/messaging/changeBlockedStatus.js +48 -0
  52. package/src/api/messaging/changeGroupImage.js +91 -0
  53. package/src/api/messaging/changeNickname.js +70 -0
  54. package/src/api/messaging/changeThreadColor.js +79 -0
  55. package/src/api/messaging/changeThreadEmoji.js +111 -0
  56. package/src/api/messaging/createNewGroup.js +88 -0
  57. package/src/api/messaging/createPoll.js +46 -0
  58. package/src/api/messaging/createThemeAI.js +98 -0
  59. package/src/api/messaging/deleteMessage.js +136 -0
  60. package/src/api/messaging/deleteThread.js +56 -0
  61. package/src/api/messaging/editMessage.js +90 -0
  62. package/src/api/messaging/forwardAttachment.js +57 -0
  63. package/src/api/messaging/forwardMessage.js +134 -0
  64. package/src/api/messaging/getEmojiUrl.js +29 -0
  65. package/src/api/messaging/getFriendsList.js +82 -0
  66. package/src/api/messaging/getMessage.js +829 -0
  67. package/src/api/messaging/getThemePictures.js +62 -0
  68. package/src/api/messaging/handleMessageRequest.js +65 -0
  69. package/src/api/messaging/markAsDelivered.js +57 -0
  70. package/src/api/messaging/markAsRead.js +88 -0
  71. package/src/api/messaging/markAsReadAll.js +49 -0
  72. package/src/api/messaging/markAsSeen.js +61 -0
  73. package/src/api/messaging/muteThread.js +50 -0
  74. package/src/api/messaging/pinMessage.js +115 -0
  75. package/src/api/messaging/removeUserFromGroup.js +62 -0
  76. package/src/api/messaging/resolvePhotoUrl.js +43 -0
  77. package/src/api/messaging/scheduler.js +264 -0
  78. package/src/api/messaging/searchForThread.js +53 -0
  79. package/src/api/messaging/sendBroadcast.js +93 -0
  80. package/src/api/messaging/sendMessage.js +269 -0
  81. package/src/api/messaging/sendTypingIndicator.js +74 -0
  82. package/src/api/messaging/sessionGuard.js +208 -0
  83. package/src/api/messaging/setMessageReaction.js +95 -0
  84. package/src/api/messaging/setTitle.js +124 -0
  85. package/src/api/messaging/shareContact.js +49 -0
  86. package/src/api/messaging/threadColors.js +128 -0
  87. package/src/api/messaging/unsendMessage.js +81 -0
  88. package/src/api/messaging/uploadAttachment.js +523 -0
  89. package/src/api/socket/OldMessage.js +186 -0
  90. package/src/api/socket/core/connectMqtt.js +320 -0
  91. package/src/api/socket/core/emitAuth.js +103 -0
  92. package/src/api/socket/core/getSeqID.js +338 -0
  93. package/src/api/socket/core/getTaskResponseData.js +25 -0
  94. package/src/api/socket/core/parseDelta.js +387 -0
  95. package/src/api/socket/detail/buildStream.js +215 -0
  96. package/src/api/socket/detail/constants.js +28 -0
  97. package/src/api/socket/e2ee/crypto.js +173 -0
  98. package/src/api/socket/e2ee/e2ee/crypto.js +173 -0
  99. package/src/api/socket/e2ee/e2ee/index.js +421 -0
  100. package/src/api/socket/e2ee/e2ee/proto/ArmadilloApplication.proto +281 -0
  101. package/src/api/socket/e2ee/e2ee/proto/ArmadilloICDC.proto +14 -0
  102. package/src/api/socket/e2ee/e2ee/proto/ConsumerApplication.proto +232 -0
  103. package/src/api/socket/e2ee/e2ee/proto/MessageApplication.proto +82 -0
  104. package/src/api/socket/e2ee/e2ee/proto/MessageTransport.proto +77 -0
  105. package/src/api/socket/e2ee/e2ee/proto/WACommon.proto +66 -0
  106. package/src/api/socket/e2ee/e2ee/proto/WAMediaTransport.proto +176 -0
  107. package/src/api/socket/e2ee/e2ee/protocol.js +196 -0
  108. package/src/api/socket/e2ee/e2ee/ratchet.js +219 -0
  109. package/src/api/socket/e2ee/e2ee/store.js +182 -0
  110. package/src/api/socket/e2ee/e2ee/vendor/fb-e2ee.cjs +9162 -0
  111. package/src/api/socket/e2ee/e2ee/vendor/proto/ArmadilloApplication.proto +281 -0
  112. package/src/api/socket/e2ee/e2ee/vendor/proto/ArmadilloICDC.proto +14 -0
  113. package/src/api/socket/e2ee/e2ee/vendor/proto/ConsumerApplication.proto +232 -0
  114. package/src/api/socket/e2ee/e2ee/vendor/proto/MessageApplication.proto +82 -0
  115. package/src/api/socket/e2ee/e2ee/vendor/proto/MessageTransport.proto +77 -0
  116. package/src/api/socket/e2ee/e2ee/vendor/proto/WACommon.proto +66 -0
  117. package/src/api/socket/e2ee/e2ee/vendor/proto/WAMediaTransport.proto +176 -0
  118. package/src/api/socket/e2ee/index.js +437 -0
  119. package/src/api/socket/e2ee/proto/ArmadilloApplication.proto +281 -0
  120. package/src/api/socket/e2ee/proto/ArmadilloICDC.proto +14 -0
  121. package/src/api/socket/e2ee/proto/ConsumerApplication.proto +232 -0
  122. package/src/api/socket/e2ee/proto/MessageApplication.proto +82 -0
  123. package/src/api/socket/e2ee/proto/MessageTransport.proto +77 -0
  124. package/src/api/socket/e2ee/proto/WACommon.proto +66 -0
  125. package/src/api/socket/e2ee/proto/WAMediaTransport.proto +176 -0
  126. package/src/api/socket/e2ee/protocol.js +196 -0
  127. package/src/api/socket/e2ee/ratchet.js +219 -0
  128. package/src/api/socket/e2ee/store.js +182 -0
  129. package/src/api/socket/e2ee/vendor/fb-e2ee.cjs +9162 -0
  130. package/src/api/socket/e2ee/vendor/proto/ArmadilloApplication.proto +281 -0
  131. package/src/api/socket/e2ee/vendor/proto/ArmadilloICDC.proto +14 -0
  132. package/src/api/socket/e2ee/vendor/proto/ConsumerApplication.proto +232 -0
  133. package/src/api/socket/e2ee/vendor/proto/MessageApplication.proto +82 -0
  134. package/src/api/socket/e2ee/vendor/proto/MessageTransport.proto +77 -0
  135. package/src/api/socket/e2ee/vendor/proto/WACommon.proto +66 -0
  136. package/src/api/socket/e2ee/vendor/proto/WAMediaTransport.proto +176 -0
  137. package/src/api/socket/listenE2EE.js +75 -0
  138. package/src/api/socket/listenMqtt.js +551 -0
  139. package/src/api/socket/middleware/index.js +216 -0
  140. package/src/api/socket/sendMessage.js +309 -0
  141. package/src/api/socket/sendMessageMqtt.js +69 -0
  142. package/src/api/threads/getThreadHistory.js +664 -0
  143. package/src/api/threads/getThreadInfo.js +296 -0
  144. package/src/api/threads/getThreadList.js +293 -0
  145. package/src/api/threads/getThreadPictures.js +78 -0
  146. package/src/api/users/getUserID.js +65 -0
  147. package/src/api/users/getUserInfo.js +402 -0
  148. package/src/api/users/getUserInfoV2.js +911 -0
  149. package/src/app/MessengerBot.js +209 -0
  150. package/src/app/MessengerContext.js +32 -0
  151. package/src/app/createFcaClient.js +139 -0
  152. package/src/app/threadInfoRealtimeSync.js +284 -0
  153. package/src/core/sendReqMqtt.js +96 -0
  154. package/src/database/helpers.js +53 -0
  155. package/src/database/models/index.js +88 -0
  156. package/src/database/models/thread.js +50 -0
  157. package/src/database/models/user.js +46 -0
  158. package/src/database/threadData.js +94 -0
  159. package/src/database/userData.js +98 -0
  160. package/src/remote/remoteClient.js +123 -0
  161. package/src/utils/broadcast.js +51 -0
  162. package/src/utils/client.js +10 -0
  163. package/src/utils/clientIdentity.js +118 -0
  164. package/src/utils/constants.js +23 -0
  165. package/src/utils/cookies.js +68 -0
  166. package/src/utils/format/attachment.js +357 -0
  167. package/src/utils/format/cookie.js +9 -0
  168. package/src/utils/format/date.js +50 -0
  169. package/src/utils/format/decode.js +44 -0
  170. package/src/utils/format/delta.js +194 -0
  171. package/src/utils/format/ids.js +64 -0
  172. package/src/utils/format/index.js +64 -0
  173. package/src/utils/format/message.js +88 -0
  174. package/src/utils/format/presence.js +132 -0
  175. package/src/utils/format/readTyp.js +44 -0
  176. package/src/utils/format/thread.js +42 -0
  177. package/src/utils/format/utils.js +141 -0
  178. package/src/utils/headers.js +124 -0
  179. package/src/utils/logger.js +144 -0
  180. package/src/utils/loginParser/autoLogin.js +125 -0
  181. package/src/utils/loginParser/helpers.js +43 -0
  182. package/src/utils/loginParser/index.js +10 -0
  183. package/src/utils/loginParser/parseAndCheckLogin.js +220 -0
  184. package/src/utils/loginParser/textUtils.js +28 -0
  185. package/src/utils/request/client.js +26 -0
  186. package/src/utils/request/config.js +29 -0
  187. package/src/utils/request/defaults.js +46 -0
  188. package/src/utils/request/helpers.js +46 -0
  189. package/src/utils/request/index.js +17 -0
  190. package/src/utils/request/methods.js +163 -0
  191. package/src/utils/request/proxy.js +46 -0
  192. package/src/utils/request/retry.js +77 -0
  193. package/src/utils/request/sanitize.js +49 -0
  194. package/src/utils/utils.js +686 -0
  195. package/src/utils/versionCheck.js +47 -0
  196. package/src/vendor/fca-unofficial/index.js +11 -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,208 @@
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/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
+ var REQUIRED_COOKIE_KEYS = ["c_user", "xs"]; // a session isn't usable without these
23
+
24
+ // Validate that an appstate array actually looks like a usable, well-formed
25
+ // Facebook session before it's allowed to overwrite anything on disk.
26
+ // Guards against persisting a partial/corrupt state (e.g. captured mid-logout)
27
+ // that would replace a good appstate with a broken one.
28
+ function isValidAppState(state) {
29
+ if (!state || !Array.isArray(state) || state.length < MIN_COOKIES) return false;
30
+ var keys = {};
31
+ for (var i = 0; i < state.length; i++) {
32
+ var c = state[i];
33
+ if (!c || typeof c !== "object") return false;
34
+ var key = c.key || c.name;
35
+ if (!key || typeof c.value !== "string" || !c.value) return false;
36
+ keys[key] = c.value;
37
+ }
38
+ for (var j = 0; j < REQUIRED_COOKIE_KEYS.length; j++) {
39
+ if (!keys[REQUIRED_COOKIE_KEYS[j]]) return false;
40
+ }
41
+ return true;
42
+ }
43
+
44
+ module.exports = function (defaultFuncs, api, ctx) {
45
+
46
+ // sessionGuard() attaches by monkey-patching api.sendMessage. If it's
47
+ // invoked more than once for the same api instance (e.g. accidentally
48
+ // called twice), that patch would stack, causing double-saves and,
49
+ // eventually, wrapping api.sendMessage in itself repeatedly. Guard
50
+ // against that here instead of relying on callers not to do it.
51
+ if (ctx._sessionGuardAttached) {
52
+ logger.warn("SessionGuard", "Already active for this session — ignoring duplicate init.");
53
+ return function alreadyActive() {
54
+ return {
55
+ save: api.saveSession,
56
+ stop: api.stopSessionGuard,
57
+ restore: api.restoreSessionBackup
58
+ };
59
+ };
60
+ }
61
+ ctx._sessionGuardAttached = true;
62
+
63
+ function getState() {
64
+ try { return api.getAppState(); } catch (_) { return null; }
65
+ }
66
+
67
+ // Serializes all writes to a given path so a periodic save and a
68
+ // debounced on-send save can never interleave their writes to the same
69
+ // file (the previous version had no such lock, so two concurrent
70
+ // fs.writeFileSync calls to the same path could race).
71
+ var writeLocks = Object.create(null);
72
+
73
+ function withWriteLock(filePath, fn) {
74
+ var prev = writeLocks[filePath] || Promise.resolve();
75
+ var next = prev.catch(function () {}).then(fn);
76
+ writeLocks[filePath] = next.catch(function () {});
77
+ return next;
78
+ }
79
+
80
+ function atomicWriteFileSync(filePath, data) {
81
+ // Write to a temp file in the same directory, then rename. rename()
82
+ // is atomic on the same filesystem, so a crash/kill mid-write can
83
+ // never leave a partially-written, corrupt appstate.json behind -
84
+ // readers either see the old complete file or the new complete file.
85
+ var dir = path.dirname(filePath);
86
+ var tmpPath = path.join(dir, "." + path.basename(filePath) + "." + process.pid + "." + Date.now() + ".tmp");
87
+ fs.writeFileSync(tmpPath, data, "utf8");
88
+ fs.renameSync(tmpPath, filePath);
89
+ }
90
+
91
+ function saveToDiskSync(filePath) {
92
+ var state = getState();
93
+ if (!isValidAppState(state)) {
94
+ logger.warn("SessionGuard", "Skipped save — state looks empty, invalid, or missing required cookies (" + (state ? state.length : 0) + " cookies).");
95
+ return false;
96
+ }
97
+
98
+ // Corruption guard: never write a smaller appstate than what's already on disk
99
+ if (fs.existsSync(filePath)) {
100
+ try {
101
+ var existing = JSON.parse(fs.readFileSync(filePath, "utf8"));
102
+ if (Array.isArray(existing) && state.length < existing.length * 0.8) {
103
+ logger.warn("SessionGuard", "Skipped save — new state has " + state.length + " cookies vs " + existing.length + " on disk (possible truncation).");
104
+ return false;
105
+ }
106
+ // Backup the current valid state before overwriting (also atomic).
107
+ atomicWriteFileSync(filePath + ".bak", JSON.stringify(existing, null, 2));
108
+ } catch (_) {}
109
+ }
110
+
111
+ atomicWriteFileSync(filePath, JSON.stringify(state, null, 2));
112
+ logger.success("SessionGuard", "Session saved → " + filePath + " (" + state.length + " cookies)");
113
+ return true;
114
+ }
115
+
116
+ function saveToDisk(filePath) {
117
+ // Run the actual save inside the per-path lock so concurrent callers
118
+ // (periodic timer vs. post-send debounce) are serialized.
119
+ var result;
120
+ return withWriteLock(filePath, function () {
121
+ try {
122
+ result = saveToDiskSync(filePath);
123
+ } catch (e) {
124
+ logger.error("SessionGuard", "Save failed: " + (e && e.message ? e.message : String(e)));
125
+ result = false;
126
+ }
127
+ return result;
128
+ }).then(function () { return result; });
129
+ }
130
+
131
+ return function sessionGuard(appStatePath, options) {
132
+ options = options || {};
133
+ var interval = options.interval !== undefined ? options.interval : SAVE_INTERVAL_MS;
134
+ var debounce = options.debounce !== undefined ? options.debounce : DEBOUNCE_MS;
135
+
136
+ appStatePath = appStatePath || path.join(process.cwd(), "appstate.json");
137
+
138
+ var lastSave = 0;
139
+ var intervalRef = null;
140
+
141
+ // Periodic save
142
+ if (interval > 0) {
143
+ intervalRef = setInterval(function () {
144
+ logger.info("SessionGuard", "Periodic save...");
145
+ saveToDisk(appStatePath);
146
+ lastSave = Date.now();
147
+ }, interval);
148
+ if (intervalRef.unref) intervalRef.unref(); // don't block process exit
149
+ }
150
+
151
+ // Debounced on-send save
152
+ // Patch sendMessage to auto-save appstate after a successful send
153
+ var originalSendMessage = api.sendMessage;
154
+ api.sendMessage = function () {
155
+ var result = originalSendMessage.apply(this, arguments);
156
+ // After send, debounce-save
157
+ Promise.resolve(result).then(function () {
158
+ if (Date.now() - lastSave > debounce) {
159
+ saveToDisk(appStatePath);
160
+ lastSave = Date.now();
161
+ }
162
+ }).catch(function () {});
163
+ return result;
164
+ };
165
+
166
+ // Expose manual save
167
+ api.saveSession = function (customPath) {
168
+ return saveToDisk(customPath || appStatePath);
169
+ };
170
+
171
+ // Expose restore from backup
172
+ api.restoreSessionBackup = function (customPath) {
173
+ var bakPath = (customPath || appStatePath) + ".bak";
174
+ if (!fs.existsSync(bakPath)) {
175
+ logger.warn("SessionGuard", "No backup file found at " + bakPath);
176
+ return false;
177
+ }
178
+ try {
179
+ var bak = fs.readFileSync(bakPath, "utf8");
180
+ atomicWriteFileSync(customPath || appStatePath, bak);
181
+ logger.success("SessionGuard", "Backup restored from " + bakPath);
182
+ return true;
183
+ } catch (e) {
184
+ logger.error("SessionGuard", "Restore failed: " + e.message);
185
+ return false;
186
+ }
187
+ };
188
+
189
+ // Expose stop
190
+ api.stopSessionGuard = function () {
191
+ if (intervalRef) clearInterval(intervalRef);
192
+ api.sendMessage = originalSendMessage;
193
+ ctx._sessionGuardAttached = false;
194
+ logger.info("SessionGuard", "Stopped.");
195
+ };
196
+
197
+ logger.success(
198
+ "SessionGuard",
199
+ "Active — auto-save every " + Math.round(interval / 60000) + " min → " + appStatePath
200
+ );
201
+
202
+ return {
203
+ save: function (p) { return saveToDisk(p || appStatePath); },
204
+ stop: api.stopSessionGuard,
205
+ restore: api.restoreSessionBackup
206
+ };
207
+ };
208
+ };
@@ -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
+ // ✅ MueidMursalinRifat 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
+ };