fix: use fetchLatestWaWebVersion to prevent 405 connection failures (#443)
Baileys' default WhatsApp version can fall behind when WhatsApp updates their protocol, causing 405 "Method Not Allowed" errors on the websocket handshake. This prevents both new authentication and reconnection. Now fetches the latest version on each connection so it stays current. Applied to both the runtime connection (whatsapp.ts) and the setup auth flow (whatsapp-auth.ts).
This commit is contained in:
@@ -6,6 +6,7 @@ import makeWASocket, {
|
||||
Browsers,
|
||||
DisconnectReason,
|
||||
WASocket,
|
||||
fetchLatestWaWebVersion,
|
||||
makeCacheableSignalKeyStore,
|
||||
useMultiFileAuthState,
|
||||
} from '@whiskeysockets/baileys';
|
||||
@@ -55,7 +56,9 @@ export class WhatsAppChannel implements Channel {
|
||||
|
||||
const { state, saveCreds } = await useMultiFileAuthState(authDir);
|
||||
|
||||
const { version } = await fetchLatestWaWebVersion({});
|
||||
this.sock = makeWASocket({
|
||||
version,
|
||||
auth: {
|
||||
creds: state.creds,
|
||||
keys: makeCacheableSignalKeyStore(state.keys, logger),
|
||||
|
||||
@@ -15,6 +15,7 @@ import readline from 'readline';
|
||||
import makeWASocket, {
|
||||
Browsers,
|
||||
DisconnectReason,
|
||||
fetchLatestWaWebVersion,
|
||||
makeCacheableSignalKeyStore,
|
||||
useMultiFileAuthState,
|
||||
} from '@whiskeysockets/baileys';
|
||||
@@ -53,7 +54,9 @@ async function connectSocket(phoneNumber?: string, isReconnect = false): Promise
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const { version } = await fetchLatestWaWebVersion({});
|
||||
const sock = makeWASocket({
|
||||
version,
|
||||
auth: {
|
||||
creds: state.creds,
|
||||
keys: makeCacheableSignalKeyStore(state.keys, logger),
|
||||
|
||||
Reference in New Issue
Block a user