fca-nx 7.3.0 → 7.3.5

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/README.md CHANGED
@@ -142,6 +142,12 @@ api.sendMessage("Hello world!", threadID);
142
142
  Bubble effects (`gift`, `fire`, `love`, `textEffect`, `text_effect_ids`) are no longer sent.
143
143
  Passing those keys is ignored. Sending them was a non-browser payload and a common checkpoint/suspend trigger.
144
144
 
145
+ ### Session safety (7.3.5)
146
+ - 7.2.5 reconnected MQTT every hour and published `/browser_close` first. Facebook treated that as the user leaving, so the saved appstate came back logged out. That publish now happens only on a real `stopListening`, and a recycle no longer clears autosave.
147
+ - 7.3.0 never recycled the socket and published a custom `/ping` every 30 seconds. That is not a browser packet (keepalive is MQTT PINGREQ). Leaving it on a socket that never closed was suspending accounts. The custom ping is gone.
148
+ - The socket is soft-recycled about every 6 hours, with jitter, so it is neither an hourly logout nor an immortal connection. Set `cycleMs: 0` in the mqtt options to turn that off.
149
+ - `getUserInfo` uses the cached GraphQL path again unless `antiGetInfo.AntiGetUserInfo` is `true`. The 7.3.0 default could send every lookup to `/chat/user_info/`, which is a spam signal.
150
+
145
151
  ### Session safety (7.2.5)
146
152
  - Default `online` is `false` (MQTT `chat_on` stays off unless you opt in).
147
153
  - `mark_thread_read` is sent only when `autoMarkRead: true`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fca-nx",
3
- "version": "7.3.0",
3
+ "version": "7.3.5",
4
4
  "description": "Facebook Messenger API for Node.js — Fast, Secure, and Feature-Rich",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -20,9 +20,12 @@ const getTaskResponseData = require("./core/getTaskResponseData");
20
20
  const createEmitAuth = require("./core/emitAuth");
21
21
  const createMiddlewareSystem = require("./middleware");
22
22
 
23
- // 7.3.0: auto-cycle disabled by default. The forced MQTT reconnect every hour
24
- // looked like automated behaviour. Set mqtt cycleMs in options to re-enable.
25
- const CYCLE_MS_DEFAULT = 0;
23
+ // 7.3.5: no hourly hard cycle (7.2.5 published /browser_close every hour and
24
+ // the session came back logged out) and no immortal socket (7.3.0 never
25
+ // cycled, and a custom /ping every 30s on that socket got accounts suspended).
26
+ // Soft-recycle the MQTT socket on a long jittered timer. Real keepalive is
27
+ // MQTT PINGREQ (connectMqtt keepalive). Set mqtt cycleMs to 0 to disable.
28
+ const CYCLE_MS_DEFAULT = 6 * 60 * 60 * 1000;
26
29
  const RECONNECT_DELAY_MS_DEFAULT = 3000;
27
30
  const UNSUB_ALL_TIMEOUT_MS = 5000;
28
31
  const MAX_MQTT_RECONNECT_DELAY_MS = 60000;
@@ -216,12 +219,11 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
216
219
  return;
217
220
  }
218
221
 
219
- try {
220
- ctx.mqttClient.publish("/ping", JSON.stringify({ timestamp: Date.now() }), { qos: 0 });
221
- logger("mqtt heartbeat sent", "debug");
222
- } catch (err) {
223
- logger(`mqtt heartbeat error: ${err.message}`, "warn");
224
- }
222
+ // 7.3.5: do not publish a custom "/ping" payload. MQTT keepalive
223
+ // (PINGREQ every 60s in connectMqtt.js) is the real browser
224
+ // signal. A JSON /ping every 30s on a socket that never closed
225
+ // is what 7.3.0 left running, and that pattern suspended accounts.
226
+ // Liveness is tracked from "packetreceive" above.
225
227
  }, conf.heartbeatInterval || HEARTBEAT_INTERVAL_MS);
226
228
  }
227
229
 
@@ -273,7 +275,7 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
273
275
  });
274
276
  }
275
277
 
