From 5d951a96b5d4cae02dbc6f5d06461df0e67fa929 Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Tue, 9 Apr 2024 07:40:45 -0300 Subject: [PATCH] adjusts in redis --- src/libs/redis.client.ts | 8 ++++---- .../controllers/instance.controller.ts | 4 ++-- .../services/whatsapp.baileys.service.ts | 19 ++++++++++--------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/libs/redis.client.ts b/src/libs/redis.client.ts index c1a0fd84..4b3e1991 100644 --- a/src/libs/redis.client.ts +++ b/src/libs/redis.client.ts @@ -72,7 +72,7 @@ export class RedisCache { try { this.logger.verbose('setData: ' + field); const json = JSON.stringify(data, BufferJSON.replacer); - await this.client.hSet(`${this.redisEnv.PREFIX_KEY}-${this.instanceName}`, field, json); + await this.client.hSet(this.redisEnv.PREFIX_KEY + ':' + this.instanceName, field, json); return true; } catch (error) { this.logger.error(error); @@ -83,7 +83,7 @@ export class RedisCache { public async getData(field: string): Promise { try { this.logger.verbose('getData: ' + field); - const data = await this.client.hGet(`${this.redisEnv.PREFIX_KEY}-${this.instanceName}`, field); + const data = await this.client.hGet(this.redisEnv.PREFIX_KEY + ':' + this.instanceName, field); if (data) { this.logger.verbose('getData: ' + field + ' success'); @@ -101,7 +101,7 @@ export class RedisCache { public async removeData(field: string): Promise { try { this.logger.verbose('removeData: ' + field); - await this.client.hDel(`${this.redisEnv.PREFIX_KEY}-${this.instanceName}`, field); + await this.client.hDel(this.redisEnv.PREFIX_KEY + ':' + this.instanceName, field); return true; } catch (error) { this.logger.error(error); @@ -111,7 +111,7 @@ export class RedisCache { public async delAll(hash?: string): Promise { try { - const targetHash = hash || `${this.redisEnv.PREFIX_KEY}-${this.instanceName}`; + const targetHash = hash || this.redisEnv.PREFIX_KEY + ':' + this.instanceName; this.logger.verbose('instance delAll: ' + targetHash); const result = await this.client.del(targetHash); return !!result; diff --git a/src/whatsapp/controllers/instance.controller.ts b/src/whatsapp/controllers/instance.controller.ts index c389b819..8fab7f2f 100644 --- a/src/whatsapp/controllers/instance.controller.ts +++ b/src/whatsapp/controllers/instance.controller.ts @@ -641,8 +641,8 @@ export class InstanceController { const instance = this.waMonitor.waInstances[instanceName]; console.log('mobileCode', mobileCode); - return await instance.receiveMobileCode(mobileCode); - // return { status: 'SUCCESS', error: false, response: { message: 'Mobile code registered' } }; + await instance.receiveMobileCode(mobileCode); + return { status: 'SUCCESS', error: false, response: { message: 'Mobile code registered' } }; } catch (error) { this.logger.error(error); } diff --git a/src/whatsapp/services/whatsapp.baileys.service.ts b/src/whatsapp/services/whatsapp.baileys.service.ts index 9f0475cd..e3f698b5 100644 --- a/src/whatsapp/services/whatsapp.baileys.service.ts +++ b/src/whatsapp/services/whatsapp.baileys.service.ts @@ -634,15 +634,16 @@ export class BaileysStartupService extends WAStartupService { } public async receiveMobileCode(code: string) { - await this.client - .register(code.replace(/["']/g, '').trim().toLowerCase()) - .then(async (response) => { - this.logger.verbose('Registration code received successfully'); - console.log(response); - }) - .catch((error) => { - this.logger.error(error); - }); + console.log('code', code); + // await this.client + // .register(code.replace(/["']/g, '').trim().toLowerCase()) + // .then(async (response) => { + // this.logger.verbose('Registration code received successfully'); + // console.log(response); + // }) + // .catch((error) => { + // this.logger.error(error); + // }); } public async reloadConnection(): Promise {