fca-nx 6.8.0 → 6.8.3
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 +0 -24
- package/package.json +2 -2
- package/src/api/messaging/sendMessage.js +0 -13
- package/src/api/socket/OldMessage.js +2 -7
- package/src/api/socket/core/connectMqtt.js +43 -27
- package/src/api/socket/listenMqtt.js +44 -100
- package/src/api/socket/sendMessage.js +3 -28
- package/src/api/socket/sendMessageMqtt.js +0 -6
- package/src/utils/sendThrottle.js +6 -6
- package/src/utils/textEffects.js +0 -92
package/README.md
CHANGED
|
@@ -148,30 +148,6 @@ on load when this key is configured.
|
|
|
148
148
|
api.sendMessage("Hello world!", threadID);
|
|
149
149
|
|
|
150
150
|
```
|
|
151
|
-
### Message Effects
|
|
152
|
-
```javascript
|
|
153
|
-
api.sendMessage(
|
|
154
|
-
{
|
|
155
|
-
body: "I love you! ❤️",
|
|
156
|
-
textEffect: "love"
|
|
157
|
-
},
|
|
158
|
-
threadID
|
|
159
|
-
);
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
Built-in effect names are `heart`, `hearts`, `love`, `gift`, `present`, `fire`,
|
|
163
|
-
`flame`, `confetti`, `confecti`, `party`, `sparkles`, `sparkle`, `star`, and
|
|
164
|
-
`magic`. You can also pass a custom numeric effect ID:
|
|
165
|
-
|
|
166
|
-
```javascript
|
|
167
|
-
api.sendMessage({ body: "Party time!", effect: "confetti" }, threadID);
|
|
168
|
-
api.sendMessage({ body: "Custom effect", textEffect: 27 }, threadID);
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
The aliases `textEffect`, `text_effect`, `effect`, `effectName`, and their
|
|
172
|
-
snake/camel-case ID variants are accepted. Effects are applied through both
|
|
173
|
-
the MQTT sender and the legacy fallback sender.
|
|
174
|
-
|
|
175
151
|
### Send Attachment
|
|
176
152
|
```javascript
|
|
177
153
|
const fs = require("fs");
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fca-nx",
|
|
3
|
-
"version": "6.8.
|
|
4
|
-
"description": "Facebook Messenger API
|
|
3
|
+
"version": "6.8.3",
|
|
4
|
+
"description": "Facebook Messenger API \u2014 no bump, no text effects, single MQTT session",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"exports": {
|
|
@@ -171,19 +171,6 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
171
171
|
metadata_dataclass: JSON.stringify({ media_accessibility_metadata: { alt_text: null } })
|
|
172
172
|
};
|
|
173
173
|
|
|
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
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
174
|
const mentionData = buildMentionData(m, baseBody);
|
|
188
175
|
if (mentionData) payload0.mention_data = mentionData;
|
|
189
176
|
|
|
@@ -3,14 +3,10 @@
|
|
|
3
3
|
var utils = require("../../utils/utils");
|
|
4
4
|
var logger = require("../../utils/logger");
|
|
5
5
|
var bluebird = require("bluebird");
|
|
6
|
-
var { getTextEffectId } = require("../../utils/textEffects");
|
|
7
6
|
|
|
8
7
|
var allowedProperties = {
|
|
9
8
|
attachment: true, url: true, sticker: true, emoji: true,
|
|
10
|
-
emojiSize: true, body: true, mentions: true, location: true
|
|
11
|
-
textEffect: true, text_effect: true, text_effect_id: true, textEffectId: true,
|
|
12
|
-
textEffectID: true, effect: true, effect_id: true, effectID: true,
|
|
13
|
-
text_effect_name: true, effectName: true, effect_name: true,
|
|
9
|
+
emojiSize: true, body: true, mentions: true, location: true
|
|
14
10
|
};
|
|
15
11
|
|
|
16
12
|
module.exports = function (defaultFuncs, api, ctx) {
|
|
@@ -118,6 +114,7 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
118
114
|
|
|
119
115
|
return function OldMessage(msg, threadID, callback, replyToMessage, isSingleUser) {
|
|
120
116
|
if (typeof msg === "string") msg = { body: msg };
|
|
117
|
+
["text_effect_ids", "textEffect", "text_effect", "text_effect_id", "textEffectId", "textEffectID", "effect", "effect_id", "effectID", "text_effect_name", "effectName", "effect_name"].forEach(function (k) { delete msg[k]; });
|
|
121
118
|
|
|
122
119
|
if (msg.body && /(https?:\/\/|www\.|t\.me\/|fb\.me\/|youtu\.be\/|facebook\.com\/|youtube\.com\/)/i.test(msg.body)) {
|
|
123
120
|
return require('./sendMessage')(defaultFuncs, api, ctx)(msg, threadID, callback, replyToMessage, false);
|
|
@@ -138,8 +135,6 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
138
135
|
|
|
139
136
|
var form = {};
|
|
140
137
|
if (msg.body) form.body = msg.body;
|
|
141
|
-
var textEffectId = getTextEffectId(msg);
|
|
142
|
-
if (textEffectId) form.text_effect_id = textEffectId;
|
|
143
138
|
|
|
144
139
|
if (msg.mentions && Array.isArray(msg.mentions)) {
|
|
145
140
|
form.body = msg.body || "";
|
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
const { formatID } = require("../../../utils/format");
|
|
7
7
|
const { getSessionIdentity } = require("../../../utils/clientIdentity");
|
|
8
8
|
|
|
9
|
-
const DEFAULT_RECONNECT_DELAY_MS =
|
|
10
|
-
const MAX_RECONNECT_DELAY_MS =
|
|
11
|
-
const MAX_RECONNECT_ATTEMPTS =
|
|
12
|
-
const MAX_RECONNECT_COOLDOWN_MS =
|
|
13
|
-
const T_MS_WAIT_TIMEOUT_MS =
|
|
9
|
+
const DEFAULT_RECONNECT_DELAY_MS = 15000;
|
|
10
|
+
const MAX_RECONNECT_DELAY_MS = 120000;
|
|
11
|
+
const MAX_RECONNECT_ATTEMPTS = 6
|
|
12
|
+
const MAX_RECONNECT_COOLDOWN_MS = 45 * 60 * 1000;
|
|
13
|
+
const T_MS_WAIT_TIMEOUT_MS = 20000;
|
|
14
14
|
|
|
15
15
|
// Exponential backoff with jitter, based on how many *consecutive* reconnect
|
|
16
16
|
// attempts have happened for this session (reset to 0 on a successful
|
|
@@ -51,6 +51,7 @@ module.exports = function createListenMqtt(deps) {
|
|
|
51
51
|
return function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
|
|
52
52
|
|
|
53
53
|
function scheduleReconnect(delayMs) {
|
|
54
|
+
ctx._mqttConnecting = false;
|
|
54
55
|
const base = (ctx._mqttOpt && ctx._mqttOpt.reconnectDelayMs) || DEFAULT_RECONNECT_DELAY_MS;
|
|
55
56
|
if (ctx._reconnectTimer) {
|
|
56
57
|
logger("mqtt reconnect already scheduled", "warn");
|
|
@@ -94,6 +95,16 @@ module.exports = function createListenMqtt(deps) {
|
|
|
94
95
|
return /No subscription existed|client disconnecting|socket hang up|ECONNRESET/i.test(msg || "");
|
|
95
96
|
}
|
|
96
97
|
|
|
98
|
+
if (ctx.mqttClient && ctx.mqttClient.connected && !ctx._ending) {
|
|
99
|
+
logger("mqtt connect skipped - already connected", "warn");
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (ctx._mqttConnecting) {
|
|
103
|
+
logger("mqtt connect skipped - already connecting", "warn");
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
ctx._mqttConnecting = true;
|
|
107
|
+
|
|
97
108
|
// Ensure only one MQTT connection exists for this session, and that any
|
|
98
109
|
// previous connection is fully closed (listeners removed, socket ended)
|
|
99
110
|
// before a new one is opened. Without this, a reconnect racing with a
|
|
@@ -103,7 +114,7 @@ module.exports = function createListenMqtt(deps) {
|
|
|
103
114
|
if (ctx.mqttClient) {
|
|
104
115
|
try {
|
|
105
116
|
ctx.mqttClient.removeAllListeners();
|
|
106
|
-
|
|
117
|
+
ctx.mqttClient.end(true);
|
|
107
118
|
} catch (_) { }
|
|
108
119
|
ctx.mqttClient = undefined;
|
|
109
120
|
}
|
|
@@ -118,7 +129,12 @@ module.exports = function createListenMqtt(deps) {
|
|
|
118
129
|
}
|
|
119
130
|
// Prefer offline presence unless user explicitly set online:true
|
|
120
131
|
const chatOn = ctx.globalOptions.online === true;
|
|
121
|
-
|
|
132
|
+
// Same browser tab for the life of the process. A new sid on every
|
|
133
|
+
// reconnect looks like a new login and is a common suspend trigger.
|
|
134
|
+
if (!ctx._edgeSid) {
|
|
135
|
+
ctx._edgeSid = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER) + 1;
|
|
136
|
+
}
|
|
137
|
+
const sessionID = ctx._edgeSid;
|
|
122
138
|
const username = {
|
|
123
139
|
u: ctx.userID, s: sessionID, chat_on: chatOn, fg: false, d: ctx.clientId,
|
|
124
140
|
ct: "websocket", aid: 219994525426954, aids: null, mqtt_sid: "",
|
|
@@ -161,10 +177,10 @@ module.exports = function createListenMqtt(deps) {
|
|
|
161
177
|
protocolVersion: 13,
|
|
162
178
|
binaryType: "arraybuffer"
|
|
163
179
|
},
|
|
164
|
-
keepalive:
|
|
180
|
+
keepalive: 60,
|
|
165
181
|
reschedulePings: true,
|
|
166
182
|
reconnectPeriod: 0,
|
|
167
|
-
connectTimeout:
|
|
183
|
+
connectTimeout: 20000
|
|
168
184
|
};
|
|
169
185
|
if (ctx.globalOptions.proxy !== undefined) {
|
|
170
186
|
const agent = new HttpsProxyAgent(ctx.globalOptions.proxy);
|
|
@@ -178,6 +194,7 @@ module.exports = function createListenMqtt(deps) {
|
|
|
178
194
|
const mqttClient = ctx.mqttClient;
|
|
179
195
|
|
|
180
196
|
mqttClient.on("error", function (err) {
|
|
197
|
+
ctx._mqttConnecting = false;
|
|
181
198
|
const msg = String(err && err.message ? err.message : err || "");
|
|
182
199
|
if ((ctx._ending || ctx._cycling) && /No subscription existed|client disconnecting/i.test(msg)) {
|
|
183
200
|
logger(`mqtt expected during shutdown: ${msg}`, "info");
|
|
@@ -200,23 +217,12 @@ module.exports = function createListenMqtt(deps) {
|
|
|
200
217
|
return emitAuth(ctx, api, globalCallback, "login_blocked", msg);
|
|
201
218
|
}
|
|
202
219
|
|
|
203
|
-
// Plain 401/403/"Not logged in" is often a cookie
|
|
204
|
-
|
|
205
|
-
(
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
} catch (_) {}
|
|
211
|
-
try {
|
|
212
|
-
const { get } = require("../../../utils/request");
|
|
213
|
-
const { saveCookies } = require("../../../utils/client");
|
|
214
|
-
await get("https://www.facebook.com/", ctx.jar, null, ctx.globalOptions, ctx).then(saveCookies(ctx.jar));
|
|
215
|
-
} catch (_) {}
|
|
216
|
-
if (!ctx._ending && ctx.globalOptions && ctx.globalOptions.autoReconnect !== false) {
|
|
217
|
-
scheduleReconnect();
|
|
218
|
-
}
|
|
219
|
-
})();
|
|
220
|
+
// Plain 401/403/"Not logged in" is often a cookie race. Do not hit
|
|
221
|
+
// facebook.com (that is a fresh login). Wait, then open one socket.
|
|
222
|
+
logger(`mqtt transient auth error; one delayed reconnect (no homepage login): ${msg}`, "warn");
|
|
223
|
+
if (!ctx._ending && ctx.globalOptions && ctx.globalOptions.autoReconnect !== false) {
|
|
224
|
+
scheduleReconnect(30000);
|
|
225
|
+
}
|
|
220
226
|
return;
|
|
221
227
|
}
|
|
222
228
|
logger(`mqtt error: ${msg}`, "error");
|
|
@@ -246,6 +252,8 @@ module.exports = function createListenMqtt(deps) {
|
|
|
246
252
|
ctx._cycling = false;
|
|
247
253
|
ctx.loggedIn = true;
|
|
248
254
|
ctx._sessionRecovering = false;
|
|
255
|
+
ctx._mqttConnecting = false;
|
|
256
|
+
ctx._tmsMisses = 0;
|
|
249
257
|
// A successful connect means the session/identity/network are fine -
|
|
250
258
|
// reset the backoff counter so a later transient failure starts a
|
|
251
259
|
// fresh backoff sequence instead of inheriting a long delay from an
|
|
@@ -273,7 +281,14 @@ module.exports = function createListenMqtt(deps) {
|
|
|
273
281
|
logger("mqtt t_ms timeout skipped - ending", "warn");
|
|
274
282
|
return;
|
|
275
283
|
}
|
|
276
|
-
logger("mqtt t_ms timeout
|
|
284
|
+
logger("mqtt t_ms timeout", "warn");
|
|
285
|
+
ctx._tmsMisses = (ctx._tmsMisses || 0) + 1;
|
|
286
|
+
if (ctx._tmsMisses < 2 && mqttClient && mqttClient.connected) {
|
|
287
|
+
try {
|
|
288
|
+
mqttClient.publish(topic, JSON.stringify(queue), { qos: 1, retain: false });
|
|
289
|
+
} catch (_) { }
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
277
292
|
try {
|
|
278
293
|
if (mqttClient && mqttClient.connected) {
|
|
279
294
|
mqttClient.end(true);
|
|
@@ -358,6 +373,7 @@ module.exports = function createListenMqtt(deps) {
|
|
|
358
373
|
});
|
|
359
374
|
|
|
360
375
|
mqttClient.on("close", function () {
|
|
376
|
+
ctx._mqttConnecting = false;
|
|
361
377
|
if (ctx._ending || ctx._cycling) {
|
|
362
378
|
logger("mqtt close expected", "info");
|
|
363
379
|
return;
|
|
@@ -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,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) *
|
|
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
|
-
// [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 (
|
|
344
|
-
ctx._userInfoIntervals.
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
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
|
-
|
|
358
|
-
|
|
359
|
-
|
|
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;
|
|
@@ -367,7 +357,7 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
|
|
|
367
357
|
|
|
368
358
|
try {
|
|
369
359
|
if (ctx.mqttClient) {
|
|
370
|
-
if (isConnected()) {
|
|
360
|
+
if (!soft && isConnected()) {
|
|
371
361
|
try {
|
|
372
362
|
ctx.mqttClient.publish("/browser_close", "{}", { qos: 0 });
|
|
373
363
|
} catch (_) { }
|
|
@@ -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
|
-
// [
|
|
404
|
+
// [Hardened7] minimum 10 min between forced cycles
|
|
426
405
|
const now = Date.now();
|
|
427
|
-
if (ctx._lastForceCycleAt && (now - ctx._lastForceCycleAt) <
|
|
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();
|
|
@@ -475,44 +454,16 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
|
|
|
475
454
|
if (!ctx.mqttClient) return;
|
|
476
455
|
|
|
477
456
|
ctx.mqttClient.removeAllListeners("packetreceive");
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
//
|
|
482
|
-
// so lastPongTime was never refreshed and the heartbeat below kept
|
|
483
|
-
// force-reconnecting the account roughly every minute (this is what
|
|
484
|
-
// looked like periodic auto logout). The library's own keepalive
|
|
485
|
-
// (keepalive: 30 in connectMqtt.js) sends PINGREQ/PINGRESP
|
|
486
|
-
// internally; we detect the PINGRESP via "packetreceive" instead.
|
|
487
|
-
// Any other incoming packet (e.g. real messages) also proves the
|
|
488
|
-
// connection is alive, so it counts too.
|
|
457
|
+
|
|
458
|
+
// Do not remove "close" / "error". connectMqtt already owns reconnect.
|
|
459
|
+
// Replacing those handlers made every drop run getSeqID (a fresh login)
|
|
460
|
+
// and sometimes opened a second socket — that is what suspends the account.
|
|
489
461
|
ctx.mqttClient.on("packetreceive", (packet) => {
|
|
490
462
|
lastPongTime = Date.now();
|
|
491
463
|
if (packet && packet.cmd === "pingresp") {
|
|
492
464
|
logger("mqtt pong received", "debug");
|
|
493
465
|
}
|
|
494
466
|
});
|
|
495
|
-
|
|
496
|
-
ctx.mqttClient.once("close", () => {
|
|
497
|
-
logger("mqtt connection closed", "warn");
|
|
498
|
-
stopHeartbeat();
|
|
499
|
-
if (!ctx._ending && ctx.globalOptions.autoReconnect !== false) {
|
|
500
|
-
if (!isReconnecting) {
|
|
501
|
-
isReconnecting = true;
|
|
502
|
-
delayedReconnect();
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
});
|
|
506
|
-
|
|
507
|
-
ctx.mqttClient.once("error", (err) => {
|
|
508
|
-
logger(`mqtt error: ${err.message}`, "error");
|
|
509
|
-
if (!ctx._ending && ctx.globalOptions.autoReconnect !== false) {
|
|
510
|
-
if (!isReconnecting) {
|
|
511
|
-
isReconnecting = true;
|
|
512
|
-
forceCycle();
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
});
|
|
516
467
|
}
|
|
517
468
|
|
|
518
469
|
return function (callback) {
|
|
@@ -587,14 +538,7 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
|
|
|
587
538
|
}
|
|
588
539
|
|
|
589
540
|
if (conf.cycleMs && conf.cycleMs > 0) {
|
|
590
|
-
|
|
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
|
-
})();
|
|
541
|
+
ctx._autoCycleTimer = setInterval(forceCycle, conf.cycleMs);
|
|
598
542
|
logger(`mqtt auto-cycle enabled ${conf.cycleMs}ms`, "info");
|
|
599
543
|
} else {
|
|
600
544
|
logger("mqtt auto-cycle disabled", "info");
|
|
@@ -7,16 +7,12 @@
|
|
|
7
7
|
|
|
8
8
|
var utils = require("../../utils/utils");
|
|
9
9
|
var logger = require("../../utils/logger");
|
|
10
|
-
var { getTextEffectId, getTextEffectIds } = require("../../utils/textEffects");
|
|
11
10
|
var { waitTurn } = require("../../utils/sendThrottle");
|
|
12
11
|
|
|
13
12
|
var ALLOWED = {
|
|
14
13
|
attachment: true, url: true, sticker: true, emoji: true,
|
|
15
14
|
emojiSize: true, body: true, mentions: true, location: true,
|
|
16
|
-
replyToMessage: true, forwardAttachmentIds: true
|
|
17
|
-
textEffect: true, text_effect: true, text_effect_id: true,
|
|
18
|
-
textEffectId: true, textEffectID: true, effect: true, effect_id: true,
|
|
19
|
-
effectID: true, text_effect_name: true, effectName: true, effect_name: true
|
|
15
|
+
replyToMessage: true, forwardAttachmentIds: true
|
|
20
16
|
};
|
|
21
17
|
|
|
22
18
|
var EMOJI_SIZES = { small: 1, medium: 2, large: 3 };
|
|
@@ -173,11 +169,6 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
173
169
|
var mentionData = buildMentionData(msg, baseBody);
|
|
174
170
|
if (mentionData) payload0.mention_data = mentionData;
|
|
175
171
|
|
|
176
|
-
var textEffectId = getTextEffectId(msg);
|
|
177
|
-
if (textEffectId) payload0.text_effect_id = textEffectId;
|
|
178
|
-
var effectArray = getTextEffectIds(msg);
|
|
179
|
-
if (effectArray.length) payload0.text_effect_ids = effectArray;
|
|
180
|
-
|
|
181
172
|
if (msg.sticker) {
|
|
182
173
|
payload0.send_type = 2;
|
|
183
174
|
payload0.sticker_id = msg.sticker;
|
|
@@ -308,6 +299,8 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
308
299
|
return async function sendMessage(msg, threadID, callback, replyToMessage, isSingleUser) {
|
|
309
300
|
if (typeof msg === "string") msg = { body: msg };
|
|
310
301
|
if (typeof callback !== "function") callback = null;
|
|
302
|
+
var drop = ["text_effect_ids", "textEffect", "text_effect", "text_effect_id", "textEffectId", "textEffectID", "effect", "effect_id", "effectID", "text_effect_name", "effectName", "effect_name"];
|
|
303
|
+
for (var d = 0; d < drop.length; d++) delete msg[drop[d]];
|
|
311
304
|
|
|
312
305
|
var resolve, reject;
|
|
313
306
|
var promise = new Promise(function (res, rej) {
|
|
@@ -388,24 +381,6 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
388
381
|
// instead of hard-failing (Hardened6).
|
|
389
382
|
if (isSingleUser && !msg.attachment && !msg.sticker && !msg.location && !msg.emoji &&
|
|
390
383
|
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
384
|
try {
|
|
410
385
|
var e2eeText = await api.e2ee.sendMessage(
|
|
411
386
|
String(threadID),
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var utils = require("../../utils/utils");
|
|
4
|
-
var { getTextEffectId, getTextEffectIds } = require("../../utils/textEffects");
|
|
5
4
|
|
|
6
5
|
module.exports = function (defaultFuncs, api, ctx) {
|
|
7
6
|
return function sendMessageMqtt(msg, threadID, callback, replyToMessage) {
|
|
@@ -34,11 +33,6 @@ module.exports = function (defaultFuncs, api, ctx) {
|
|
|
34
33
|
multitab_env: 0
|
|
35
34
|
};
|
|
36
35
|
|
|
37
|
-
var textEffectId = getTextEffectId(msg);
|
|
38
|
-
if (textEffectId) payload0.text_effect_id = textEffectId;
|
|
39
|
-
var effectArray = getTextEffectIds(msg);
|
|
40
|
-
if (effectArray.length) payload0.text_effect_ids = effectArray;
|
|
41
|
-
|
|
42
36
|
if (msg.sticker) { payload0.send_type = 2; payload0.sticker_id = msg.sticker; }
|
|
43
37
|
if (replyToMessage || msg.replyToMessage) {
|
|
44
38
|
payload0.reply_metadata = {
|
|
@@ -7,16 +7,16 @@
|
|
|
7
7
|
* released no sooner than `delay` ms after the previous one. This avoids sending bursts that
|
|
8
8
|
* look like a script and that Facebook's rate limiting reacts to.
|
|
9
9
|
*
|
|
10
|
-
* FCA_NX_SEND_DELAY_MS base gap between sends, default
|
|
11
|
-
* FCA_NX_SEND_JITTER_MS extra random 0..N ms added to each gap, default
|
|
10
|
+
* FCA_NX_SEND_DELAY_MS base gap between sends, default 1500 (set 0 to disable)
|
|
11
|
+
* FCA_NX_SEND_JITTER_MS extra random 0..N ms added to each gap, default 600
|
|
12
12
|
* or at runtime: api.setSendDelay(ms, jitterMs)
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
const state = { last: 0, chain: Promise.resolve(), delay: null, jitter: null, stamps: [] };
|
|
16
|
-
// Hard ceiling per rolling minute (FCA_NX_SEND_MAX_PER_MIN, default
|
|
16
|
+
// Hard ceiling per rolling minute (FCA_NX_SEND_MAX_PER_MIN, default 12, 0 = off).
|
|
17
17
|
function maxPerMin() {
|
|
18
18
|
const n = Number(process.env.FCA_NX_SEND_MAX_PER_MIN);
|
|
19
|
-
return Number.isFinite(n) && n >= 0 ? n :
|
|
19
|
+
return Number.isFinite(n) && n >= 0 ? n : 12;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
function readNum(v, d) {
|
|
@@ -25,10 +25,10 @@ function readNum(v, d) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
function getDelay() {
|
|
28
|
-
return state.delay != null ? state.delay : readNum(process.env.FCA_NX_SEND_DELAY_MS,
|
|
28
|
+
return state.delay != null ? state.delay : readNum(process.env.FCA_NX_SEND_DELAY_MS, 1500);
|
|
29
29
|
}
|
|
30
30
|
function getJitter() {
|
|
31
|
-
return state.jitter != null ? state.jitter : readNum(process.env.FCA_NX_SEND_JITTER_MS,
|
|
31
|
+
return state.jitter != null ? state.jitter : readNum(process.env.FCA_NX_SEND_JITTER_MS, 600);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
function setSendDelay(ms, jitterMs) {
|
package/src/utils/textEffects.js
DELETED
|
@@ -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
|
-
};
|