276
- function endQuietly(next) {
278
+ function endQuietly(next, full) {
277
279
  stopHeartbeat();
278
280
 
279
281
  const finish = () => {
@@ -303,23 +305,28 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
303
305
  ctx.tasks.clear();
304
306
  }
305
307
 
306
- if (ctx._userInfoIntervals && Array.isArray(ctx._userInfoIntervals)) {
307
- ctx._userInfoIntervals.forEach(interval => {
308
- try { clearInterval(interval); } catch (_) { }
309
- });
310
- ctx._userInfoIntervals = [];
311
- }
308
+ // Only a real stopListening tears down appstate autosave, the
309
+ // user-info refresh timers and the scheduler. A soft cycle must
310
+ // leave those running or the saved session goes stale (logout).
311
+ if (full) {
312
+ if (ctx._userInfoIntervals && Array.isArray(ctx._userInfoIntervals)) {
313
+ ctx._userInfoIntervals.forEach(interval => {
314
+ try { clearInterval(interval); } catch (_) { }
315
+ });
316
+ ctx._userInfoIntervals = [];
317
+ }
312
318
 
313
- if (ctx._autoSaveInterval && Array.isArray(ctx._autoSaveInterval)) {
314
- ctx._autoSaveInterval.forEach(interval => {
315
- try { clearInterval(interval); } catch (_) { }
316
- });
317
- ctx._autoSaveInterval = [];
318
- }
319
+ if (ctx._autoSaveInterval && Array.isArray(ctx._autoSaveInterval)) {
320
+ ctx._autoSaveInterval.forEach(interval => {
321
+ try { clearInterval(interval); } catch (_) { }
322
+ });
323
+ ctx._autoSaveInterval = [];
324
+ }
319
325
 
320
- if (ctx._scheduler && typeof ctx._scheduler.destroy === "function") {
321
- try { ctx._scheduler.destroy(); } catch (_) { }
322
- ctx._scheduler = undefined;
326
+ if (ctx._scheduler && typeof ctx._scheduler.destroy === "function") {
327
+ try { ctx._scheduler.destroy(); } catch (_) { }
328
+ ctx._scheduler = undefined;
329
+ }
323
330
  }
324
331
 
325
332
  reconnectAttempts = 0;
@@ -330,7 +337,10 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
330
337
 
331
338
  try {
332
339
  if (ctx.mqttClient) {
333
- if (isConnected()) {
340
+ // /browser_close tells Facebook the user left. Sending it on a
341
+ // routine recycle is what 7.2.5 did every hour, and the account
342
+ // came back logged out. Only a real stop publishes it.
343
+ if (full && isConnected()) {
334
344
  try {
335
345
  ctx.mqttClient.publish("/browser_close", "{}", { qos: 0 });
336
346
  } catch (_) { }
@@ -362,6 +372,23 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
362
372
  }, d);
363
373
  }
364
374
 
375
+ function scheduleSoftCycle() {
376
+ if (ctx._autoCycleTimer) {
377
+ clearTimeout(ctx._autoCycleTimer);
378
+ ctx._autoCycleTimer = null;
379
+ }
380
+ const base = conf.cycleMs;
381
+ if (!base || base <= 0) return;
382
+ // ±20% so the reconnect is not a fixed cron-like interval.
383
+ const jitter = Math.floor((Math.random() - 0.5) * base * 0.4);
384
+ const wait = Math.max(30 * 60 * 1000, base + jitter);
385
+ ctx._autoCycleTimer = setTimeout(() => {
386
+ ctx._autoCycleTimer = null;
387
+ if (!ctx._ending && !ctx._cycling) forceCycle();
388
+ }, wait);
389
+ logger(`mqtt soft-cycle in ${Math.round(wait / 60000)}min`, "info");
390
+ }
391
+
365
392
  function forceCycle() {
366
393
  if (ctx._cycling) {
367
394
  logger("mqtt force cycle already in progress", "warn");
@@ -384,8 +411,9 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
384
411
  ctx._cycling = false;
385
412
  if (conf.reconnectAfterStop || conf.autoReconnect !== false) {
386
413
  delayedReconnect();
414
+ scheduleSoftCycle();
387
415
  }
388
- });
416
+ }, false);
389
417
  });
390
418
  }
391
419
 
@@ -461,7 +489,7 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
461
489
  stopHeartbeat();
462
490
 
463
491
  if (ctx._autoCycleTimer) {
464
- clearInterval(ctx._autoCycleTimer);
492
+ clearTimeout(ctx._autoCycleTimer);
465
493
  ctx._autoCycleTimer = null;
466
494
  logger("mqtt auto-cycle cleared", "info");
467
495
  }
@@ -479,7 +507,7 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
479
507
  if (conf.reconnectAfterStop) {
480
508
  delayedReconnect();
481
509
  }
482
- });
510
+ }, true);
483
511
  });
484
512
  }
485
513
 
@@ -517,16 +545,11 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
517
545
  ctx.t_mqttCalled = false;
518
546
 
519
547
  if (ctx._autoCycleTimer) {
520
- clearInterval(ctx._autoCycleTimer);
548
+ clearTimeout(ctx._autoCycleTimer);
521
549
  ctx._autoCycleTimer = null;
522
550
  }
523
551
 
