diff --git a/.env.dev b/.env.dev index 4f8f1117..3a1ec0f6 100644 --- a/.env.dev +++ b/.env.dev @@ -65,7 +65,7 @@ INSTANCE_EXPIRATION_TIME=false CONFIG_SESSION_PHONE_CLIENT=CodeChat_V1 CONFIG_SESSION_PHONE_NAME=Edge -WA_VERSION=[ 2, 3000, 1015901307 ] +WA_VERSION=[ 2, 3000, 1023047013 ] # Set qrcode display limit QRCODE_LIMIT=5 diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index c303761c..ffcb2f66 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -194,6 +194,7 @@ export class WAStartupService { this.configService.get('DATABASE'); private endSession = false; + private inReconnection = false; public client: WASocket; private authState: Partial = {}; private authStateProvider: AuthStateProvider; @@ -440,7 +441,7 @@ export class WAStartupService { if (connection === 'close') { const shouldReconnect = (lastDisconnect.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut; - if (shouldReconnect) { + if (shouldReconnect && !this.inReconnection) { await this.connectToWhatsapp(); } else { this.sendDataWebhook('statusInstance', { @@ -568,12 +569,22 @@ export class WAStartupService { public async connectToWhatsapp(): Promise { try { this.instanceQr.count = 0; - await this.loadWebhook(); - this.client = await this.setSocket(); - this.eventHandler(); + const timeout = this.client ? 3000 : 0; + + if (!this.inReconnection) { + this.inReconnection = true; + setTimeout(async () => { + await this.loadWebhook(); + this.client = await this.setSocket(); + this.eventHandler(); + + this.inReconnection = false; + }, timeout); + } return this.client; } catch (error) { + this.inReconnection = false; this.logger.error(error); throw new InternalServerErrorException(error?.toString()); }