From 258f56759ca102359c9d383f7f18789deddef295 Mon Sep 17 00:00:00 2001 From: Felipe Medeiros Date: Tue, 6 Aug 2024 01:48:42 -0300 Subject: [PATCH] refactor: update reconnection logic to prevent reconnection in cases of banishment or blocking Handled specific errors to improve reconnection logic: - 401: Triggered logout to handle unauthorized access. - 402: Recognized as temporary ban, reconnection attempts paused. - 403: Recognized as forbidden, reconnection attempts stopped. - 406: Recognized as permanent ban, reconnection attempts halted. --- src/api/services/channels/whatsapp.baileys.service.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/api/services/channels/whatsapp.baileys.service.ts b/src/api/services/channels/whatsapp.baileys.service.ts index 714deea4..e0ff6785 100644 --- a/src/api/services/channels/whatsapp.baileys.service.ts +++ b/src/api/services/channels/whatsapp.baileys.service.ts @@ -388,7 +388,9 @@ export class BaileysStartupService extends ChannelStartupService { } if (connection === 'close') { - const shouldReconnect = (lastDisconnect.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut; + const statusCode = (lastDisconnect?.error as Boom)?.output?.statusCode; + const codesToNotReconnect = [DisconnectReason.loggedOut, DisconnectReason.forbidden, 402, 406]; + const shouldReconnect = !codesToNotReconnect.includes(statusCode); if (shouldReconnect) { await this.connectToWhatsapp(this.phoneNumber); } else {