From f7293255cf05d74c6c33ba887bc7774d926fcd5d Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Mon, 24 Jul 2023 18:21:11 -0300 Subject: [PATCH 1/3] fix: Fixed reconnect with pairing code or qrcode --- CHANGELOG.md | 6 ++++++ src/whatsapp/controllers/instance.controller.ts | 4 ++-- src/whatsapp/services/whatsapp.service.ts | 10 +++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bb71df6..2d62c451 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 1.4.1 (homolog) + +### Fixed + +* Fixed reconnect with pairing code or qrcode + # 1.4.0 (2023-07-24 17:03) ### Features diff --git a/src/whatsapp/controllers/instance.controller.ts b/src/whatsapp/controllers/instance.controller.ts index ef930c7b..fa3b0812 100644 --- a/src/whatsapp/controllers/instance.controller.ts +++ b/src/whatsapp/controllers/instance.controller.ts @@ -107,7 +107,7 @@ export class InstanceController { if (qrcode) { this.logger.verbose('creating qrcode'); await instance.connectToWhatsapp(number); - await delay(3000); + await delay(5000); getQrcode = instance.qrCode; } @@ -214,7 +214,7 @@ export class InstanceController { this.logger.verbose('connecting'); await instance.connectToWhatsapp(number); - await delay(2000); + await delay(5000); return instance.qrCode; } diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index d475988a..37ec3341 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -606,11 +606,14 @@ export class WAStartupService { color: { light: '#ffffff', dark: '#198754' }, }; + console.log(this.phoneNumber); if (this.phoneNumber) { await delay(2000); this.instance.qrcode.pairingCode = await this.client.requestPairingCode( this.phoneNumber, ); + } else { + this.instance.qrcode.pairingCode = null; } this.logger.verbose('Generating QR code'); @@ -894,13 +897,6 @@ export class WAStartupService { this.phoneNumber = number; - // if (number) { - // this.logger.verbose('creating pairing code'); - // await delay(5000); - // this.phoneNumber = number; - // this.instance.qrcode.pairingCode = await this.client.requestPairingCode(number); - // } - return this.client; } catch (error) { this.logger.error(error); From f9abd90cc9044961eb2078132f6c538433135614 Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Mon, 24 Jul 2023 18:28:01 -0300 Subject: [PATCH 2/3] fix: connection state --- CHANGELOG.md | 1 + src/validate/validate.schema.ts | 2 -- src/whatsapp/controllers/instance.controller.ts | 17 +++++++++++------ src/whatsapp/services/whatsapp.service.ts | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d62c451..b9672e6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Fixed * Fixed reconnect with pairing code or qrcode +* Fixed problem in createJid # 1.4.0 (2023-07-24 17:03) diff --git a/src/validate/validate.schema.ts b/src/validate/validate.schema.ts index 18a070ab..aea723ca 100644 --- a/src/validate/validate.schema.ts +++ b/src/validate/validate.schema.ts @@ -124,7 +124,6 @@ const optionsSchema: JSONSchema7 = { const numberDefinition: JSONSchema7Definition = { type: 'string', - // pattern: '^\\d+[\\.@\\w-]+', description: 'Invalid format', }; @@ -446,7 +445,6 @@ export const whatsappNumberSchema: JSONSchema7 = { uniqueItems: true, items: { type: 'string', - // pattern: '^\\d+', description: '"numbers" must be an array of numeric strings', }, }, diff --git a/src/whatsapp/controllers/instance.controller.ts b/src/whatsapp/controllers/instance.controller.ts index fa3b0812..7322e194 100644 --- a/src/whatsapp/controllers/instance.controller.ts +++ b/src/whatsapp/controllers/instance.controller.ts @@ -245,7 +245,12 @@ export class InstanceController { public async connectionState({ instanceName }: InstanceDto) { this.logger.verbose('requested connectionState from ' + instanceName + ' instance'); - return this.waMonitor.waInstances[instanceName]?.connectionStatus; + return { + instance: { + instanceName: instanceName, + state: this.waMonitor.waInstances[instanceName]?.connectionStatus?.state, + }, + }; } public async fetchInstances({ instanceName }: InstanceDto) { @@ -260,9 +265,9 @@ export class InstanceController { public async logout({ instanceName }: InstanceDto) { this.logger.verbose('requested logout from ' + instanceName + ' instance'); - const stateConn = await this.connectionState({ instanceName }); + const { instance } = await this.connectionState({ instanceName }); - if (stateConn.state === 'close') { + if (instance.state === 'close') { throw new BadRequestException( 'The "' + instanceName + '" instance is not connected', ); @@ -285,15 +290,15 @@ export class InstanceController { public async deleteInstance({ instanceName }: InstanceDto) { this.logger.verbose('requested deleteInstance from ' + instanceName + ' instance'); - const stateConn = await this.connectionState({ instanceName }); + const { instance } = await this.connectionState({ instanceName }); - if (stateConn.state === 'open') { + if (instance.state === 'open') { throw new BadRequestException( 'The "' + instanceName + '" instance needs to be disconnected', ); } try { - if (stateConn.state === 'connecting') { + if (instance.state === 'connecting') { this.logger.verbose('logging out instance: ' + instanceName); await this.logout({ instanceName }); diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index 37ec3341..6c7c96f0 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -1517,7 +1517,7 @@ export class WAStartupService { .split(/\:/)[0] .split('@')[0]; - if (number.includes('-') && number.length >= 24) { + if (number.length >= 18) { this.logger.verbose('Jid created is group: ' + `${number}@g.us`); number = number.replace(/[^\d-]/g, ''); return `${number}@g.us`; From 8d1f2313ac002b179cd7ed79089f83a28bb2b326 Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Mon, 24 Jul 2023 18:28:39 -0300 Subject: [PATCH 3/3] version: 1.4.1 --- CHANGELOG.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9672e6d..7dd59c0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# 1.4.1 (homolog) +# 1.4.1 (2023-07-24 18:28) ### Fixed diff --git a/package.json b/package.json index 92745ead..1145676d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "evolution-api", - "version": "1.4.0", + "version": "1.4.1", "description": "Rest api for communication with WhatsApp", "main": "./dist/src/main.js", "scripts": {