fca-nx 6.8.0 → 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.8.0",
4
- "description": "Facebook Messenger API for Node.js — hardened sendMessage + listenMqtt (cascade fallback, soft MQTT, anti-reconnect-storm)",
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": {
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+
3
+ // api.bump(threadID, options?, callback?)
4
+ // Bumps a thread by sending a short message (default "👆") then optionally unsending it.
5
+ //
6
+ // options:
7
+ // text: message to send (default "👆")
8
+ // effect: text effect name or id (default "confetti"; false/"none" = plain text)
9
+ // unsend: unsend after sending (default true)
10
+ // delay: ms to wait before unsend (default 1500, clamped 500..10000)
11
+ //
12
+ // Returns: { threadID, messageID, unsent, unsendError? }
13
+ //
14
+ // Safety (hardened):
15
+ // - per-thread cooldown 45s
16
+ // - global cap 8 bumps / 60s
17
+ // - rejects invalid threadID early
18
+ // - never throws on unsend failure (message already bumped the thread)
19
+
20
+ const COOLDOWN_MS = 45 * 1000;
21
+ const WINDOW_MS = 60 * 1000;
22
+ const MAX_PER_WINDOW = 8;
23
+ const MIN_DELAY = 500;
24
+ const MAX_DELAY = 10000;
25
+
26
+ module.exports = function (defaultFuncs, api, ctx) {
27
+ const lastBump = new Map();
28
+ let recent = [];
29
+
30
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
31
+
32
+ const send = (body, threadID, effect) =>
33
+ new Promise((resolve, reject) => {
34
+ if (typeof api.sendMessage !== "function") {
35
+ return reject(new Error("bump: api.sendMessage is not available"));
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)));
43
+ });
44
+
45
+ const unsend = (messageID, threadID) =>
46
+ new Promise((resolve, reject) => {
47
+ if (typeof api.unsendMessage !== "function") {
48
+ return reject(new Error("bump: api.unsendMessage is not available"));
49
+ }
50
+ // support both (messageID, callback) and (messageID, threadID, callback) styles
51
+ try {
52
+ const ret = api.unsendMessage(messageID, threadID, (err) => (err ? reject(err) : resolve()));
53
+ if (ret && typeof ret.then === "function") {
54
+ ret.then(resolve, reject);
55
+ }
56
+ } catch (e) {
57
+ // fallback single-arg form
58
+ try {
59
+ const ret2 = api.unsendMessage(messageID, (err) => (err ? reject(err) : resolve()));
60
+ if (ret2 && typeof ret2.then === "function") {
61
+ ret2.then(resolve, reject);
62
+ }
63
+ } catch (e2) {
64
+ reject(e2 || e);
65
+ }
66
+ }
67
+ });
68
+
69
+ return function bump(threadID, options, callback) {
70
+ if (typeof options === "function") {
71
+ callback = options;
72
+ options = {};
73
+ }
74
+ options = options || {};
75
+
76
+ const promise = (async () => {
77
+ if (threadID == null || threadID === "") {
78
+ throw new Error("bump: threadID is required");
79
+ }
80
+ const tid = String(threadID).trim();
81
+ if (!tid) throw new Error("bump: threadID is required");
82
+
83
+ const now = Date.now();
84
+
85
+ const last = lastBump.get(tid) || 0;
86
+ if (now - last < COOLDOWN_MS) {
87
+ throw new Error(
88
+ `bump: cooldown active for this thread, wait ${Math.ceil((COOLDOWN_MS - (now - last)) / 1000)}s`
89
+ );
90
+ }
91
+
92
+ recent = recent.filter((t) => now - t < WINDOW_MS);
93
+ if (recent.length >= MAX_PER_WINDOW) {
94
+ throw new Error("bump: global rate limit reached (max 8 / minute), try again shortly");
95
+ }
96
+
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
+ }
104
+ const doUnsend = options.unsend !== false;
105
+ let delay = Number.isFinite(options.delay) ? Number(options.delay) : 1500;
106
+ if (delay < MIN_DELAY) delay = MIN_DELAY;
107
+ if (delay > MAX_DELAY) delay = MAX_DELAY;
108
+
109
+ const info = await send(text, tid, effect);
110
+ lastBump.set(tid, Date.now());
111
+ recent.push(Date.now());
112
+
113
+ // prune map if it grows too large (memory safety)
114
+ if (lastBump.size > 5000) {
115
+ const cutoff = Date.now() - COOLDOWN_MS * 2;
116
+ for (const [k, v] of lastBump) {
117
+ if (v < cutoff) lastBump.delete(k);
118
+ }
119
+ }
120
+
121
+ const result = {
122
+ threadID: tid,
123
+ messageID: info && info.messageID ? String(info.messageID) : null,
124
+ unsent: false
125
+ };
126
+
127
+ if (doUnsend && result.messageID) {
128
+ await sleep(delay);
129
+ try {
130
+ await unsend(result.messageID, tid);
131
+ result.unsent = true;
132
+ } catch (e) {
133
+ // Message was still sent (thread is bumped); unsend can fail e.g. in E2EE DMs.
134
+ result.unsendError = e && e.message ? e.message : String(e);
135
+ }
136
+ }
137
+
138
+ return result;
139
+ })();
140
+
141
+ if (typeof callback === "function") {
142
+ promise.then((r) => callback(null, r), (e) => callback(e));
143
+ }
144
+ return promise;
145
+ };
146
+ };
@@ -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
- // --- TEXT EFFECTS SUPPORT FOR MQTT ---
175
- if (m.text_effect_ids) {
176
- let effectArray = [];
177
- if (Array.isArray(m.text_effect_ids)) {
178
- effectArray = m.text_effect_ids;
179
- } else if (typeof m.text_effect_ids === "string" || typeof m.text_effect_ids === "number") {
180
- effectArray = [m.text_effect_ids];
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 = 6 * 60 * 60 * 1000; // [Hardened5] 6h cycle - minimize session churn
24
- const RECONNECT_DELAY_MS_DEFAULT = 8000; // [Hardened5]
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 = 60000;
27
- const MAX_MQTT_RECONNECT_COOLDOWN_MS = 15 * 60 * 1000 /* [Hardened5] longer cooldown */; // long cooldown after exhausting fast retries - never give up permanently
28
- const MAX_MQTT_RECONNECT_ATTEMPTS = 10;
29
- const HEARTBEAT_INTERVAL_MS = 45000 // [Hardened5];
30
- const HEARTBEAT_TIMEOUT_MS = 15000 // [Hardened5];
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,33 +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) * 5;
236
+ const limit = (conf.heartbeatTimeout || HEARTBEAT_TIMEOUT_MS) * 4;
236
237
  if (now - lastPongTime > limit) {
237
238
  missedPongs += 1;
238
- // Require 2 consecutive misses before forceCycle (avoid one delayed pong killing session)
239
- if (missedPongs >= 2) {
240
- logger("mqtt heartbeat: no response x2, forcing reconnect", "warn");
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
- forceCycle();
245
+ stopHeartbeat();
246
+ try { ctx.mqttClient.end(true); } catch (_) { }
243
247
  return;
244
248
  }
245
- logger("mqtt heartbeat: pong late, waiting one more cycle", "warn");
249
+ logger("mqtt heartbeat: packet late, waiting", "warn");
246
250
  } else {
247
251
  missedPongs = 0;
248
252
  }
249
-
250
- // [Hardened7] The real Messenger client never publishes a custom "/ping" message; liveness is
251
- // handled by MQTT keepalive (PINGREQ/PINGRESP, keepalive: 30 in connectMqtt) which updates
252
- // lastPongTime via the "pong" event. A custom topic is an easy automation fingerprint, so it is
253
- // opt-in only (FCA_NX_MQTT_APP_PING=1).
254
- if (process.env.FCA_NX_MQTT_APP_PING === "1") {
255
- try {
256
- ctx.mqttClient.publish("/ping", JSON.stringify({ timestamp: Date.now() }), { qos: 0 });
257
- logger("mqtt heartbeat sent", "debug");
258
- } catch (err) {
259
- logger(`mqtt heartbeat error: ${err.message}`, "warn");
260
- }
261
- }
262
253
  }, hbEvery);
