ayman-fca 1.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 (124) hide show
  1. package/README.md +81 -0
  2. package/func/checkUpdate.js +13 -0
  3. package/func/logAdapter.js +30 -0
  4. package/func/logger.js +66 -0
  5. package/index.d.ts +751 -0
  6. package/index.js +15 -0
  7. package/module/config.js +38 -0
  8. package/module/login.js +111 -0
  9. package/module/loginHelper.js +1296 -0
  10. package/module/options.js +37 -0
  11. package/package.json +78 -0
  12. package/src/api/action/addExternalModule.js +19 -0
  13. package/src/api/action/changeAvatar.js +137 -0
  14. package/src/api/action/changeBio.js +48 -0
  15. package/src/api/action/enableAutoSaveAppState.js +72 -0
  16. package/src/api/action/getCurrentUserID.js +11 -0
  17. package/src/api/action/handleFriendRequest.js +33 -0
  18. package/src/api/action/logout.js +76 -0
  19. package/src/api/action/refreshFb_dtsg.js +62 -0
  20. package/src/api/action/setPostReaction.js +106 -0
  21. package/src/api/action/story.js +118 -0
  22. package/src/api/action/unfriend.js +30 -0
  23. package/src/api/http/httpGet.js +28 -0
  24. package/src/api/http/httpPost.js +32 -0
  25. package/src/api/http/postFormData.js +23 -0
  26. package/src/api/messaging/J +1 -0
  27. package/src/api/messaging/addUserToGroup.js +70 -0
  28. package/src/api/messaging/changeAdminStatus.js +72 -0
  29. package/src/api/messaging/changeArchivedStatus.js +31 -0
  30. package/src/api/messaging/changeBlockedStatus.js +27 -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 +44 -0
  34. package/src/api/messaging/changeThreadEmoji.js +111 -0
  35. package/src/api/messaging/createNewGroup.js +50 -0
  36. package/src/api/messaging/createPoll.js +52 -0
  37. package/src/api/messaging/createThemeAI.js +98 -0
  38. package/src/api/messaging/deleteMessage.js +73 -0
  39. package/src/api/messaging/deleteThread.js +29 -0
  40. package/src/api/messaging/editMessage.js +67 -0
  41. package/src/api/messaging/forwardAttachment.js +55 -0
  42. package/src/api/messaging/forwardMessage.js +73 -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/groupActions.js +119 -0
  48. package/src/api/messaging/handleMessageRequest.js +31 -0
  49. package/src/api/messaging/markAsDelivered.js +31 -0
  50. package/src/api/messaging/markAsRead.js +88 -0
  51. package/src/api/messaging/markAsReadAll.js +28 -0
  52. package/src/api/messaging/markAsSeen.js +30 -0
  53. package/src/api/messaging/muteThread.js +27 -0
  54. package/src/api/messaging/notes.js +101 -0
  55. package/src/api/messaging/removeUserFromGroup.js +51 -0
  56. package/src/api/messaging/resolvePhotoUrl.js +29 -0
  57. package/src/api/messaging/scheduler.js +100 -0
  58. package/src/api/messaging/searchForThread.js +32 -0
  59. package/src/api/messaging/sendMessage.js +270 -0
  60. package/src/api/messaging/sendTypingIndicator.js +62 -0
  61. package/src/api/messaging/setMessageReaction.js +91 -0
  62. package/src/api/messaging/setTitle.js +86 -0
  63. package/src/api/messaging/shareContact.js +47 -0
  64. package/src/api/messaging/threadColors.js +128 -0
  65. package/src/api/messaging/unsendMessage.js +73 -0
  66. package/src/api/messaging/uploadAttachment.js +492 -0
  67. package/src/api/socket/core/connectMqtt.js +259 -0
  68. package/src/api/socket/core/emitAuth.js +79 -0
  69. package/src/api/socket/core/getSeqID.js +170 -0
  70. package/src/api/socket/core/getTaskResponseData.js +27 -0
  71. package/src/api/socket/core/parseDelta.js +377 -0
  72. package/src/api/socket/detail/buildStream.js +215 -0
  73. package/src/api/socket/detail/constants.js +29 -0
  74. package/src/api/socket/listenMqtt.js +377 -0
  75. package/src/api/socket/middleware/index.js +80 -0
  76. package/src/api/threads/getThreadHistory.js +664 -0
  77. package/src/api/threads/getThreadInfo.js +296 -0
  78. package/src/api/threads/getThreadList.js +293 -0
  79. package/src/api/threads/getThreadPictures.js +43 -0
  80. package/src/api/user/J +1 -0
  81. package/src/api/user/getUserID.js +48 -0
  82. package/src/api/user/getUserInfo.js +402 -0
  83. package/src/api/user/getUserInfoV2.js +134 -0
  84. package/src/core/sendReqMqtt.js +69 -0
  85. package/src/database/helpers.js +36 -0
  86. package/src/database/models/index.js +55 -0
  87. package/src/database/models/thread.js +44 -0
  88. package/src/database/models/user.js +39 -0
  89. package/src/database/threadData.js +92 -0
  90. package/src/database/userData.js +88 -0
  91. package/src/remote/remoteClient.js +71 -0
  92. package/src/utils/broadcast.js +62 -0
  93. package/src/utils/client.js +10 -0
  94. package/src/utils/constants.js +53 -0
  95. package/src/utils/cookies.js +73 -0
  96. package/src/utils/format/attachment.js +357 -0
  97. package/src/utils/format/cookie.js +9 -0
  98. package/src/utils/format/date.js +50 -0
  99. package/src/utils/format/decode.js +44 -0
  100. package/src/utils/format/delta.js +194 -0
  101. package/src/utils/format/ids.js +64 -0
  102. package/src/utils/format/index.js +64 -0
  103. package/src/utils/format/message.js +88 -0
  104. package/src/utils/format/presence.js +132 -0
  105. package/src/utils/format/readTyp.js +44 -0
  106. package/src/utils/format/thread.js +42 -0
  107. package/src/utils/format/utils.js +141 -0
  108. package/src/utils/headers.js +96 -0
  109. package/src/utils/loginParser/autoLogin.js +125 -0
  110. package/src/utils/loginParser/helpers.js +43 -0
  111. package/src/utils/loginParser/index.js +10 -0
  112. package/src/utils/loginParser/parseAndCheckLogin.js +220 -0
  113. package/src/utils/loginParser/textUtils.js +28 -0
  114. package/src/utils/request/H +1 -0
  115. package/src/utils/request/client.js +33 -0
  116. package/src/utils/request/config.js +25 -0
  117. package/src/utils/request/defaults.js +40 -0
  118. package/src/utils/request/helpers.js +31 -0
  119. package/src/utils/request/index.js +12 -0
  120. package/src/utils/request/methods.js +92 -0
  121. package/src/utils/request/proxy.js +23 -0
  122. package/src/utils/request/retry.js +87 -0
  123. package/src/utils/request/sanitize.js +41 -0
  124. package/src/utils/sessionKeeper.js +275 -0
