From e2c67d7dae657594555cd332c6ba8d26f2ab794a Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Mon, 19 Feb 2024 16:04:48 -0300 Subject: [PATCH] fix: integration --- src/whatsapp/controllers/instance.controller.ts | 3 ++- src/whatsapp/services/monitor.service.ts | 10 +++++++++- src/whatsapp/services/whatsapp.baileys.service.ts | 15 ++++++++++++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/whatsapp/controllers/instance.controller.ts b/src/whatsapp/controllers/instance.controller.ts index 08fa28e8..e106aca7 100644 --- a/src/whatsapp/controllers/instance.controller.ts +++ b/src/whatsapp/controllers/instance.controller.ts @@ -105,7 +105,6 @@ export class InstanceController { this.cache, this.chatwootCache, ); - await this.waMonitor.saveInstance({ integration, instanceName, token, number }); } else { instance = new BaileysStartupService( this.configService, @@ -116,6 +115,8 @@ export class InstanceController { ); } + await this.waMonitor.saveInstance({ integration, instanceName, token, number }); + instance.instanceName = instanceName; const instanceId = v4(); diff --git a/src/whatsapp/services/monitor.service.ts b/src/whatsapp/services/monitor.service.ts index a2899d7c..0b6f5863 100644 --- a/src/whatsapp/services/monitor.service.ts +++ b/src/whatsapp/services/monitor.service.ts @@ -347,6 +347,8 @@ export class WAMonitoringService { this.cache, this.chatwootCache, ); + + instance.instanceName = name; } else { instance = new BaileysStartupService( this.configService, @@ -355,8 +357,14 @@ export class WAMonitoringService { this.cache, this.chatwootCache, ); + + instance.instanceName = name; + + if (!integration) { + await instance.setIntegration({ integration: Integration.WHATSAPP_BAILEYS }); + } } - instance.instanceName = name; + this.logger.verbose('Instance loaded: ' + name); await instance.connectToWhatsapp(); this.logger.verbose('connectToWhatsapp: ' + name); diff --git a/src/whatsapp/services/whatsapp.baileys.service.ts b/src/whatsapp/services/whatsapp.baileys.service.ts index e471bef2..0fc4f541 100644 --- a/src/whatsapp/services/whatsapp.baileys.service.ts +++ b/src/whatsapp/services/whatsapp.baileys.service.ts @@ -2020,13 +2020,22 @@ export class BaileysStartupService extends WAStartupService { if (mediaMessage.mimetype) { mimetype = mediaMessage.mimetype; } else { - if (isURL(mediaMessage.media)) { + mimetype = getMIMEType(mediaMessage.fileName); + + if (!mimetype && isURL(mediaMessage.media)) { const response = await axios.get(mediaMessage.media, { responseType: 'arraybuffer' }); mimetype = response.headers['content-type']; - } else { - mimetype = getMIMEType(mediaMessage.fileName); } + // if (isURL(mediaMessage.media)) { + // const response = await axios.get(mediaMessage.media, { responseType: 'arraybuffer' }); + + // mimetype = response.headers['content-type']; + // console.log('mediaMessage.mimetype2', mimetype); + // } else { + // mimetype = getMIMEType(mediaMessage.fileName); + // console.log('mediaMessage.mimetype3', mimetype); + // } } this.logger.verbose('Mimetype: ' + mimetype);