@lazyneoaz/metachat 1.1.0 → 1.1.2

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/index.js CHANGED
@@ -54,3 +54,7 @@ module.exports.createRequestHelper = createRequestHelper;
54
54
  module.exports.normalizeCookieHeaderString = normalizeCookieHeaderString;
55
55
  module.exports.setJarFromPairs = setJarFromPairs;
56
56
  module.exports.createAuthCore = createAuthCore;
57
+
58
+ module.exports.getVersion = function getVersion() {
59
+ return require('./package.json').version;
60
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lazyneoaz/metachat",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "type": "commonjs",
5
5
  "types": "src/types/index.d.ts",
6
6
  "description": "Advanced Facebook Chat API client for building Messenger bots — real-time messaging, thread management, MQTT, and session stability.",
@@ -140,14 +140,10 @@ async function listenMqtt(defaultFuncs, api, ctx, globalCallback, scheduleReconn
140
140
 
141
141
  utils.log("Connecting to MQTT...", host);
142
142
 
143
- const cachedSecChUa = ctx.globalOptions.cachedSecChUa || '"Google Chrome";v="136", "Not;A=Brand";v="99", "Chromium";v="136"';
144
- const cachedSecChUaPlatform = ctx.globalOptions.cachedSecChUaPlatform || '"Windows"';
145
143
  const cachedLocale = ctx.globalOptions.cachedLocale || 'en-US,en;q=0.9';
146
144
 
147
- // Generate a unique client ID per session like a real browser would
148
- const mqttClientId = 'mqttwsclient_' + Math.random().toString(36).slice(2, 10) + Date.now().toString(36);
149
145
  const options = {
150
- clientId: mqttClientId,
146
+ clientId: 'mqttwsclient',
151
147
  protocolId: 'MQIsdp',
152
148
  protocolVersion: 3,
153
149
  username: JSON.stringify(username),
@@ -166,18 +162,15 @@ async function listenMqtt(defaultFuncs, api, ctx, globalCallback, scheduleReconn
166
162
  'Sec-WebSocket-Version': '13',
167
163
  'Accept-Encoding': 'gzip, deflate, br',
168
164
  'Accept-Language': cachedLocale,
169
- 'Sec-Ch-Ua': cachedSecChUa,
170
- 'Sec-Ch-Ua-Mobile': '?0',
171
- 'Sec-Ch-Ua-Platform': cachedSecChUaPlatform,
172
165
  'Sec-WebSocket-Extensions': 'permessage-deflate; client_max_window_bits'
173
166
  },
174
167
  origin: 'https://www.facebook.com',
175
168
  protocolVersion: 13,
176
169
  binaryType: 'arraybuffer'
177
170
  },
178
- keepalive: 60,
171
+ keepalive: 30,
179
172
  reschedulePings: true,
180
- connectTimeout: 10000,
173
+ connectTimeout: 12000,
181
174
  reconnectPeriod: 0
182
175
  };
183
176
 
@@ -62,9 +62,6 @@ module.exports = (defaultFuncs, api, ctx) => {
62
62
  const batch = attachments.slice(i, i + CONCURRENT_UPLOADS);
63
63
  const results = await Promise.all(batch.map(a => uploadSingleAttachment(a, threadIDHint)));
64
64
  uploads.push(...results);
65
- if (i + CONCURRENT_UPLOADS < attachments.length) {
66
- await globalAntiSuspension.addSmartDelay();
67
- }
68
65
  }
69
66
  return uploads;
70
67
  }
@@ -289,27 +286,6 @@ module.exports = (defaultFuncs, api, ctx) => {
289
286
  }
290
287
 