263
254
  }
264
255
 
@@ -310,7 +301,7 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
310
301
  });
311
302
  }
312
303
 
313
- function endQuietly(next) {
304
+ function endQuietly(next, soft) {
314
305
  stopHeartbeat();
315
306
 
316
307
  const finish = () => {
@@ -321,11 +312,15 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
321
312
  } catch (_) { }
322
313
 
323
314
  ctx.mqttClient = undefined;
324
- ctx.lastSeqId = null;
325
- ctx.syncToken = undefined;
326
315
  ctx.t_mqttCalled = false;
327
316
  ctx._ending = false;
328
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
+ }
329
324
 
330
325
  if (ctx._reconnectTimer) {
331
326
  clearTimeout(ctx._reconnectTimer);
@@ -340,23 +335,18 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
340
335
  ctx.tasks.clear();
341
336
  }
342
337
 
343
- if (ctx._userInfoIntervals && Array.isArray(ctx._userInfoIntervals)) {
344
- ctx._userInfoIntervals.forEach(interval => {
345
- try { clearInterval(interval); } catch (_) { }
346
- });
347
- ctx._userInfoIntervals = [];
348
- }
349
-
350
- if (ctx._autoSaveInterval && Array.isArray(ctx._autoSaveInterval)) {
351
- ctx._autoSaveInterval.forEach(interval => {
352
- try { clearInterval(interval); } catch (_) { }
353
- });
354
- ctx._autoSaveInterval = [];
355
- }
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
+ }
356
345
 
