From e7d971867b4d417a2d4769b3f81cff62d5f40ff4 Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Wed, 21 Aug 2024 13:52:09 -0300 Subject: [PATCH] refactor: chatbot integration --- .../whatsapp/baileys/whatsapp.baileys.service.ts | 14 ++++++++------ .../whatsapp/business/whatsapp.business.service.ts | 13 +++++++------ src/api/integrations/chatbot/chatbot.controller.ts | 3 +++ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/api/integrations/channel/whatsapp/baileys/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/baileys/whatsapp.baileys.service.ts index f1c0378a..48be6750 100644 --- a/src/api/integrations/channel/whatsapp/baileys/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/baileys/whatsapp.baileys.service.ts @@ -2010,12 +2010,14 @@ export class BaileysStartupService extends ChannelStartupService { ); } - await chatbotController.emit({ - instance: { instanceName: this.instance.name, instanceId: this.instanceId }, - remoteJid: messageRaw.key.remoteJid, - msg: messageRaw, - pushName: messageRaw.pushName, - }); + if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot.enabled && isIntegration) + await chatbotController.emit({ + instance: { instanceName: this.instance.name, instanceId: this.instanceId }, + remoteJid: messageRaw.key.remoteJid, + msg: messageRaw, + pushName: messageRaw.pushName, + isIntegration, + }); if (this.configService.get('DATABASE').SAVE_DATA.NEW_MESSAGE) await this.prismaRepository.message.create({ diff --git a/src/api/integrations/channel/whatsapp/business/whatsapp.business.service.ts b/src/api/integrations/channel/whatsapp/business/whatsapp.business.service.ts index f6b4b56e..127adb81 100644 --- a/src/api/integrations/channel/whatsapp/business/whatsapp.business.service.ts +++ b/src/api/integrations/channel/whatsapp/business/whatsapp.business.service.ts @@ -923,12 +923,13 @@ export class BusinessStartupService extends ChannelStartupService { ); } - await chatbotController.emit({ - instance: { instanceName: this.instance.name, instanceId: this.instanceId }, - remoteJid: messageRaw.key.remoteJid, - msg: messageRaw, - pushName: messageRaw.pushName, - }); + if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot.enabled && isIntegration) + await chatbotController.emit({ + instance: { instanceName: this.instance.name, instanceId: this.instanceId }, + remoteJid: messageRaw.key.remoteJid, + msg: messageRaw, + pushName: messageRaw.pushName, + }); await this.prismaRepository.message.create({ data: messageRaw, diff --git a/src/api/integrations/chatbot/chatbot.controller.ts b/src/api/integrations/chatbot/chatbot.controller.ts index 7054f4f9..75aa4962 100644 --- a/src/api/integrations/chatbot/chatbot.controller.ts +++ b/src/api/integrations/chatbot/chatbot.controller.ts @@ -68,17 +68,20 @@ export class ChatbotController { remoteJid, msg, pushName, + isIntegration = false, }: { instance: InstanceDto; remoteJid: string; msg: any; pushName?: string; + isIntegration?: boolean; }): Promise { const emitData = { instance, remoteJid, msg, pushName, + isIntegration, }; // typebot await typebotController.emit(emitData);