291
288
  try {
292
- await globalAntiSuspension.prepareBeforeMessage(String(Array.isArray(threadID) ? threadID[0] : threadID), msg.body || '');
293
-
294
- let typingStarted = false;
295
- let typingTimeout;
296
- const shouldSimulateTyping = ctx.globalOptions && ctx.globalOptions.simulateTyping && api.sendTypingIndicator && ctx.mqttClient && ctx.mqttClient.connected;
297
- if (shouldSimulateTyping) {
298
- try {
299
- await api.sendTypingIndicator(true, threadID);
300
- typingStarted = true;
301
- const msgLen = (msg.body || '').length;
302
- const typingMs = await globalAntiSuspension.simulateTyping(threadID, msgLen);
303
- await new Promise(resolve => setTimeout(resolve, typingMs));
304
- typingTimeout = setTimeout(() => {
305
- if (typingStarted) {
306
- try { api.sendTypingIndicator(false, threadID); } catch (_) {}
307
- typingStarted = false;
308
- }
309
- }, 10000);
310
- } catch (_) {}
311
- }
312
-
313
289
  try {
314
290
  const mqttReady = ctx.mqttClient && ctx.mqttClient.connected;
315
291
  const isMultiRecipient = Array.isArray(threadID);
@@ -22,9 +22,6 @@ module.exports = (defaultFuncs, api, ctx) => {
22
22
  if (!utils.isReadableStream(attachments[i])) {
23
23
  throw new Error("Attachment should be a readable stream and not " + utils.getType(attachments[i]) + ".");
24
24
  }
25
- if (i > 0) {
26
- await globalAntiSuspension.addSmartDelay();
27
- }
28
25
  const form = {
29
26
  upload_1024: attachments[i],
30
27
  ...detectAttachmentType(attachments[i]),
@@ -534,4 +534,6 @@ declare module "@lazyneoaz/metachat" {
534
534
  options: LoginOptions | Callback<API>,
535
535
  callback?: Callback<API>
536
536
  ): Promise<API> | void;
537
+
538
+ export function getVersion(): string;
537
539
  }
@@ -87,8 +87,8 @@ class AntiSuspension {
87
87
  this.lastActivity = new Map();
88
88
  this.typing = new Map();
89
89
 
90
- this.messageDelayMs = 50;
91
- this.threadDelayMs = 50;
90
+ this.messageDelayMs = 0;
91
+ this.threadDelayMs = 0;
92
92
  this.loginAttempts = 0;
93
93
  this.maxLoginAttempts = 3;
94
94
  this.loginCooldown = 300000;
@@ -329,14 +329,14 @@ class AntiSuspension {
329
329
 
330
330
  async enforceThreadThrottling(threadID) {
331
331
  const lastTime = this.lastActivity.get(String(threadID)) || 0;
332
- const timeSinceLastMsg = Date.now() - lastTime;
333
- const minInterval = this.threadDelayMs + Math.random() * 10;
334
-
335
- if (timeSinceLastMsg < minInterval) {
336
- const waitTime = minInterval - timeSinceLastMsg;
337
- await new Promise(resolve => setTimeout(resolve, waitTime));
332
+ if (this.threadDelayMs > 0) {
333
+ const timeSinceLastMsg = Date.now() - lastTime;
334
+ const minInterval = this.threadDelayMs + Math.random() * 10;
335
+ if (timeSinceLastMsg < minInterval) {
336
+ const waitTime = minInterval - timeSinceLastMsg;
337
+ await new Promise(resolve => setTimeout(resolve, waitTime));
338
+ }
338
339
  }
339
-
340
340
  this.lastActivity.set(String(threadID), Date.now());
341
341
  return Date.now() - lastTime;
342
342
  }
@@ -482,8 +482,6 @@ class AntiSuspension {
482
482
  if (volumeWarning) {
483
483
  const { utils } = this._getUtils();
484
484
  utils && utils.warn && utils.warn("AntiSuspension", volumeWarning);
485
- // Add a safety pause instead of hard-blocking so callers can decide
486
- await new Promise(resolve => setTimeout(resolve, 5000 + Math.random() * 3000));
487
485
  }
488
486
 
489
487
  await this.enforceThreadThrottling(threadID);
@@ -113,7 +113,6 @@ function getHeaders(url, options, ctx, customHeader, requestType = 'navigate') {
113
113
  const isXhr = requestType === 'xhr';
114
114
 
115
115
  const locales = options?.cachedLocale || (androidData?.locale ? androidData.locale.replace('_', '-') : getRandomLocale());
116
- const timezone = options?.cachedTimezone || getRandomTimezone();
117
116
 
118
117
  if (isAndroid) {
119
118
  const headers = {
@@ -161,29 +160,26 @@ function getHeaders(url, options, ctx, customHeader, requestType = 'navigate') {
161
160
  const isLinux = secChUaPlatform === '"Linux"';
162
161
 
163
162
  const headers = {
164
- 'Accept': isXhr ? '*/*' : 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
163
+ 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,application/json;q=0.8,*/*;q=0.7',
165
164
  'Accept-Language': locales,
166
165
  'Accept-Encoding': 'gzip, deflate, br',
167
166
  'Cache-Control': 'no-cache',
168
167
  'Connection': 'keep-alive',
169
168
  'DNT': '1',
170
- 'Dpr': '1',
171
169
  'Host': host,
172
170
  'Pragma': 'no-cache',
173
171
  'Referer': referer,
174
- 'Sec-Ch-Prefers-Color-Scheme': 'light',
175
172
  'Sec-Ch-Ua': secChUa,
176
173
  'Sec-Ch-Ua-Full-Version-List': secChUaFullVersionList,
177
174
  'Sec-Ch-Ua-Mobile': '?0',
178
- 'Sec-Ch-Ua-Model': '""',
179
175
  'Sec-Ch-Ua-Platform': secChUaPlatform,
180
176
  'Sec-Ch-Ua-Platform-Version': secChUaPlatformVersion,
181
177
  'Sec-Fetch-Dest': isXhr ? 'empty' : 'document',
182
178
  'Sec-Fetch-Mode': isXhr ? 'cors' : 'navigate',
183
179
  'Sec-Fetch-Site': isXhr ? 'same-origin' : 'none',
184
180
  'User-Agent': userAgent,
185
- 'Viewport-Width': '1920',
186
- 'X-FB-Timezone-Offset': (typeof timezone === 'number' && isFinite(timezone)) ? String(timezone * 60) : '0'
181
+ 'Upgrade-Insecure-Requests': '1',
182
+ 'X-Requested-With': 'XMLHttpRequest'
187
183
  };
188
184
 
189
185
  if (isWindows || isMac || isLinux) {
@@ -193,10 +189,6 @@ function getHeaders(url, options, ctx, customHeader, requestType = 'navigate') {
193
189
 
194
190
  if (isXhr) {
195
191
  headers['Origin'] = `https://${host}`;
196
- headers['X-Requested-With'] = 'XMLHttpRequest';
197
- } else {
198
- headers['Sec-Fetch-User'] = '?1';
199
- headers['Upgrade-Insecure-Requests'] = '1';
200
192
  }
201
193
 
202
194
  if (ctx) {