@eryxenx/fca 1.0.3 → 1.0.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.
@@ -872,6 +872,19 @@ function loginHelper(appState, Cookie, email, password, globalOptions, callback)
872
872
  };
873
873
  if (appState || Cookie) {
874
874
  const initial = await get("https://www.facebook.com/", jar, null, globalOptions).then(saveCookies(jar));
875
+ // Sanity-check the response actually looks like a real FB page load
876
+ // for the current UA (checked via a marker only present in that
877
+ // rendering). If not, the appstate/UA combo may be mismatched from
878
+ // how it was originally captured — retry once with a known-good UA
879
+ // rather than pushing forward with a session that already looks
880
+ // inconsistent to Facebook.
881
+ const bodyStr = typeof initial?.data === "string" ? initial.data : String(initial?.data ?? "");
882
+ if (!/MPageLoadClientMetrics/.test(bodyStr)) {
883
+ logger("Initial page load doesn't match expected UA rendering — retrying with fallback UA", "warn");
884
+ globalOptions.userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36";
885
+ const retryInitial = await get("https://www.facebook.com/", jar, null, globalOptions).then(saveCookies(jar));
886
+ return (await ctx.bypassAutomation(retryInitial, jar)) || retryInitial;
887
+ }
875
888
  return (await ctx.bypassAutomation(initial, jar)) || initial;
876
889
  }
877
890
  const hydrated = await hydrateJarFromDB(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eryxenx/fca",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Facebook Chat API by EryXenX | Stable • Auto Re-login • Full E2EE Support — send messages, media, reactions & more in encrypted chats, hassle-free",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -26,7 +26,7 @@ module.exports = function (defaultFuncs, api, ctx) {
26
26
  fb_api_caller_class: "RelayModern",
27
27
  fb_api_req_friendly_name: "FBScrapingWarningMutation",
28
28
  server_timestamps: "true",
29
- doc_id: "24406519995698862",
29
+ doc_id: "6339492849481770",
30
30
  variables: "{}"
31
31
  };
32
32
 
@@ -3,6 +3,7 @@
3
3
  var utils = require("../../utils/nexca-utils");
4
4
  var logger = require("../../utils/nexca-logger");
5
5
  var bluebird = require("bluebird");
6
+ var { globalAntiSuspension } = require("../../utils/antiSuspension");
6
7
 
7
8
  var allowedProperties = {
8
9
  attachment: true, url: true, sticker: true, emoji: true,
@@ -31,7 +32,7 @@ module.exports = function (defaultFuncs, api, ctx) {
31
32
  }
32
33
  bluebird.all(uploads)
33
34
  .then(resData => callback(null, resData))
34
- .catch(err => { logger.error("OldMessage.upload", err); callback(err); });
35
+ .catch(err => { globalAntiSuspension.checkAccountHealth(err); logger.error("OldMessage.upload", err); callback(err); });
35
36
  }
36
37
 
37
38
  function getUrl(url, callback) {
@@ -72,7 +73,10 @@ module.exports = function (defaultFuncs, api, ctx) {
72
73
  defaultFuncs.post("https://www.facebook.com/messaging/send/", ctx.jar, form)
73
74
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
74
75
  .then(resData => {
75
- if (!resData.payload) throw resData;
76
+ if (!resData.payload) {
77
+ globalAntiSuspension.checkAccountHealth(resData);
78
+ throw resData;
79
+ }
76
80
  var messageID = (resData.payload.actions && resData.payload.actions[0] &&
77
81
  resData.payload.actions[0].message_id) || null;
78
82
  var threadID2 = resData.payload.thread_fbid ||
@@ -83,7 +87,11 @@ module.exports = function (defaultFuncs, api, ctx) {
83
87
  timestamp: resData.payload.timestamp
84
88
  });
85
89
  })
86
- .catch(err => { logger.error("OldMessage.send", err); callback(err); });
90
+ .catch(err => {
91
+ globalAntiSuspension.checkAccountHealth(err);
92
+ logger.error("OldMessage.send", err);
93
+ callback(err);
94
+ });
87
95
  }
88
96
 
89
97
  function send(form, threadID, isSingleUser, callback) {
@@ -109,7 +117,12 @@ module.exports = function (defaultFuncs, api, ctx) {
109
117
  form.manual_retry_cnt = 0;
110
118
  form.has_attachment = false;
111
119
  form.signatureID = utils.getGUID().replace(/-/g, "").slice(0, 8);
112
- sendContent(form, threadID, isSingleUser, messageAndOTID, callback);
120
+ const doSend = () => sendContent(form, threadID, isSingleUser, messageAndOTID, callback);
121
+ if (!ctx.globalOptions || ctx.globalOptions.antiBan !== false) {
122
+ globalAntiSuspension.prepareBeforeMessage(threadID, form.body || "").then(doSend).catch(doSend);
123
+ } else {
124
+ doSend();
125
+ }
113
126
  }
114
127
 
115
128
  return function OldMessage(msg, threadID, callback, replyToMessage, isSingleUser) {
@@ -221,7 +221,25 @@ module.exports = function (defaultFuncs, api, ctx, opts) {
221
221
  function delayedReconnect() {
222
222
  const d = conf.reconnectDelayMs;
223
223
  logger(`mqtt reconnect in ${d}ms`, "info");
224
- setTimeout(() => getSeqIDWrapper(), d);
224
+ setTimeout(() => refreshSessionAndReconnect(), d);
225
+ }
226
+
227
+ function refreshSessionAndReconnect() {
228
+ logger("Refreshing session before MQTT reconnection to avoid cookie/dtsg desync", "info");
229
+ defaultFuncs.get("https://www.messenger.com/", ctx.jar, null, ctx)
230
+ .then(() => {
231
+ if (typeof api.refreshFb_dtsg === "function") {
232
+ return api.refreshFb_dtsg().then(() => {
233
+ logger("fb_dtsg refreshed before reconnect", "info");
234
+ });
235
+ }
236
+ })
237
+ .catch((err) => {
238
+ logger(`Session refresh before reconnect failed (non-fatal): ${err && err.message ? err.message : String(err)}`, "warn");
239
+ })
240
+ .finally(() => {
241
+ getSeqIDWrapper();
242
+ });
225
243
  }
226
244
 
227
245
  function forceCycle() {
@@ -198,7 +198,7 @@ function parseAndCheckLogin(ctx, http, retryCount = 0) {
198
198
  fb_api_caller_class: "RelayModern",
199
199
  fb_api_req_friendly_name: "FBScrapingWarningMutation",
200
200
  server_timestamps: "true",
201
- doc_id: "24406519995698862",
201
+ doc_id: "6339492849481770",
202
202
  variables: "{}"
203
203
  }, ctx.globalOptions, ctx)
204
204
  .then(() => logger("Dismissed automated-behavior warning", "info"))