fca-nx 6.7.9 → 6.8.1
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.
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fca-nx",
|
|
3
|
-
"version": "6.
|
|
4
|
-
"description": "Facebook Messenger API for Node.js \
|
|
3
|
+
"version": "6.8.1",
|
|
4
|
+
"description": "Facebook Messenger API for Node.js \u2027 hardened sendMessage + listenMqtt (cascade fallback, soft MQTT, anti-reconnect-storm)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"exports": {
|
|
@@ -103,4 +103,4 @@
|
|
|
103
103
|
"sqlite3"
|
|
104
104
|
]
|
|
105
105
|
}
|
|
106
|
-
}
|
|
106
|
+
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
//
|
|
6
6
|
// options:
|
|
7
7
|
// text: message to send (default "👆")
|
|
8
|
+
// effect: text effect name or id (default "confetti"; false/"none" = plain text)
|
|
8
9
|
// unsend: unsend after sending (default true)
|
|
9
10
|
// delay: ms to wait before unsend (default 1500, clamped 500..10000)
|
|
10
11
|
//
|
|
@@ -28,12 +29,17 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
28
29
|
|
|
29
30
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
30
31
|
|
|
31
|
-
const send = (body, threadID) =>
|
|
32
|
+
const send = (body, threadID, effect) =>
|
|
32
33
|
new Promise((resolve, reject) => {
|
|
33
34
|
if (typeof api.sendMessage !== "function") {
|
|
34
35
|
return reject(new Error("bump: api.sendMessage is not available"));
|
|
35
36
|
}
|
|
36
|
-
|
|
37
|
+
const msg = { body };
|
|
38
|
+
if (effect != null && effect !== false && effect !== "none" && effect !== "") {
|
|
39
|
+
msg.effect = effect;
|
|
40
|
+
msg.text_effect_ids = [effect];
|
|
41
|
+
}
|
|
42
|
+
api.sendMessage(msg, threadID, (err, info) => (err ? reject(err) : resolve(info)));
|
|
37
43
|
});
|
|
38
44
|
|
|
39
45
|
const unsend = (messageID, threadID) =>
|
|
@@ -89,12 +95,18 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
89
95
|
}
|
|
90
96
|
|
|
91
97
|
const text = options.text != null ? String(options.text) : "👆";
|
|
98
|
+
let effect = "confetti";
|
|
99
|
+
if (options.effect === false || options.effect === null || options.effect === "none" || options.effect === "") {
|
|
100
|
+
effect = null;
|
|
101
|
+
} else if (options.effect != null) {
|
|
102
|
+
effect = options.effect;
|
|
103
|
+
}
|
|
92
104
|
const doUnsend = options.unsend !== false;
|
|
93
105
|
let delay = Number.isFinite(options.delay) ? Number(options.delay) : 1500;
|
|
94
106
|
if (delay < MIN_DELAY) delay = MIN_DELAY;
|
|
95
107
|
if (delay > MAX_DELAY) delay = MAX_DELAY;
|
|
96
108
|
|
|
97
|
-
const info = await send(text, tid);
|
|
109
|
+
const info = await send(text, tid, effect);
|
|
98
110
|
lastBump.set(tid, Date.now());
|
|
99
111
|
recent.push(Date.now());
|
|
100
112
|
|
|
@@ -14,6 +14,7 @@ const log = require("../../../func/logAdapter");
|
|
|
14
14
|
const { getType } = require("../../utils/format");
|
|
15
15
|
const { isReadableStream } = require("../../utils/constants");
|
|
16
16
|
const { generateOfflineThreadingID } = require("../../utils/format");
|
|
17
|
+
const { getTextEffectId, getTextEffectIds } = require("../../utils/textEffects");
|
|
17
18
|
|
|
18
19
|
module.exports = function (defaultFuncs, api, ctx) {
|
|
19
20
|
const uploadAttachment = require("./uploadAttachment")(defaultFuncs, api, ctx);
|
|
@@ -171,17 +172,14 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
171
172
|
metadata_dataclass: JSON.stringify({ media_accessibility_metadata: { alt_text: null } })
|
|
172
173
|
};
|
|
173
174
|
|
|
174
|
-
|
|
175
|
-
if (
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
if (effectArray.length > 0) {
|
|
183
|
-
payload0.text_effect_ids = effectArray.map(id => String(id));
|
|
184
|
-
}
|
|
175
|
+
const textEffectId = getTextEffectId(m);
|
|
176
|
+
if (textEffectId) payload0.text_effect_id = textEffectId;
|
|
177
|
+
const effectArray = getTextEffectIds(m);
|
|
178
|
+
if (effectArray.length) {
|
|
179
|
+
payload0.text_effect_ids = effectArray.map((id) => {
|
|
180
|
+
const n = Number(id);
|
|
181
|
+
return Number.isFinite(n) && String(n) === String(id) ? n : id;
|
|
182
|
+
});
|
|
185
183
|
}
|
|
186
184
|
|
|
187
185
|
const mentionData = buildMentionData(m, baseBody);
|
|
@@ -20,14 +20,15 @@ const getTaskResponseData = require("./core/getTaskResponseData");
|
|
|
20
20
|
const createEmitAuth = require("./core/emitAuth");
|
|
21
21
|
const createMiddlewareSystem = require("./middleware");
|
|
22
22
|
|
|
23
|
-
const CYCLE_MS_DEFAULT =
|
|
24
|
-
const RECONNECT_DELAY_MS_DEFAULT =
|
|
23
|
+
const CYCLE_MS_DEFAULT = 0; // [Hardened7] auto-cycle OFF. A 1h cycle tears the socket down and opens a new MQTT session — after ~2h that looks like repeated logins and gets the account suspended.
|
|
24
|
+
const RECONNECT_DELAY_MS_DEFAULT = 12000;
|
|
25
25
|
const UNSUB_ALL_TIMEOUT_MS = 5000;
|
|
26
|
-
const MAX_MQTT_RECONNECT_DELAY_MS =
|
|
27
|
-
const MAX_MQTT_RECONNECT_COOLDOWN_MS =
|
|
28
|
-
const MAX_MQTT_RECONNECT_ATTEMPTS =
|
|
29
|
-
const HEARTBEAT_INTERVAL_MS =
|
|
30
|
-
const HEARTBEAT_TIMEOUT_MS =
|
|
26
|
+
const MAX_MQTT_RECONNECT_DELAY_MS = 120000;
|
|
27
|
+
const MAX_MQTT_RECONNECT_COOLDOWN_MS = 45 * 60 * 1000; // long quiet period, do not hammer
|
|
28
|
+
const MAX_MQTT_RECONNECT_ATTEMPTS = 6;
|
|
29
|
+
const HEARTBEAT_INTERVAL_MS = 60000;
|
|
30
|
+
const HEARTBEAT_TIMEOUT_MS = 20000;
|
|
31
|
+
const MIN_FORCE_CYCLE_MS = 10 * 60 * 1000;
|
|
31
32
|
|
|
32
33
|
const parseDelta = createParseDelta({ parseAndCheckLogin });
|
|
33
34
|
const emitAuth = createEmitAuth({ logger });
|
|
@@ -232,27 +233,23 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
|
|
|
232
233
|
}
|
|
233
234
|
|
|
234
235
|
const now = Date.now();
|
|
235
|
-
const limit = (conf.heartbeatTimeout || HEARTBEAT_TIMEOUT_MS) *
|
|
236
|
+
const limit = (conf.heartbeatTimeout || HEARTBEAT_TIMEOUT_MS) * 4;
|
|
236
237
|
if (now - lastPongTime > limit) {
|
|
237
238
|
missedPongs += 1;
|
|
238
|
-
//
|
|
239
|
-
|
|
240
|
-
|
|
239
|
+
// mqtt.js keepalive already sends PINGREQ. A custom /ping every
|
|
240
|
+
// few seconds is not what Messenger web does, and force-cycling
|
|
241
|
+
// on one late pong opens a second session (suspend ~1-2h).
|
|
242
|
+
if (missedPongs >= 3) {
|
|
243
|
+
logger("mqtt heartbeat: silent too long, closing socket once", "warn");
|
|
241
244
|
missedPongs = 0;
|
|
242
|
-
|
|
245
|
+
stopHeartbeat();
|
|
246
|
+
try { ctx.mqttClient.end(true); } catch (_) { }
|
|
243
247
|
return;
|
|
244
248
|
}
|
|
245
|
-
logger("mqtt heartbeat:
|
|
249
|
+
logger("mqtt heartbeat: packet late, waiting", "warn");
|
|
246
250
|
} else {
|
|
247
251
|
missedPongs = 0;
|
|
248
252
|
}
|
|
249
|
-
|
|
250
|
-
try {
|
|
251
|
-
ctx.mqttClient.publish("/ping", JSON.stringify({ timestamp: Date.now() }), { qos: 0 });
|
|
252
|
-
logger("mqtt heartbeat sent", "debug");
|
|
253
|
-
} catch (err) {
|
|
254
|
-
logger(`mqtt heartbeat error: ${err.message}`, "warn");
|
|
255
|
-
}
|
|
256
253
|
}, hbEvery);
|
|
257
254
|
}
|
|
258
255
|
|
|
@@ -304,7 +301,7 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
|
|
|
304
301
|
});
|
|
305
302
|
}
|
|
306
303
|
|
|
307
|
-
function endQuietly(next) {
|
|
304
|
+
function endQuietly(next, soft) {
|
|
308
305
|
stopHeartbeat();
|
|
309
306
|
|
|
310
307
|
const finish = () => {
|
|
@@ -315,11 +312,15 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
|
|
|
315
312
|
} catch (_) { }
|
|
316
313
|
|
|
317
314
|
ctx.mqttClient = undefined;
|
|
318
|
-
ctx.lastSeqId = null;
|
|
319
|
-
ctx.syncToken = undefined;
|
|
320
315
|
ctx.t_mqttCalled = false;
|
|
321
316
|
ctx._ending = false;
|
|
322
317
|
ctx._cycling = false;
|
|
318
|
+
// Soft cycle keeps seq + appstate saver. Wiping them on every
|
|
319
|
+
// reconnect forces a full re-login and looks like a new device.
|
|
320
|
+
if (!soft) {
|
|
321
|
+
ctx.lastSeqId = null;
|
|
322
|
+
ctx.syncToken = undefined;
|
|
323
|
+
}
|
|
323
324
|
|
|
324
325
|
if (ctx._reconnectTimer) {
|
|
325
326
|
clearTimeout(ctx._reconnectTimer);
|
|
@@ -334,23 +335,18 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
|
|
|
334
335
|
ctx.tasks.clear();
|
|
335
336
|
}
|
|
336
337
|
|
|
337
|
-
if (
|
|
338
|
-
ctx._userInfoIntervals.
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
if (ctx._autoSaveInterval && Array.isArray(ctx._autoSaveInterval)) {
|
|
345
|
-
ctx._autoSaveInterval.forEach(interval => {
|
|
346
|
-
try { clearInterval(interval); } catch (_) { }
|
|
347
|
-
});
|
|
348
|
-
ctx._autoSaveInterval = [];
|
|
349
|
-
}
|
|
338
|
+
if (!soft) {
|
|
339
|
+
if (ctx._userInfoIntervals && Array.isArray(ctx._userInfoIntervals)) {
|
|
340
|
+
ctx._userInfoIntervals.forEach(interval => {
|
|
341
|
+
try { clearInterval(interval); } catch (_) { }
|
|
342
|
+
});
|
|
343
|
+
ctx._userInfoIntervals = [];
|
|
344
|
+
}
|
|
350
345
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
346
|
+
if (ctx._scheduler && typeof ctx._scheduler.destroy === "function") {
|
|
347
|
+
try { ctx._scheduler.destroy(); } catch (_) { }
|
|
348
|
+
ctx._scheduler = undefined;
|
|
349
|
+
}
|
|
354
350
|
}
|
|
355
351
|
|
|
356
352
|
reconnectAttempts = 0;
|
|
@@ -405,9 +401,9 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
|
|
|
405
401
|
logger("mqtt force cycle skipped - ending", "warn");
|
|
406
402
|
return;
|
|
407
403
|
}
|
|
408
|
-
// [
|
|
404
|
+
// [Hardened7] minimum 10 min between forced cycles
|
|
409
405
|
const now = Date.now();
|
|
410
|
-
if (ctx._lastForceCycleAt && (now - ctx._lastForceCycleAt) <
|
|
406
|
+
if (ctx._lastForceCycleAt && (now - ctx._lastForceCycleAt) < MIN_FORCE_CYCLE_MS) {
|
|
411
407
|
logger("mqtt force cycle skipped - too soon since last cycle", "warn");
|
|
412
408
|
return;
|
|
413
409
|
}
|
|
@@ -429,7 +425,7 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
|
|
|
429
425
|
|
|
430
426
|
unsubAll(() => {
|
|
431
427
|
try {
|
|
432
|
-
endQuietly(finish);
|
|
428
|
+
endQuietly(finish, true);
|
|
433
429
|
} catch (e) {
|
|
434
430
|
logger(`mqtt force cycle endQuietly error: ${e && e.message ? e.message : e}`, "warn");
|
|
435
431
|
finish();
|
|
@@ -488,11 +484,18 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
|
|
|
488
484
|
});
|
|
489
485
|
|
|
490
486
|
ctx.mqttClient.once("error", (err) => {
|
|
491
|
-
|
|
492
|
-
|
|
487
|
+
const msg = err && err.message ? err.message : String(err || "");
|
|
488
|
+
logger(`mqtt error: ${msg}`, "error");
|
|
489
|
+
if (/blocked the login|checkpoint/i.test(msg)) {
|
|
490
|
+
emitAuth(ctx, api, globalCallback, "login_blocked", msg);
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
// Do NOT forceCycle here. forceCycle + the close handler together
|
|
494
|
+
// open two sessions. One delayed reconnect is enough.
|
|
495
|
+
if (!ctx._ending && ctx.globalOptions.autoReconnect !== false && !isConnected()) {
|
|
493
496
|
if (!isReconnecting) {
|
|
494
497
|
isReconnecting = true;
|
|
495
|
-
|
|
498
|
+
delayedReconnect();
|
|
496
499
|
}
|
|
497
500
|
}
|
|
498
501
|
});
|
|
@@ -176,7 +176,14 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
176
176
|
var textEffectId = getTextEffectId(msg);
|
|
177
177
|
if (textEffectId) payload0.text_effect_id = textEffectId;
|
|
178
178
|
var effectArray = getTextEffectIds(msg);
|
|
179
|
-
if (effectArray.length)
|
|
179
|
+
if (effectArray.length) {
|
|
180
|
+
// Messenger applies the animation only when these are numbers.
|
|
181
|
+
// String ids ("1") are ignored and the text goes out plain.
|
|
182
|
+
payload0.text_effect_ids = effectArray.map(function (id) {
|
|
183
|
+
var n = Number(id);
|
|
184
|
+
return Number.isFinite(n) && String(n) === String(id) ? n : id;
|
|
185
|
+
});
|
|
186
|
+
}
|
|
180
187
|
|
|
181
188
|
if (msg.sticker) {
|
|
182
189
|
payload0.send_type = 2;
|
|
@@ -386,11 +393,11 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
386
393
|
// ---- E2EE text path with cascade fallback ----
|
|
387
394
|
// Text replies to E2EE DMs should use the bridge; if it fails, try MQTT then OldMessage
|
|
388
395
|
// instead of hard-failing (Hardened6).
|
|
396
|
+
// Effects are not part of the E2EE payload. If one is set, skip the
|
|
397
|
+
// bridge and send over MQTT so the effect is not stripped.
|
|
389
398
|
if (isSingleUser && !msg.attachment && !msg.sticker && !msg.location && !msg.emoji &&
|
|
399
|
+
!getTextEffectId(msg) &&
|
|
390
400
|
api.e2ee && typeof api.e2ee.isConnected === "function" && api.e2ee.isConnected()) {
|
|
391
|
-
if (getTextEffectId(msg)) {
|
|
392
|
-
logger.warn("sendMessage", "Text effects are not supported in E2EE DMs - sending plain text. Use a group chat for effects.");
|
|
393
|
-
}
|
|
394
401
|
try {
|
|
395
402
|
var e2eeText = await api.e2ee.sendMessage(
|
|
396
403
|
String(threadID),
|
|
@@ -37,7 +37,12 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
37
37
|
var textEffectId = getTextEffectId(msg);
|
|
38
38
|
if (textEffectId) payload0.text_effect_id = textEffectId;
|
|
39
39
|
var effectArray = getTextEffectIds(msg);
|
|
40
|
-
if (effectArray.length)
|
|
40
|
+
if (effectArray.length) {
|
|
41
|
+
payload0.text_effect_ids = effectArray.map(function (id) {
|
|
42
|
+
var n = Number(id);
|
|
43
|
+
return Number.isFinite(n) && String(n) === String(id) ? n : id;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
41
46
|
|
|
42
47
|
if (msg.sticker) { payload0.send_type = 2; payload0.sticker_id = msg.sticker; }
|
|
43
48
|
if (replyToMessage || msg.replyToMessage) {
|
package/src/utils/textEffects.js
CHANGED
|
@@ -68,12 +68,18 @@ function getTextEffectId(message) {
|
|
|
68
68
|
|
|
69
69
|
function getTextEffectIds(message) {
|
|
70
70
|
if (!message || typeof message !== "object") return [];
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
.
|
|
71
|
+
const raw = message.text_effect_ids;
|
|
72
|
+
const rawIDs = raw == null ? [] : (Array.isArray(raw) ? raw : [raw]);
|
|
73
|
+
const ids = [];
|
|
74
|
+
for (const rawID of rawIDs) {
|
|
75
|
+
const effectID = toTextEffectId(rawID);
|
|
76
|
+
if (effectID && !ids.includes(effectID)) ids.push(effectID);
|
|
77
|
+
}
|
|
78
|
+
// Named fields (effect / effectName / textEffect) must also land in the array.
|
|
79
|
+
// Messenger renders text_effect_ids; a lone text_effect_id is often ignored.
|
|
80
|
+
const primary = getTextEffectId(message);
|
|
81
|
+
if (primary && !ids.includes(primary)) ids.unshift(primary);
|
|
82
|
+
return ids;
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
module.exports = {
|