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:
Lorenzo Fränkel
2026-02-24 00:56:43 -04:00
committed by GitHub
parent 9f802bc5d4
commit ec176a05e1
2 changed files with 6 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ import makeWASocket, {
Browsers, Browsers,
DisconnectReason, DisconnectReason,
WASocket, WASocket,
fetchLatestWaWebVersion,
makeCacheableSignalKeyStore, makeCacheableSignalKeyStore,
useMultiFileAuthState, useMultiFileAuthState,
} from '@whiskeysockets/baileys'; } from '@whiskeysockets/baileys';
@@ -55,7 +56,9 @@ export class WhatsAppChannel implements Channel {
const { state, saveCreds } = await useMultiFileAuthState(authDir); const { state, saveCreds } = await useMultiFileAuthState(authDir);
const { version } = await fetchLatestWaWebVersion({});
this.sock = makeWASocket({ this.sock = makeWASocket({
version,
auth: { auth: {
creds: state.creds, creds: state.creds,
keys: makeCacheableSignalKeyStore(state.keys, logger), keys: makeCacheableSignalKeyStore(state.keys, logger),

View File

@@ -15,6 +15,7 @@ import readline from 'readline';
import makeWASocket, { import makeWASocket, {
Browsers, Browsers,
DisconnectReason, DisconnectReason,
fetchLatestWaWebVersion,
makeCacheableSignalKeyStore, makeCacheableSignalKeyStore,
useMultiFileAuthState, useMultiFileAuthState,
} from '@whiskeysockets/baileys'; } from '@whiskeysockets/baileys';
@@ -53,7 +54,9 @@ async function connectSocket(phoneNumber?: string, isReconnect = false): Promise
process.exit(0); process.exit(0);
} }
const { version } = await fetchLatestWaWebVersion({});
const sock = makeWASocket({ const sock = makeWASocket({
version,
auth: { auth: {
creds: state.creds, creds: state.creds,
keys: makeCacheableSignalKeyStore(state.keys, logger), keys: makeCacheableSignalKeyStore(state.keys, logger),