fca-nx 7.2.5 → 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/func/logger.js CHANGED
@@ -126,9 +126,27 @@ function formatMessage(text) {
126
126
  .replace(/\n+/g, "\n");
127
127
  }
128
128
 
129
- module.exports = (text, type = "info") => {
129
+ // 7.3.0 quiet logs: when config.json has "quietLogs": true (or FCA_NX_QUIET=1),
130
+ // info/debug/success lines are hidden. Warnings and errors always show.
131
+ // FCA_NX_DEBUG=1 turns everything back on. The bot can call
132
+ // require("fca-nx/func/logger").setQuiet(false) to change it at runtime.
133
+ let quietOverride = null;
134
+ const QUIET_HIDDEN = { info: true, debug: true, success: true };
135
+ function isQuiet() {
136
+ if (process.env.FCA_NX_DEBUG === "1") return false;
137
+ if (quietOverride !== null) return quietOverride;
138
+ try {
139
+ const c = global.fca && global.fca.config;
140
+ if (c && c.quietLogs === true) return true;
141
+ } catch (_) {}
142
+ return process.env.FCA_NX_QUIET === "1";
143
+ }
144
+ const logFn = (text, type = "info") => {
145
+ if (isQuiet() && QUIET_HIDDEN[type]) return;
130
146
  const message = formatMessage(text);
131
147
  const prefix = formatPrefix(type);
132
148
 
133
149
  process.stderr.write(`${prefix} ${co(">")} ${message}\n`);
134
150
  };
151
+ logFn.setQuiet = (v) => { quietOverride = v === null ? null : !!v; };
152
+ module.exports = logFn;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fca-nx",
3
- "version": "7.2.5",
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,7 +20,12 @@ 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 = 60 * 60 * 1000;
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;
24
29
  const RECONNECT_DELAY_MS_DEFAULT = 3000;
25
30
  const UNSUB_ALL_TIMEOUT_MS = 5000;
26
31
  const MAX_MQTT_RECONNECT_DELAY_MS = 60000;
@@ -214,12 +219,11 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
214
219
  return;
215
220
  }
216
221
 
217
- try {
218
- ctx.mqttClient.publish("/ping", JSON.stringify({ timestamp: Date.now() }), { qos: 0 });
219
- logger("mqtt heartbeat sent", "debug");
220
- } catch (err) {
221
- logger(`mqtt heartbeat error: ${err.message}`, "warn");
222
- }
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.
223
227
  }, conf.heartbeatInterval || HEARTBEAT_INTERVAL_MS);
224
228
  }
225
229
 
@@ -271,7 +275,7 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
271
275
  });
272
276
  }
273
277
 
274
- function endQuietly(next) {
278
+ function endQuietly(next, full) {
275
279
  stopHeartbeat();
276
280
 
277
281
  const finish = () => {
@@ -301,23 +305,28 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
301
305
  ctx.tasks.clear();
302
306
  }
303
307
 
304
- if (ctx._userInfoIntervals && Array.isArray(ctx._userInfoIntervals)) {
305
- ctx._userInfoIntervals.forEach(interval => {
306
- try { clearInterval(interval); } catch (_) { }
307
- });
308
- ctx._userInfoIntervals = [];
309
- }
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
+ }
310
318
 
311
- if (ctx._autoSaveInterval && Array.isArray(ctx._autoSaveInterval)) {
312
- ctx._autoSaveInterval.forEach(interval => {
313
- try { clearInterval(interval); } catch (_) { }
314
- });
315
- ctx._autoSaveInterval = [];
316
- }
319
+ if (ctx._autoSaveInterval && Array.isArray(ctx._autoSaveInterval)) {
320
+ ctx._autoSaveInterval.forEach(interval => {
321
+ try { clearInterval(interval); } catch (_) { }
322
+ });
323
+ ctx._autoSaveInterval = [];
324
+ }
317
325
 
318
- if (ctx._scheduler && typeof ctx._scheduler.destroy === "function") {
319
- try { ctx._scheduler.destroy(); } catch (_) { }
320
- ctx._scheduler = undefined;
326
+ if (ctx._scheduler && typeof ctx._scheduler.destroy === "function") {
327
+ try { ctx._scheduler.destroy(); } catch (_) { }
328
+ ctx._scheduler = undefined;
329
+ }
321
330
  }
322
331
 
323
332
  reconnectAttempts = 0;
@@ -328,7 +337,10 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
328
337
 
329
338
  try {
330
339
  if (ctx.mqttClient) {
331
- 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()) {
332
344
  try {
333
345
  ctx.mqttClient.publish("/browser_close", "{}", { qos: 0 });
334
346
  } catch (_) { }
@@ -360,6 +372,23 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
360
372
  }, d);
361
373
  }
362
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
+
363
392
  function forceCycle() {
364
393
  if (ctx._cycling) {
365
394
  logger("mqtt force cycle already in progress", "warn");
@@ -382,8 +411,9 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
382
411
  ctx._cycling = false;
383
412
  if (conf.reconnectAfterStop || conf.autoReconnect !== false) {
384
413
  delayedReconnect();
414
+ scheduleSoftCycle();
385
415
  }
386
- });
416
+ }, false);
387
417
  });
388
418
  }
389
419
 
@@ -459,7 +489,7 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
459
489
  stopHeartbeat();
460
490
 
461
491
  if (ctx._autoCycleTimer) {
462
- clearInterval(ctx._autoCycleTimer);
492
+ clearTimeout(ctx._autoCycleTimer);
463
493
  ctx._autoCycleTimer = null;
464
494
  logger("mqtt auto-cycle cleared", "info");
465
495
  }
@@ -477,7 +507,7 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
477
507
  if (conf.reconnectAfterStop) {
478
508
  delayedReconnect();
479
509
  }
480
- });
510
+ }, true);
481
511
  });
482
512
  }
483
513
 
@@ -515,16 +545,11 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
515
545
  ctx.t_mqttCalled = false;
516
546
 
517
547
  if (ctx._autoCycleTimer) {
518
- clearInterval(ctx._autoCycleTimer);
548
+ clearTimeout(ctx._autoCycleTimer);
519
549
  ctx._autoCycleTimer = null;
520
550
  }
521
551
 
522
- if (conf.cycleMs && conf.cycleMs > 0) {
523
- ctx._autoCycleTimer = setInterval(forceCycle, conf.cycleMs);
524
- logger(`mqtt auto-cycle enabled ${conf.cycleMs}ms`, "info");
525
- } else {
526
- logger("mqtt auto-cycle disabled", "info");
527
- }
552
+ scheduleSoftCycle();
528
553
 
529
554
  if (!ctx.firstListen || !ctx.lastSeqId) {
530
555
  getSeqIDWrapper();
@@ -122,6 +122,11 @@ 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.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.
125
130
  const disableAntiUserInfo = !!(antiCfg && antiCfg.AntiGetUserInfo === true);
126
131
 
127
132
  // Lightweight, Horizon-style implementation without database/queue
@@ -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
- };