From 2786f1700898ce4e6ef7661d5bdd132ff89d9ef7 Mon Sep 17 00:00:00 2001 From: Saulo Mendes Martins Date: Thu, 21 Aug 2025 07:36:41 -0300 Subject: [PATCH] Add develop debug branch --- .../chatbot/base-chatbot.controller.ts | 64 ++++++++++++++----- .../chatbot/openai/services/openai.service.ts | 5 +- src/utils/findBotByTrigger.ts | 5 ++ 3 files changed, 58 insertions(+), 16 deletions(-) diff --git a/src/api/integrations/chatbot/base-chatbot.controller.ts b/src/api/integrations/chatbot/base-chatbot.controller.ts index 3a472cd8..f72d8c3a 100644 --- a/src/api/integrations/chatbot/base-chatbot.controller.ts +++ b/src/api/integrations/chatbot/base-chatbot.controller.ts @@ -775,29 +775,46 @@ export abstract class BaseChatbotController 0) { + this.logger.log(`⏱️ [${this.integrationName}] Processing with debounce (${debounceTime}s)...`); this.processDebounce(this.userMessageDebounce, content, remoteJid, debounceTime, async (debouncedContent) => { + this.logger.log(`🚀 [${this.integrationName}] Debounce complete! Calling processBot...`); + try { + await this.processBot( + this.waMonitor.waInstances[instance.instanceName], + remoteJid, + findBot, + session, + mergedSettings, + debouncedContent, + msg?.pushName, + msg, + ); + this.logger.log(`✅ [${this.integrationName}] processBot completed successfully`); + } catch (error) { + this.logger.error(`❌ [${this.integrationName}] Error in processBot: ${error.message}`); + } + }); + } else { + this.logger.log(`🚀 [${this.integrationName}] Processing without debounce...`); + try { await this.processBot( this.waMonitor.waInstances[instance.instanceName], remoteJid, findBot, session, mergedSettings, - debouncedContent, + content, msg?.pushName, msg, ); - }); - } else { - await this.processBot( - this.waMonitor.waInstances[instance.instanceName], - remoteJid, - findBot, - session, - mergedSettings, - content, - msg?.pushName, - msg, - ); + this.logger.log(`✅ [${this.integrationName}] processBot completed successfully`); + } catch (error) { + this.logger.error(`❌ [${this.integrationName}] Error in processBot: ${error.message}`); + } } } catch (error) { this.logger.error(error); diff --git a/src/api/integrations/chatbot/openai/services/openai.service.ts b/src/api/integrations/chatbot/openai/services/openai.service.ts index dd00b04c..8c299b48 100644 --- a/src/api/integrations/chatbot/openai/services/openai.service.ts +++ b/src/api/integrations/chatbot/openai/services/openai.service.ts @@ -52,7 +52,10 @@ export class OpenaiService extends BaseChatbotService msg?: any, ): Promise { try { - this.logger.log(`Starting process for remoteJid: ${remoteJid}, bot type: ${openaiBot.botType}`); + this.logger.log(`🚀 [OpenaiService] PROCESS STARTED - remoteJid: ${remoteJid}, bot type: ${openaiBot.botType}`); + this.logger.log(`🤖 [OpenaiService] Bot ID: ${openaiBot.id}, enabled: ${openaiBot.enabled}`); + this.logger.log(`💬 [OpenaiService] Content: "${content}"`); + this.logger.log(`📱 [OpenaiService] Session: ${session ? 'EXISTS' : 'NEW'}`); // Handle audio message transcription if (content.startsWith('audioMessage|') && msg) { diff --git a/src/utils/findBotByTrigger.ts b/src/utils/findBotByTrigger.ts index eea5db82..6d3bee92 100644 --- a/src/utils/findBotByTrigger.ts +++ b/src/utils/findBotByTrigger.ts @@ -1,6 +1,8 @@ import { advancedOperatorsSearch } from './advancedOperatorsSearch'; export const findBotByTrigger = async (botRepository: any, content: string, instanceId: string) => { + console.log(`🔍 [findBotByTrigger] Searching for bot - content: "${content}", instanceId: ${instanceId}`); + // Check for triggerType 'all' or 'none' (both should match any message) const findTriggerAllOrNone = await botRepository.findFirst({ where: { @@ -12,7 +14,10 @@ export const findBotByTrigger = async (botRepository: any, content: string, inst }, }); + console.log(`🤖 [findBotByTrigger] All/None trigger found: ${findTriggerAllOrNone ? 'YES' : 'NO'} - ID: ${findTriggerAllOrNone?.id || 'NONE'}`); + if (findTriggerAllOrNone) { + console.log(`✅ [findBotByTrigger] Returning bot with triggerType: ${findTriggerAllOrNone.triggerType}`); return findTriggerAllOrNone; }