From 7632ee7f99757f29e82be230926d6988955f8b21 Mon Sep 17 00:00:00 2001 From: Saulo Mendes Martins Date: Thu, 21 Aug 2025 07:45:23 -0300 Subject: [PATCH] Add develop debug branch --- .../whatsapp/baileysMessage.processor.ts | 5 ++- .../whatsapp/whatsapp.baileys.service.ts | 22 ++++++++--- .../chatbot/chatbot.controller.ts | 37 +++++++++++++++---- 3 files changed, 50 insertions(+), 14 deletions(-) diff --git a/src/api/integrations/channel/whatsapp/baileysMessage.processor.ts b/src/api/integrations/channel/whatsapp/baileysMessage.processor.ts index 79fedd93..589ee4f3 100644 --- a/src/api/integrations/channel/whatsapp/baileysMessage.processor.ts +++ b/src/api/integrations/channel/whatsapp/baileysMessage.processor.ts @@ -22,7 +22,10 @@ export class BaileysMessageProcessor { this.subscription = this.messageSubject .pipe( tap(({ messages }) => { - this.processorLogs.log(`Processing batch of ${messages.length} messages`); + this.processorLogs.log(`🚀 [BaileysMessageProcessor] Processing batch of ${messages.length} messages`); + messages.forEach((msg, index) => { + this.processorLogs.log(`📱 [BaileysMessageProcessor] Message ${index + 1}: ${msg.key?.remoteJid} - ${msg.message?.conversation || msg.message?.extendedTextMessage?.text || 'NO_TEXT'}`); + }); }), concatMap(({ messages, type, requestId, settings }) => from(onMessageReceive({ messages, type, requestId }, settings)).pipe( diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index 758a5bf9..ea2081b5 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -1047,7 +1047,10 @@ export class BaileysStartupService extends ChannelStartupService { settings: any, ) => { try { + this.logger.log(`🚀 [Baileys] MESSAGES.UPSERT STARTED - type: ${type}, messages: ${messages.length}`); + for (const received of messages) { + this.logger.log(`📱 [Baileys] Processing message: ${received.key.id} from ${received.key.remoteJid} - text: "${received.message?.conversation || received.message?.extendedTextMessage?.text || 'NO_TEXT'}"`); if (received.key.remoteJid?.includes('@lid') && received.key.senderPn) { (received.key as { previousRemoteJid?: string | null }).previousRemoteJid = received.key.remoteJid; received.key.remoteJid = received.key.senderPn; @@ -1336,12 +1339,19 @@ export class BaileysStartupService extends ChannelStartupService { this.sendDataWebhook(Events.MESSAGES_UPSERT, messageRaw); - await chatbotController.emit({ - instance: { instanceName: this.instance.name, instanceId: this.instanceId }, - remoteJid: messageRaw.key.remoteJid, - msg: messageRaw, - pushName: messageRaw.pushName, - }); + this.logger.log(`🤖 [Baileys] Calling chatbotController.emit for remoteJid: ${messageRaw.key.remoteJid}`); + + try { + await chatbotController.emit({ + instance: { instanceName: this.instance.name, instanceId: this.instanceId }, + remoteJid: messageRaw.key.remoteJid, + msg: messageRaw, + pushName: messageRaw.pushName, + }); + this.logger.log(`✅ [Baileys] chatbotController.emit completed successfully`); + } catch (error) { + this.logger.error(`❌ [Baileys] Error in chatbotController.emit: ${error.message}`); + } const contact = await this.prismaRepository.contact.findFirst({ where: { remoteJid: received.key.remoteJid, instanceId: this.instanceId }, diff --git a/src/api/integrations/chatbot/chatbot.controller.ts b/src/api/integrations/chatbot/chatbot.controller.ts index a2312f6e..3d7dcc45 100644 --- a/src/api/integrations/chatbot/chatbot.controller.ts +++ b/src/api/integrations/chatbot/chatbot.controller.ts @@ -84,6 +84,8 @@ export class ChatbotController { pushName?: string; isIntegration?: boolean; }): Promise { + this.logger.log(`🚀 [ChatbotController] EMIT STARTED - remoteJid: ${remoteJid}, instance: ${instance.instanceName}`); + const emitData = { instance, remoteJid, @@ -91,19 +93,40 @@ export class ChatbotController { pushName, isIntegration, }; - await evolutionBotController.emit(emitData); + + try { + this.logger.log(`🤖 [ChatbotController] Calling evolutionBotController.emit...`); + await evolutionBotController.emit(emitData); + this.logger.log(`✅ [ChatbotController] evolutionBotController.emit completed`); - await typebotController.emit(emitData); + this.logger.log(`🤖 [ChatbotController] Calling typebotController.emit...`); + await typebotController.emit(emitData); + this.logger.log(`✅ [ChatbotController] typebotController.emit completed`); - await openaiController.emit(emitData); + this.logger.log(`🤖 [ChatbotController] Calling openaiController.emit...`); + await openaiController.emit(emitData); + this.logger.log(`✅ [ChatbotController] openaiController.emit completed`); - await difyController.emit(emitData); + this.logger.log(`🤖 [ChatbotController] Calling difyController.emit...`); + await difyController.emit(emitData); + this.logger.log(`✅ [ChatbotController] difyController.emit completed`); - await n8nController.emit(emitData); + this.logger.log(`🤖 [ChatbotController] Calling n8nController.emit...`); + await n8nController.emit(emitData); + this.logger.log(`✅ [ChatbotController] n8nController.emit completed`); - await evoaiController.emit(emitData); + this.logger.log(`🤖 [ChatbotController] Calling evoaiController.emit...`); + await evoaiController.emit(emitData); + this.logger.log(`✅ [ChatbotController] evoaiController.emit completed`); - await flowiseController.emit(emitData); + this.logger.log(`🤖 [ChatbotController] Calling flowiseController.emit...`); + await flowiseController.emit(emitData); + this.logger.log(`✅ [ChatbotController] flowiseController.emit completed`); + + this.logger.log(`🎉 [ChatbotController] All controllers completed successfully`); + } catch (error) { + this.logger.error(`❌ [ChatbotController] Error in emit: ${error.message}`); + } } public processDebounce(