Skip to content
Closed
2 changes: 1 addition & 1 deletion .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 15 additions & 4 deletions src/whatsapp/services/whatsapp.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export class WAStartupService {
this.configService.get<Database>('DATABASE');

private endSession = false;
private inReconnection = false;
public client: WASocket;
private authState: Partial<AuthState> = {};
private authStateProvider: AuthStateProvider;
Expand Down Expand Up @@ -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', {
Expand Down Expand Up @@ -568,12 +569,22 @@ export class WAStartupService {
public async connectToWhatsapp(): Promise<WASocket> {
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());
}
Expand Down
Loading