davexbaileys 2.5.13 → 2.5.14
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/lib/Utils/generics.js +22 -11
- package/package.json +1 -1
package/lib/Utils/generics.js
CHANGED
|
@@ -174,10 +174,23 @@ export const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connect
|
|
|
174
174
|
* Use to ensure your WA connection is always on the latest version
|
|
175
175
|
*/
|
|
176
176
|
export const fetchLatestBaileysVersion = async (options = {}) => {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
177
|
+
// Fetch live from WhatsApp web so bots always get the current version
|
|
178
|
+
// Falls back to hardcoded baileysVersion if fetch fails
|
|
179
|
+
try {
|
|
180
|
+
const defaultHeaders = {
|
|
181
|
+
'sec-fetch-site': 'none',
|
|
182
|
+
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'
|
|
183
|
+
};
|
|
184
|
+
const headers = { ...defaultHeaders, ...options.headers };
|
|
185
|
+
const response = await fetch('https://web.whatsapp.com/sw.js', { ...options, method: 'GET', headers });
|
|
186
|
+
if (!response.ok) throw new Error('fetch failed');
|
|
187
|
+
const data = await response.text();
|
|
188
|
+
const match = data.match(/\"?client_revision\"?:\s*(\d+)/);
|
|
189
|
+
if (match?.[1]) {
|
|
190
|
+
return { version: [2, 3000, +match[1]], isLatest: true };
|
|
191
|
+
}
|
|
192
|
+
} catch {}
|
|
193
|
+
return { version: baileysVersion, isLatest: false };
|
|
181
194
|
};
|
|
182
195
|
/**
|
|
183
196
|
* A utility that fetches the latest web version of whatsapp.
|
|
@@ -303,15 +316,13 @@ export const getCodeFromWSError = (error) => {
|
|
|
303
316
|
statusCode = code;
|
|
304
317
|
}
|
|
305
318
|
}
|
|
306
|
-
else if (
|
|
307
|
-
|
|
319
|
+
else if (
|
|
320
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
321
|
+
error?.code?.startsWith('E') ||
|
|
322
|
+
error?.message?.includes('timed out')) {
|
|
323
|
+
// handle ETIMEOUT, ENOTFOUND etc
|
|
308
324
|
statusCode = 408;
|
|
309
325
|
}
|
|
310
|
-
else if (error?.code?.startsWith('E')) {
|
|
311
|
-
// network reset/unavailable (ECONNRESET, ENOTFOUND etc) — NOT a 408 timeout loop
|
|
312
|
-
// use 503 so bots can distinguish and apply a smarter reconnect strategy
|
|
313
|
-
statusCode = 503;
|
|
314
|
-
}
|
|
315
326
|
return statusCode;
|
|
316
327
|
};
|
|
317
328
|
/**
|