357
- if (ctx._scheduler && typeof ctx._scheduler.destroy === "function") {
358
- try { ctx._scheduler.destroy(); } catch (_) { }
359
- ctx._scheduler = undefined;
346
+ if (ctx._scheduler && typeof ctx._scheduler.destroy === "function") {
347
+ try { ctx._scheduler.destroy(); } catch (_) { }
348
+ ctx._scheduler = undefined;
349
+ }
360
350
  }
361
351
 
362
352
  reconnectAttempts = 0;
@@ -389,17 +379,6 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
389
379
  return;
390
380
  }
391
381
  let d = getReconnectDelay();
392
- // [Hardened7] flap limiter: >4 reconnects within 10 min means something is wrong (killed
393
- // sessions, checkpoint, double instance). Hammering Facebook then is what triggers
394
- // "multiple sessions"/automation restrictions, so wait 10 min instead.
395
- const nowTs = Date.now();
396
- ctx._reconnectStamps = (ctx._reconnectStamps || []).filter(t => nowTs - t < 10 * 60 * 1000);
397
- ctx._reconnectStamps.push(nowTs);
398
- if (ctx._reconnectStamps.length > 4) {
399
- d = Math.max(d, 10 * 60 * 1000);
400
- logger(`mqtt reconnect flapping (${ctx._reconnectStamps.length} in 10min) - cooling down ${Math.round(d / 60000)}min`, "error");
401
- ctx._reconnectStamps = [];
402
- }
403
382
  // Always add a little extra jitter on the scheduled path (even when d is small)
404
383
  if (d > 0) d += Math.floor(Math.random() * 1500);
405
384
  logger(d === 0 ? "mqtt reconnecting immediately" : `mqtt reconnect in ${d}ms`, "info");
@@ -422,9 +401,9 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
422
401
  logger("mqtt force cycle skipped - ending", "warn");
423
402
  return;
424
403
  }
425
- // [Hardened6] minimum 90s between forced cycles to avoid reconnect storms
404
+ // [Hardened7] minimum 10 min between forced cycles
426
405
  const now = Date.now();