@@ -0,0 +1,100 @@
1
+ // ============================================================
2
+ // AYMAN-FCA v2.0 — Message Scheduler
3
+ // © 2025 Ayman. All Rights Reserved.
4
+ // ============================================================
5
+ "use strict";
6
+
7
+ const logger = require("../../../func/logger");
8
+
9
+ module.exports = function(defaultFuncs, api, ctx) {
10
+ if (!ctx._scheduler) ctx._scheduler = createScheduler(api);
11
+ return ctx._scheduler;
12
+ };
13
+
14
+ function createScheduler(api) {
15
+ const jobs = new Map();
16
+ let nextId = 1;
17
+
18
+ function parseWhen(when) {
19
+ if (when instanceof Date) return when.getTime();
20
+ if (typeof when === "number") return when;
21
+ if (typeof when === "string") return new Date(when).getTime();
22
+ throw new Error("when يجب أن يكون Date أو number أو ISO string");
23
+ }
24
+
25
+ function schedule(message, threadID, when, options = {}, callback) {
26
+ if (typeof options === "function") { callback = options; options = {}; }
27
+
28
+ const ts = parseWhen(when);
29
+ const now = Date.now();
30
+ if (ts <= now) {
31
+ const err = new Error("الوقت المحدد في الماضي");
32
+ if (callback) callback(err);
33
+ return null;
34
+ }
35
+
36
+ const id = String(nextId++);
37
+ const delay = ts - now;
38
+
39
+ const timer = setTimeout(async () => {
40
+ const job = jobs.get(id);
41
+ if (!job || job.cancelled) return;
42
+ jobs.delete(id);
43
+
44
+ const targets = Array.isArray(threadID) ? threadID : [threadID];
45
+ for (const tid of targets) {
46
+ try {
47
+ await api.sendMessage(message, tid);
48
+ logger(`[ Scheduler ] رسالة أُرسلت ✅ → ${tid}`, "info");
49
+ if (callback) callback(null, { id, threadID: tid, message });
50
+ } catch (e) {
51
+ logger(`[ Scheduler ] فشل الإرسال → ${tid}: ${e?.message || e}`, "error");
52
+ if (callback) callback(e);
53
+ }
54
+ }
55
+ }, delay);
56
+
57
+ jobs.set(id, { id, message, threadID, timestamp: ts, timer, options, cancelled: false, createdAt: now });
58
+ logger(`[ Scheduler ] جُدولت رسالة #${id} بعد ${Math.round(delay / 1000)}s`, "info");
59
+ return id;
60
+ }
61
+
62
+ function cancel(id) {
63
+ const job = jobs.get(String(id));
64
+ if (!job) return false;
65
+ clearTimeout(job.timer);
66
+ job.cancelled = true;
67
+ jobs.delete(String(id));
68
+ logger(`[ Scheduler ] تم إلغاء الرسالة #${id}`, "info");
69
+ return true;
70
+ }
71
+
72
+ function cancelAll() {
73
+ let count = 0;
74
+ for (const [id, job] of jobs) {
75
+ clearTimeout(job.timer);
76
+ job.cancelled = true;
77
+ count++;
78
+ }
79
+ jobs.clear();
80
+ logger(`[ Scheduler ] تم إلغاء ${count} رسالة`, "info");
81
+ return count;
82
+ }
83
+
84
+ function list() {
85
+ return Array.from(jobs.values()).map(j => ({
86
+ id: j.id,
87
+ threadID: j.threadID,
88
+ timestamp: j.timestamp,
89
+ createdAt: j.createdAt,
90
+ remaining: Math.max(0, j.timestamp - Date.now())
91
+ }));
92
+ }
93
+
94
+ function destroy() {
95
+ cancelAll();
96
+ logger("[ Scheduler ] تم التدمير", "info");
97
+ }
98
+
99
+ return { schedule, cancel, cancelAll, list, destroy };
100
+ }
@@ -0,0 +1,32 @@
1
+ // ============================================================
2
+ // AYMAN-FCA v2.0 — Search For Thread
3
+ // © 2025 Ayman. All Rights Reserved.
4
+ // ============================================================
5
+ "use strict";
6
+
7
+ const { parseAndCheckLogin } = require("../../utils/client");
8
+ const { formatThread } = require("../../utils/format");
9
+
10
+ module.exports = function(defaultFuncs, api, ctx) {
11
+ return function searchForThread(name, callback) {
12
+ let resolve, reject;
13
+ const p = new Promise((res, rej) => { resolve = res; reject = rej; });
14
+ callback = callback || ((err, data) => err ? reject(err) : resolve(data));
15
+
16
+ defaultFuncs.post(
17
+ "https://www.facebook.com/ajax/mercury/search_threads.php",
18
+ ctx.jar,
19
+ { client: "web_messenger", query: name, offset: 0, limit: 21, index: "fbid" }
20
+ )
21
+ .then(parseAndCheckLogin(ctx, defaultFuncs))
22
+ .then(res => {
23
+ if (res.error) throw res;
24
+ const threads = res.payload?.mercury_payload?.threads;
25
+ if (!threads) return callback({ error: `لم يُعثر على "${name}"` });
26
+ callback(null, threads.map(formatThread));
27
+ })
28
+ .catch(err => callback(err));
29
+
30
+ return p;
31
+ };
32
+ };
@@ -0,0 +1,270 @@
1
+ /**
2
+ * Create by Donix-VN (DongDev)
3
+ * Don't change credit
4
+ * Send a message using MQTT.
5
+ * @param {string} text - The text of the message to send.
6
+ * @param {string} threadID - The ID of the thread to send the message to.
7
+ * @param {string} [msgReplace] - Optional. The message ID of the message to replace.
8
+ * @param {Array<Buffer|Stream>} [attachments] - Optional. The attachments to send with the message.
9
+ * @param {function} [callback] - Optional. The callback function to call when the message is sent.
10
+ * @returns {Promise<object>} A promise that resolves with the bodies of the sent message.
11
+ */
12
+
13
+ "use strict";
14
+ const log = require("../../../func/logAdapter");
15
+ const { getType } = require("../../utils/format");
16
+ const { isReadableStream } = require("../../utils/constants");
17
+ const { generateOfflineThreadingID } = require("../../utils/format");
18
+
19
+ module.exports = function (defaultFuncs, api, ctx) {
20
+ const uploadAttachment = require("./uploadAttachment")(defaultFuncs, api, ctx);
21
+ const hasLinks = s => typeof s === "string" && /(https?:\/\/|www\.|t\.me\/|fb\.me\/|youtu\.be\/|facebook\.com\/|youtube\.com\/)/i.test(s);
22
+ const emojiSizes = { small: 1, medium: 2, large: 3 };
23
+
24
+ function extractIdsFromPayload(payload) {
25
+ let messageID = null;
26
+ let threadID = null;
27
+ function walk(n) {
28
+ if (Array.isArray(n)) {
29
+ if (n[0] === 5 && (n[1] === "replaceOptimsiticMessage" || n[1] === "replaceOptimisticMessage")) {
30
+ messageID = String(n[3]);
31
+ }
32
+ if (n[0] === 5 && n[1] === "writeCTAIdToThreadsTable") {
33
+ const a = n[2];
34
+ if (Array.isArray(a) && a[0] === 19) threadID = String(a[1]);
35
+ }
36
+ for (const x of n) walk(x);
37
+ }
38
+ }
39
+ walk(payload?.step);
40
+ return { threadID, messageID };
41
+ }
42
+
43
+ function publishWithAck(content, text, reqID, callback) {
44
+ return new Promise((resolve, reject) => {
45
+ // Ensure MQTT client is available before using it
46
+ if (!ctx.mqttClient || typeof ctx.mqttClient.on !== "function" || typeof ctx.mqttClient.publish !== "function") {
47
+ const err = new Error("MQTT client is not initialized");
48
+ log.error("sendMessageMqtt", err);
49
+ callback && callback(err);
50
+ return reject(err);
51
+ }
52
+
53
+ // Remove default max listeners limit to avoid MaxListenersExceededWarning
54
+ if (typeof ctx.mqttClient.setMaxListeners === "function") {
55
+ ctx.mqttClient.setMaxListeners(0);
56
+ }
57
+
58
+ let done = false;
59
+ const cleanup = () => {
60
+ if (done) return;
61
+ done = true;
62
+ ctx.mqttClient.removeListener("message", handleRes);
63
+ };
64
+ const handleRes = (topic, message) => {
65
+ if (topic !== "/ls_resp") return;
66
+ let jsonMsg;
67
+ try {
68
+ jsonMsg = JSON.parse(message.toString());
69
+ jsonMsg.payload = JSON.parse(jsonMsg.payload);
70
+ } catch {
71
+ return;
72
+ }
73
+ if (jsonMsg.request_id !== reqID) return;
74
+ const { threadID, messageID } = extractIdsFromPayload(jsonMsg.payload);
75
+ const bodies = { body: text || null, messageID, threadID };
76
+ cleanup();
77
+ callback && callback(undefined, bodies);
78
+ resolve(bodies);
79
+ };
80
+ ctx.mqttClient.on("message", handleRes);
81
+ ctx.mqttClient.publish("/ls_req", JSON.stringify(content), { qos: 1, retain: false }, err => {
82
+ if (err) {
83
+ cleanup();
84
+ callback && callback(err);
85
+ reject(err);
86
+ }
87
+ });
88
+ setTimeout(() => {
89
+ if (done) return;
90
+ cleanup();
91
+ const err = { error: "Timeout waiting for ACK" };
92
+ callback && callback(err);
93
+ reject(err);
94
+ }, 15000);
95
+ });
96
+ }
97
+
98
+ function buildMentionData(msg, baseBody) {
99
+ if (!msg.mentions || !Array.isArray(msg.mentions) || !msg.mentions.length) return null;
100
+ const base = typeof baseBody === "string" ? baseBody : "";
101
+ const ids = [];
102
+ const offsets = [];
103
+ const lengths = [];
104
+ const types = [];
105
+ let cursor = 0;
106
+ for (const m of msg.mentions) {
107
+ const raw = String(m.tag || "");
108
+ const name = raw.replace(/^@+/, "");
109
+ const start = Number.isInteger(m.fromIndex) ? m.fromIndex : cursor;
110
+ let idx = base.indexOf(raw, start);
111
+ let adj = 0;
112
+ if (idx === -1) {
113
+ idx = base.indexOf(name, start);
114
+ adj = 0;
115
+ } else {
116
+ adj = raw.length - name.length;
117
+ }
118
+ if (idx < 0) {
119
+ idx = 0;
120
+ adj = 0;
121
+ }
122
+ const off = idx + adj;
123
+ ids.push(String(m.id || 0));
124
+ offsets.push(off);
125
+ lengths.push(name.length);
126
+ types.push("p");
127
+ cursor = off + name.length;
128
+ }
129
+ return {
130
+ mention_ids: ids.join(","),
131
+ mention_offsets: offsets.join(","),
132
+ mention_lengths: lengths.join(","),
133
+ mention_types: types.join(",")
134
+ };
135
+ }
136
+
137
+ function coerceMsg(x) {
138
+ if (x == null) return { body: "" };
139
+ if (typeof x === "string") return { body: x };
140
+ if (typeof x === "object") return x;
141
+ return { body: String(x) };
142
+ }
143
+
144
+ return async function sendMessageMqtt(msg, threadID, callback, replyToMessage) {
145
+ if (typeof threadID === "function") return threadID({ error: "Pass a threadID as a second argument." });
146
+ if (typeof callback === "string" && !replyToMessage) {
147
+ replyToMessage = callback;
148
+ callback = () => { };
149
+ }
150
+ if (typeof callback !== "function") callback = () => { };
151
+ if (!threadID) {
152
+ const err = { error: "threadID is required" };
153
+ callback(err);
154
+ throw err;
155
+ }
156
+
157
+ const m = coerceMsg(msg);
158
+ const baseBody = m.body != null ? String(m.body) : "";
159
+ const reqID = Math.floor(100 + Math.random() * 900);
160
+ const epoch = (BigInt(Date.now()) << 22n).toString();
161
+
162
+ const payload0 = {
163
+ thread_id: String(threadID),
164
+ otid: generateOfflineThreadingID(),
165
+ source: 2097153,
166
+ send_type: 1,
167
+ sync_group: 1,
168
+ mark_thread_read: 1,
169
+ text: baseBody === "" ? null : baseBody,
170
+ initiating_source: 0,
171
+ skip_url_preview_gen: 0,
172
+ text_has_links: hasLinks(baseBody) ? 1 : 0,
173
+ multitab_env: 0,
174
+ metadata_dataclass: JSON.stringify({ media_accessibility_metadata: { alt_text: null } })
175
+ };
176
+
177
+ const mentionData = buildMentionData(m, baseBody);
178
+ if (mentionData) payload0.mention_data = mentionData;
179
+
180
+ if (m.sticker) {
181
+ payload0.send_type = 2;
182
+ payload0.sticker_id = m.sticker;
183
+ }
184
+
185
+ if (m.emoji) {
186
+ const size = !isNaN(m.emojiSize) ? Number(m.emojiSize) : emojiSizes[m.emojiSize || "small"] || 1;
187
+ payload0.send_type = 1;
188
+ payload0.text = m.emoji;
189
+ payload0.hot_emoji_size = Math.min(3, Math.max(1, size));
190
+ }
191
+
192
+ if (m.location && m.location.latitude != null && m.location.longitude != null) {
193
+ payload0.send_type = 1;
194
+ payload0.location_data = {
195
+ coordinates: { latitude: m.location.latitude, longitude: m.location.longitude },
196
+ is_current_location: !!m.location.current,
197
+ is_live_location: !!m.location.live
198
+ };
199
+ }
200
+
201
+ if (replyToMessage) {
202
+ payload0.reply_metadata = { reply_source_id: replyToMessage, reply_source_type: 1, reply_type: 0 };
203
+ }
204
+
205
+ if (m.attachment) {
206
+ payload0.send_type = 3;
207
+ if (payload0.text === "") payload0.text = null;
208
+ payload0.attachment_fbids = [];
209
+ let list = m.attachment;
210
+ if (getType(list) !== "Array") list = [list];
211
+ const idsFromPairs = [];
212
+ const streams = [];
213
+ for (const it of list) {
214
+ if (Array.isArray(it) && typeof it[0] === "string") {
215
+ idsFromPairs.push(String(it[1]));
216
+ } else if (isReadableStream(it)) {
217
+ streams.push(it);
218
+ }
219
+ }
220
+ if (idsFromPairs.length) payload0.attachment_fbids.push(...idsFromPairs);
221
+ if (streams.length) {
222
+ try {
223
+ const files = await uploadAttachment(streams);
224
+ for (const file of files) {
225
+ const key = Object.keys(file)[0];
226
+ payload0.attachment_fbids.push(file[key]);
227
+ }
228
+ } catch (err) {
229
+ log.error("uploadAttachment", err);
230
+ callback(err);
231
+ throw err;
232
+ }
233
+ }
234
+ }
235
+
236
+ const content = {
237
+ app_id: "2220391788200892",
238
+ payload: {
239
+ tasks: [
240
+ {
241
+ label: "46",
242
+ payload: payload0,
243
+ queue_name: String(threadID),
244
+ task_id: 400,
245
+ failure_count: null
246
+ },
247
+ {
248
+ label: "21",
249
+ payload: {
250
+ thread_id: String(threadID),
251
+ last_read_watermark_ts: Date.now(),
252
+ sync_group: 1
253
+ },
254
+ queue_name: String(threadID),
255
+ task_id: 401,
256
+ failure_count: null
257
+ }
258
+ ],
259
+ epoch_id: epoch,
260
+ version_id: "24804310205905615",
261
+ data_trace_id: "#" + Buffer.from(String(Math.random())).toString("base64").replace(/=+$/g, "")
262
+ },
263
+ request_id: reqID,
264
+ type: 3
265
+ };
266
+ content.payload.tasks.forEach(t => (t.payload = JSON.stringify(t.payload)));
267
+ content.payload = JSON.stringify(content.payload);
268
+ return publishWithAck(content, baseBody, reqID, callback);
269
+ };
270
+ };
@@ -0,0 +1,62 @@
1
+ // ============================================================
2
+ // AYMAN-FCA v2.0 — Send Typing Indicator
3
+ // © 2025 Ayman. All Rights Reserved.
4
+ // ============================================================
5
+ "use strict";
6
+
7
+ const { getType } = require("../../utils/format");
8
+
9
+ module.exports = function(defaultFuncs, api, ctx) {
10
+ return function sendTypingIndicator(threadID, isTyping, options, callback) {
11
+ let resolve, reject;
12
+ const p = new Promise((res, rej) => { resolve = res; reject = rej; });
13
+
14
+ if (getType(options) === "Function" || getType(options) === "AsyncFunction") {
15
+ callback = options; options = {};
16
+ }
17
+ options = options || {};
18
+ callback = callback || ((err, data) => err ? reject(err) : resolve(data));
19
+
20
+ if (!threadID) return callback(new Error("threadID مطلوب"));
21
+ if (!ctx.mqttClient) return callback(new Error("AYMAN-FCA: MQTT غير متصل"));
22
+
23
+ if (typeof ctx.wsReqNumber !== "number") ctx.wsReqNumber = 0;
24
+
25
+ const ids = Array.isArray(threadID) ? threadID : [threadID];
26
+
27
+ ids.forEach(tid => {
28
+ const isGroup = getType(tid) !== "Array" ? 1 : 0;
29
+ const threadType = isGroup ? 2 : 1;
30
+ const duration = options.duration || 10000;
31
+ const attribution= options.type || 0;
32
+
33
+ const publish = (typing) => {
34
+ ctx.mqttClient.publish("/ls_req", JSON.stringify({
35
+ app_id: "772021112871879",
36
+ payload: JSON.stringify({
37
+ label: "3",
38
+ payload: JSON.stringify({
39
+ thread_key: parseInt(tid),
40
+ is_group_thread: isGroup,
41
+ is_typing: typing ? 1 : 0,
42
+ attribution,
43
+ sync_group: 1,
44
+ thread_type: threadType
45
+ }),
46
+ version: "8965252033599983"
47
+ }),
48
+ request_id: ++ctx.wsReqNumber,
49
+ type: 4
50
+ }), { qos: 1, retain: false });
51
+ };
52
+
53
+ publish(isTyping);
54
+ if (isTyping && options.autoStop !== false) {
55
+ setTimeout(() => publish(false), duration);
56
+ }
57
+ });
58
+
59
+ callback(null, true);
60
+ return p;
61
+ };
62
+ };
@@ -0,0 +1,91 @@
1
+ // ============================================================
2
+ // AYMAN-FCA v2.0 — Set Message Reaction
3
+ // © 2025 Ayman. All Rights Reserved.
4
+ // ============================================================
5
+ "use strict";
6
+
7
+ const logger = require("../../../func/logger");
8
+ const { generateOfflineThreadingID, getCurrentTimestamp } = require("../../utils/format");
9
+
10
+ module.exports = function(defaultFuncs, api, ctx) {
11
+ return function setMessageReaction(reaction, messageID, threadID, callback, forceCustomReaction) {
12
+ if (typeof threadID === "function") { forceCustomReaction = callback; callback = threadID; threadID = undefined; }
13
+ else if (typeof threadID === "boolean") { forceCustomReaction = threadID; threadID = undefined; }
14
+ else if (typeof callback === "boolean") { forceCustomReaction = callback; callback = undefined; }
15
+
16
+ const cb = typeof callback === "function" ? callback : undefined;
17
+
18
+ return new Promise((resolve, reject) => {
19
+ if (!ctx.mqttClient) {
20
+ const err = new Error("AYMAN-FCA: MQTT غير متصل");
21
+ cb?.(err); return reject(err);
22
+ }
23
+ if (reaction === undefined || reaction === null || !messageID || !threadID) {
24
+ const err = new Error("reaction و messageID و threadID مطلوبة");
25
+ cb?.(err); return reject(err);
26
+ }
27
+
28
+ if (typeof ctx.wsReqNumber !== "number") ctx.wsReqNumber = 0;
29
+ if (typeof ctx.wsTaskNumber !== "number") ctx.wsTaskNumber = 0;
30
+ const reqID = ++ctx.wsReqNumber;
31
+ const taskID = ++ctx.wsTaskNumber;
32
+
33
+ const content = {
34
+ app_id: "2220391788200892",
35
+ payload: JSON.stringify({
36
+ epoch_id: parseInt(generateOfflineThreadingID()),
37
+ tasks: [{
38
+ failure_count: null,
39
+ label: "29",
40
+ payload: JSON.stringify({
41
+ thread_key: threadID,
42
+ timestamp_ms: getCurrentTimestamp(),
43
+ message_id: messageID,
44
+ reaction,
45
+ actor_id: ctx.userID,
46
+ reaction_style: forceCustomReaction ? 1 : null,
47
+ sync_group: 1,
48
+ send_attribution: 65537,
49
+ dataclass_params: null,
50
+ attachment_fbid: null
51
+ }),
52
+ queue_name: "reaction:" + messageID,
53
+ task_id: taskID
54
+ }],
55
+ version_id: "24585299697835063"
56
+ }),
57
+ request_id: reqID,
58
+ type: 3
59
+ };
60
+
61
+ let done = false;
62
+ const timer = setTimeout(() => {
63
+ if (done) return; done = true;
64
+ ctx.mqttClient?.removeListener("message", handleRes);
65
+ cb?.(null, { success: true }); resolve({ success: true });
66
+ }, 10000);
67
+
68
+ const handleRes = (topic, message) => {
69
+ if (topic !== "/ls_resp") return;
70
+ let msg;
71
+ try { msg = JSON.parse(message.toString()); msg.payload = JSON.parse(msg.payload); } catch { return; }
72
+ if (msg.request_id !== reqID) return;
73
+ if (done) return; done = true;
74
+ clearTimeout(timer);
75
+ ctx.mqttClient?.removeListener("message", handleRes);
76
+ cb?.(null, { success: true }); resolve({ success: true });
77
+ };
78
+
79
+ ctx.mqttClient.on("message", handleRes);
80
+ ctx.mqttClient.publish("/ls_req", JSON.stringify(content), { qos: 1, retain: false }, err => {
81
+ if (err) {
82
+ if (done) return; done = true;
83
+ clearTimeout(timer);
84
+ ctx.mqttClient?.removeListener("message", handleRes);
85
+ logger("setMessageReaction: " + err, "error");
86
+ cb?.(err); reject(err);
87
+ }
88
+ });
89
+ });
90
+ };
91
+ };
@@ -0,0 +1,86 @@
1
+ // ============================================================
2
+ // AYMAN-FCA v2.0 — Set Thread Title
3
+ // © 2025 Ayman. All Rights Reserved.
4
+ // ============================================================
5
+ "use strict";
6
+
7
+ const log = require("../../../func/logAdapter");
8
+ const { generateOfflineThreadingID, getType } = require("../../utils/format");
9
+ const { parseAndCheckLogin } = require("../../utils/client");
10
+
11
+ module.exports = function(defaultFuncs, api, ctx) {
12
+
13
+ function setTitleMqtt(newTitle, threadID, callback) {
14
+ if (!ctx.mqttClient) throw new Error("AYMAN-FCA: MQTT غير متصل");
15
+ if (typeof ctx.wsReqNumber !== "number") ctx.wsReqNumber = 0;
16
+ const reqID = ++ctx.wsReqNumber;
17
+
18
+ let resolve, reject;
19
+ const p = new Promise((res, rej) => { resolve = res; reject = rej; });
20
+ const done = (err, data) => {
21
+ if (callback) callback(err, data);
22
+ err ? reject(err) : resolve(data);
23
+ };
24
+
25
+ const form = JSON.stringify({
26
+ app_id: "2220391788200892",
27
+ payload: JSON.stringify({
28
+ epoch_id: generateOfflineThreadingID(),
29
+ tasks: [{
30
+ failure_count: null,
31
+ label: "32",
32
+ payload: JSON.stringify({ thread_key: threadID, thread_name: newTitle, sync_group: 1 }),
33
+ queue_name: String(threadID),
34
+ task_id: Math.random() * 1001 << 0
35
+ }],
36
+ version_id: "8798795233522156"
37
+ }),
38
+ request_id: reqID,
39
+ type: 3
40
+ });
41
+
42
+ ctx.mqttClient.publish("/ls_req", form, { qos: 1, retain: false }, err => {
43
+ if (err) return done(err);
44
+ done(null, { success: true });
45
+ });
46
+ return p;
47
+ }
48
+
49
+ function setTitleHttp(newTitle, threadID, callback) {
50
+ let resolve, reject;
51
+ const p = new Promise((res, rej) => { resolve = res; reject = rej; });
52
+ callback = callback || (err => err ? reject(err) : resolve());
53
+
54
+ const form = {
55
+ client: "mercury",
56
+ action_type: "ma-type:log-message",
57
+ author: `fbid:${ctx.userID}`,
58
+ timestamp: Date.now(),
59
+ offline_threading_id: generateOfflineThreadingID(),
60
+ thread_fbid: threadID,
61
+ thread_name: newTitle,
62
+ thread_id: threadID,
63
+ log_message_type: "log:thread-name"
64
+ };
65
+
66
+ defaultFuncs.post("https://www.facebook.com/messaging/set_thread_name/", ctx.jar, form)
67
+ .then(parseAndCheckLogin(ctx, defaultFuncs))
68
+ .then(res => {
69
+ if (res.error === 1545012) throw { error: "لا يمكن تغيير العنوان: لست عضواً في المحادثة" };
70
+ if (res.error === 1545003) throw { error: "لا يمكن تغيير عنوان محادثة فردية" };
71
+ if (res.error) throw res;
72
+ callback();
73
+ })
74
+ .catch(err => { log.error("setTitle", err); callback(err); });
75
+
76
+ return p;
77
+ }
78
+
79
+ return function setTitle(newTitle, threadID, callback) {
80
+ if (ctx.mqttClient) {
81
+ try { return setTitleMqtt(newTitle, threadID, callback); }
82
+ catch (_) { return setTitleHttp(newTitle, threadID, callback); }
83
+ }
84
+ return setTitleHttp(newTitle, threadID, callback);
85
+ };
86
+ };
@@ -0,0 +1,47 @@
1
+ // ============================================================
2
+ // AYMAN-FCA v2.0 — Share Contact
3
+ // © 2025 Ayman. All Rights Reserved.
4
+ // ============================================================
5
+ "use strict";
6
+
7
+ const { generateOfflineThreadingID } = require("../../utils/format");
8
+
9
+ module.exports = function(defaultFuncs, api, ctx) {
10
+ return function shareContact(text, senderID, threadID, callback) {
11
+ let resolve, reject;
12
+ const p = new Promise((res, rej) => { resolve = res; reject = rej; });
13
+ callback = callback || ((err, data) => err ? reject(err) : resolve(data));
14
+
15
+ if (!ctx.mqttClient) return callback(new Error("AYMAN-FCA: MQTT غير متصل"));
16
+
17
+ const form = JSON.stringify({
18
+ app_id: "2220391788200892",
19
+ payload: JSON.stringify({
20
+ tasks: [{
21
+ label: "359",
22
+ payload: JSON.stringify({
23
+ contact_id: senderID,
24
+ sync_group: 1,
25
+ text: text || "",
26
+ thread_id: threadID
27
+ }),
28
+ queue_name: "messenger_contact_sharing",
29
+ task_id: (Math.random() * 1001) << 0,
30
+ failure_count: null
31
+ }],
32
+ epoch_id: generateOfflineThreadingID(),
33
+ version_id: "7214102258676893"
34
+ }),
35
+ request_id: ++ctx.wsReqNumber,
36
+ type: 3
37
+ });
38
+
39
+ ctx.mqttClient.publish("/ls_req", form, { qos: 1, retain: false }, err => {
40
+ if (err) return callback(err);
41
+ callback(null, { success: true });
42
+ resolve({ success: true });
43
+ });
44
+
45
+ return p;
46
+ };
47
+ };