diff --git a/CHANGELOG.md b/CHANGELOG.md index 05b3e4f7..ef049988 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * Fixed loading of selects in the manager * Add restart button to sessions screen * Adjustments to docker files +* StopBotFromMe working with chatwoot # 2.0.8-rc (2024-08-08 20:23) diff --git a/src/api/integrations/dify/services/dify.service.ts b/src/api/integrations/dify/services/dify.service.ts index fb658cfa..9a618b1b 100644 --- a/src/api/integrations/dify/services/dify.service.ts +++ b/src/api/integrations/dify/services/dify.service.ts @@ -977,23 +977,14 @@ export class DifyService { }; if (stopBotFromMe && key.fromMe && session) { - if (keepOpen) { - await this.prismaRepository.difySession.update({ - where: { - id: session.id, - }, - data: { - status: 'closed', - }, - }); - } else { - await this.prismaRepository.difySession.deleteMany({ - where: { - difyId: findDify.id, - remoteJid: remoteJid, - }, - }); - } + await this.prismaRepository.difySession.update({ + where: { + id: session.id, + }, + data: { + status: 'paused', + }, + }); return; } diff --git a/src/api/integrations/openai/services/openai.service.ts b/src/api/integrations/openai/services/openai.service.ts index 021e1df9..8846924a 100644 --- a/src/api/integrations/openai/services/openai.service.ts +++ b/src/api/integrations/openai/services/openai.service.ts @@ -1180,23 +1180,14 @@ export class OpenaiService { }; if (stopBotFromMe && key.fromMe && session) { - if (keepOpen) { - await this.prismaRepository.openaiSession.update({ - where: { - id: session.id, - }, - data: { - status: 'closed', - }, - }); - } else { - await this.prismaRepository.openaiSession.deleteMany({ - where: { - openaiBotId: findOpenai.id, - remoteJid: remoteJid, - }, - }); - } + await this.prismaRepository.openaiSession.update({ + where: { + id: session.id, + }, + data: { + status: 'paused', + }, + }); return; } diff --git a/src/api/integrations/typebot/services/typebot.service.ts b/src/api/integrations/typebot/services/typebot.service.ts index 435ec744..80067718 100644 --- a/src/api/integrations/typebot/services/typebot.service.ts +++ b/src/api/integrations/typebot/services/typebot.service.ts @@ -1559,23 +1559,14 @@ export class TypebotService { }; if (stopBotFromMe && key.fromMe && session) { - if (keepOpen) { - await this.prismaRepository.typebotSession.update({ - where: { - id: session.id, - }, - data: { - status: 'closed', - }, - }); - } else { - await this.prismaRepository.typebotSession.deleteMany({ - where: { - typebotId: findTypebot.id, - remoteJid: remoteJid, - }, - }); - } + await this.prismaRepository.typebotSession.update({ + where: { + id: session.id, + }, + data: { + status: 'paused', + }, + }); return; } diff --git a/src/api/services/channels/whatsapp.baileys.service.ts b/src/api/services/channels/whatsapp.baileys.service.ts index 8b67e145..118e458b 100644 --- a/src/api/services/channels/whatsapp.baileys.service.ts +++ b/src/api/services/channels/whatsapp.baileys.service.ts @@ -2014,6 +2014,36 @@ export class BaileysStartupService extends ChannelStartupService { ); } + if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot.enabled && isIntegration) { + if (this.configService.get('TYPEBOT').ENABLED) { + if (messageRaw.messageType !== 'reactionMessage') + await this.typebotService.sendTypebot( + { instanceName: this.instance.name, instanceId: this.instanceId }, + messageRaw.key.remoteJid, + messageRaw, + ); + } + + if (this.configService.get('OPENAI').ENABLED) { + if (messageRaw.messageType !== 'reactionMessage') + await this.openaiService.sendOpenai( + { instanceName: this.instance.name, instanceId: this.instanceId }, + messageRaw.key.remoteJid, + messageRaw, + ); + } + + if (this.configService.get('DIFY').ENABLED) { + console.log('DIFY messageRaw', messageRaw); + if (messageRaw.messageType !== 'reactionMessage') + await this.difyService.sendDify( + { instanceName: this.instance.name, instanceId: this.instanceId }, + messageRaw.key.remoteJid, + messageRaw, + ); + } + } + if (this.configService.get('DATABASE').SAVE_DATA.NEW_MESSAGE) await this.prismaRepository.message.create({ data: messageRaw, diff --git a/src/api/services/channels/whatsapp.business.service.ts b/src/api/services/channels/whatsapp.business.service.ts index dbab3edb..cd7ab4a6 100644 --- a/src/api/services/channels/whatsapp.business.service.ts +++ b/src/api/services/channels/whatsapp.business.service.ts @@ -948,6 +948,35 @@ export class BusinessStartupService extends ChannelStartupService { ); } + if (this.configService.get('CHATWOOT').ENABLED && this.localChatwoot.enabled && isIntegration) { + if (this.configService.get('TYPEBOT').ENABLED) { + if (messageRaw.messageType !== 'reactionMessage') + await this.typebotService.sendTypebot( + { instanceName: this.instance.name, instanceId: this.instanceId }, + messageRaw.key.remoteJid, + messageRaw, + ); + } + + if (this.configService.get('OPENAI').ENABLED) { + if (messageRaw.messageType !== 'reactionMessage') + await this.openaiService.sendOpenai( + { instanceName: this.instance.name, instanceId: this.instanceId }, + messageRaw.key.remoteJid, + messageRaw, + ); + } + + if (this.configService.get('DIFY').ENABLED) { + if (messageRaw.messageType !== 'reactionMessage') + await this.difyService.sendDify( + { instanceName: this.instance.name, instanceId: this.instanceId }, + messageRaw.key.remoteJid, + messageRaw, + ); + } + } + await this.prismaRepository.message.create({ data: messageRaw, });