524
- if (conf.cycleMs && conf.cycleMs > 0) {
525
- ctx._autoCycleTimer = setInterval(forceCycle, conf.cycleMs);
526
- logger(`mqtt auto-cycle enabled ${conf.cycleMs}ms`, "info");
527
- } else {
528
- logger("mqtt auto-cycle disabled", "info");
529
- }
552
+ scheduleSoftCycle();
530
553
 
531
554
  if (!ctx.firstListen || !ctx.lastSeqId) {
532
555
  getSeqIDWrapper();
@@ -122,9 +122,12 @@ module.exports = function (defaultFuncs, api, ctx) {
122
122
  // Read FastConfig-style anti-get-info flag from global config (if available)
123
123
  const cfg = global.fca && global.fca.config;
124
124
  const antiCfg = cfg && cfg.antiGetInfo;
125
- // 7.3.0: on-demand lookup is the default. The background 10s refresh queue made
126
- // many Facebook calls. Set antiGetInfo.AntiGetUserInfo to false to restore it.
127
- const disableAntiUserInfo = !(antiCfg && antiCfg.AntiGetUserInfo === false);
125
+ // 7.3.5: cached GraphQL path is the default again.
126
+ // 7.3.0 flipped this so a missing/odd config hit /chat/user_info/ on every
127
+ // lookup. That endpoint is a known spam signal and was suspending accounts.
128
+ // Set antiGetInfo.AntiGetUserInfo to true only if you explicitly want the
129
+ // uncached legacy endpoint.
130
+ const disableAntiUserInfo = !!(antiCfg && antiCfg.AntiGetUserInfo === true);
128
131
 
129
132
  // Lightweight, Horizon-style implementation without database/queue
130
133
  if (disableAntiUserInfo) {
@@ -1,92 +0,0 @@
1
- "use strict";
2
-
3
- const TEXT_EFFECTS = Object.freeze({
4
- hearts: "1",
5
- heart: "1",
6
- love: "1",
7
- gift: "2",
8
- present: "2",
9
- box: "2",
10
- giftbox: "2",
11
- fire: "3",
12
- flame: "3",
13
- hot: "3",
14
- confetti: "4",
15
- confecti: "4",
16
- party: "4",
17
- celebrate: "4",
18
- celebration: "4",
19
- sparkles: "5",
20
- sparkle: "5",
21
- star: "5",
22
- stars: "5",
23
- magic: "5"
24
- });
25
-
26
- const EFFECT_PROPERTIES = [
27
- "textEffect",
28
- "text_effect",
29
- "text_effect_id",
30
- "textEffectId",
31
- "textEffectID",
32
- "effect",
33
- "effect_id",
34
- "effectID",
35
- "text_effect_name",
36
- "effectName",
37
- "effect_name"
38
- ];
39
-
40
- function toTextEffectId(effect) {
41
- if (effect === null || effect === undefined) return null;
42
- if (typeof effect === "number" && Number.isFinite(effect)) return String(effect);
43
- if (typeof effect !== "string") return null;
44
-
45
- const value = effect.trim();
46
- if (!value) return null;
47
- return TEXT_EFFECTS[value.toLowerCase()] || value;
48
- }
49
-
50
- function getTextEffectId(message) {
51
- if (!message || typeof message !== "object") return null;
52
- for (const property of EFFECT_PROPERTIES) {
53
- if (message[property] !== undefined && message[property] !== null) {
54
- const effectID = toTextEffectId(message[property]);
55
- if (effectID) return effectID;
56
- }
57
- }
58
-
59
- const rawIDs = Array.isArray(message.text_effect_ids)
60
- ? message.text_effect_ids
61
- : [message.text_effect_ids];
62
- for (const rawID of rawIDs) {
63
- const effectID = toTextEffectId(rawID);
64
- if (effectID) return effectID;
65
- }
66
- return null;
67
- }
68
-
69
- function getTextEffectIds(message) {
70
- if (!message || typeof message !== "object") return [];
71
- const rawIDs = Array.isArray(message.text_effect_ids)
72
- ? message.text_effect_ids
73
- : [message.text_effect_ids];
74
- const ids = rawIDs
75
- .map(toTextEffectId)
76
- .filter(Boolean);
77
- // [Hardened7] `effect: "fire"` / `textEffect` / `effectName` only produced the single id; the
78
- // array form (text_effect_ids) stayed empty, and Messenger reads the array. Always send both.
79
- if (!ids.length) {
80
- const single = getTextEffectId(message);
81
- if (single) ids.push(single);
82
- }
83
- return ids;
84
- }
85
-
86
- module.exports = {
87
- EFFECT_PROPERTIES,
88
- TEXT_EFFECTS,
89
- getTextEffectId,
90
- getTextEffectIds,
91
- toTextEffectId
92
- };