Skip to content

Commit 3d253ff

Browse files
committed
Correção de bug: Loop infinito de reconexão do código QR
1 parent cd800f2 commit 3d253ff

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,19 @@ export class BaileysStartupService extends ChannelStartupService {
426426
if (connection === 'close') {
427427
const statusCode = (lastDisconnect?.error as Boom)?.output?.statusCode;
428428
const codesToNotReconnect = [DisconnectReason.loggedOut, DisconnectReason.forbidden, 402, 406];
429+
430+
// FIX: Não reconectar se é primeira conexão (aguardando QR code)
431+
// Isso evita loop infinito que impede geração do QR
432+
const isInitialConnection = !this.instance.wuid && this.instance.qrcode.count === 0;
433+
434+
if (isInitialConnection) {
435+
this.logger.info('Initial connection closed, waiting for QR code generation...');
436+
return;
437+
}
438+
429439
const shouldReconnect = !codesToNotReconnect.includes(statusCode);
430440
if (shouldReconnect) {
441+
this.logger.warn(`Connection lost (status: ${statusCode}), reconnecting...`);
431442
await this.connectToWhatsapp(this.phoneNumber);
432443
} else {
433444
this.sendDataWebhook(Events.STATUS_INSTANCE, {

0 commit comments

Comments
 (0)