427
- if (ctx._lastForceCycleAt && (now - ctx._lastForceCycleAt) < 90000) {
406
+ if (ctx._lastForceCycleAt && (now - ctx._lastForceCycleAt) < MIN_FORCE_CYCLE_MS) {
428
407
  logger("mqtt force cycle skipped - too soon since last cycle", "warn");
429
408
  return;
430
409
  }
@@ -446,7 +425,7 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
446
425
 
447
426
  unsubAll(() => {
448
427
  try {
449
- endQuietly(finish);
428
+ endQuietly(finish, true);
450
429
  } catch (e) {
451
430
  logger(`mqtt force cycle endQuietly error: ${e && e.message ? e.message : e}`, "warn");
452
431
  finish();
@@ -505,11 +484,18 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
505
484
  });
506
485
 
507
486
  ctx.mqttClient.once("error", (err) => {
508
- logger(`mqtt error: ${err.message}`, "error");
509
- if (!ctx._ending && ctx.globalOptions.autoReconnect !== false) {
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()) {
510
496
  if (!isReconnecting) {
511
497
  isReconnecting = true;
512
- forceCycle();
498
+ delayedReconnect();
513
499
  }
514
500
  }
515
501
  });
@@ -587,14 +573,7 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
587
573
  }
588
574
 
589
575
  if (conf.cycleMs && conf.cycleMs > 0) {
590
- // [Hardened7] jittered (+-15%) so the cycle is not an exact clock
591
- (function scheduleCycle() {
592
- const j = conf.cycleMs * (0.85 + Math.random() * 0.3);
593
- ctx._autoCycleTimer = setTimeout(function () {
594
- if (!ctx._ending) forceCycle();
595
- if (ctx._autoCycleTimer) scheduleCycle();
596
- }, j);
597
- })();
576
+ ctx._autoCycleTimer = setInterval(forceCycle, conf.cycleMs);
598
577
  logger(`mqtt auto-cycle enabled ${conf.cycleMs}ms`, "info");
599
578
  } else {
600
579
  logger("mqtt auto-cycle disabled", "info");
@@ -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) payload0.text_effect_ids = effectArray;
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,26 +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
- // [Hardened8] Effects can't ride the E2EE bridge. Try MQTT once so the effect is kept;
393
- // if that errors/times out, fall back to plain E2EE text so the reply is never lost.
394
- // FCA_NX_E2EE_EFFECT_VIA_MQTT=0 disables the MQTT attempt (always plain E2EE text).
395
- if (process.env.FCA_NX_E2EE_EFFECT_VIA_MQTT !== "0") {
396
- try {
397
- var fxResult = await sendViaMqtt(msg, threadID, replyToMessage, 8000);
398
- if (fxResult && !fxResult.threadID) fxResult.threadID = String(threadID);
399
- if (callback) callback(null, fxResult);
400
- else resolve(fxResult);
401
- return promise;
402
- } catch (fxErr) {
403
- logger.warn("sendMessage", "Effect via MQTT failed in E2EE DM, sending plain E2EE text: " + (fxErr.message || fxErr));
404
- }
405
- } else {
406
- logger.warn("sendMessage", "Text effects are not supported in E2EE DMs - sending plain text. Use a group chat for effects.");
407
- }
408
- }
409
401
  try {
410
402
  var e2eeText = await api.e2ee.sendMessage(
411
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) payload0.text_effect_ids = effectArray;
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) {
@@ -48,7 +48,8 @@ function createFallbackNamespaces(api) {
48
48
  getEmojiUrl: bindOptionalMethod(api, "getEmojiUrl"),
49
49
  resolvePhotoUrl: bindOptionalMethod(api, "resolvePhotoUrl"),
50
50
  uploadAttachment: bindOptionalMethod(api, "uploadAttachment"),
51
- forwardAttachment: bindOptionalMethod(api, "forwardAttachment")
51
+ forwardAttachment: bindOptionalMethod(api, "forwardAttachment"),
52
+ bump: bindLiveMethod(api, "bump")
52
53
  }),
53
54
  threads: compactNamespace({
54
55
  createGroup: bindOptionalMethod(api, "createNewGroup"),
@@ -68,18 +68,17 @@ function getTextEffectId(message) {
68
68
 
69
69
  function getTextEffectIds(message) {
70
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);
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);
82
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);
83
82
  return ids;
84
83
  }
85
84