@@ -775,29 +775,46 @@ export abstract class BaseChatbotController<BotType = any, BotData extends BaseC
775775
776776 // Base implementation for emit
777777 public async emit ( { instance, remoteJid, msg } : EmitData ) {
778- if ( ! this . integrationEnabled ) return ;
778+ this . logger . log ( `🚀 [${ this . integrationName } ] EMIT STARTED - remoteJid: ${ remoteJid } , instance: ${ instance . instanceName } ` ) ;
779+
780+ if ( ! this . integrationEnabled ) {
781+ this . logger . warn ( `❌ [${ this . integrationName } ] Integration is DISABLED` ) ;
782+ return ;
783+ }
779784
780785 try {
786+ this . logger . log ( `🔍 [${ this . integrationName } ] Looking for settings...` ) ;
781787 const settings = await this . settingsRepository . findFirst ( {
782788 where : {
783789 instanceId : instance . instanceId ,
784790 } ,
785791 } ) ;
792+
793+ this . logger . log ( `⚙️ [${ this . integrationName } ] Settings found: ${ settings ? 'YES' : 'NO' } ` ) ;
786794
787- if ( this . checkIgnoreJids ( settings ?. ignoreJids , remoteJid ) ) return ;
795+ if ( this . checkIgnoreJids ( settings ?. ignoreJids , remoteJid ) ) {
796+ this . logger . warn ( `🚫 [${ this . integrationName } ] Message ignored due to ignoreJids` ) ;
797+ return ;
798+ }
788799
800+ this . logger . log ( `🔍 [${ this . integrationName } ] Looking for session...` ) ;
789801 const session = await this . getSession ( remoteJid , instance ) ;
802+ this . logger . log ( `📱 [${ this . integrationName } ] Session found: ${ session ? 'YES' : 'NO' } ` ) ;
790803
791804 const content = getConversationMessage ( msg ) ;
805+ this . logger . log ( `💬 [${ this . integrationName } ] Content: ${ content } ` ) ;
792806
793807 // Get integration type
794808 // const integrationType = this.getIntegrationType();
795809
796810 // Find a bot for this message
811+ this . logger . log ( `🤖 [${ this . integrationName } ] Looking for bot trigger...` ) ;
797812 let findBot : any = await this . findBotTrigger ( this . botRepository , content , instance , session ) ;
813+ this . logger . log ( `🤖 [${ this . integrationName } ] Bot found: ${ findBot ? 'YES' : 'NO' } - ID: ${ findBot ?. id || 'NONE' } ` ) ;
798814
799815 // If no bot is found, try to use fallback
800816 if ( ! findBot ) {
817+ this . logger . warn ( `⚠️ [${ this . integrationName } ] No bot found, trying fallback...` ) ;
801818 const fallback = await this . settingsRepository . findFirst ( {
802819 where : {
803820 instanceId : instance . instanceId ,
@@ -806,6 +823,7 @@ export abstract class BaseChatbotController<BotType = any, BotData extends BaseC
806823
807824 // Get the fallback ID for this integration type
808825 const fallbackId = this . getFallbackBotId ( fallback ) ;
826+ this . logger . log ( `🔄 [${ this . integrationName } ] Fallback ID: ${ fallbackId || 'NONE' } ` ) ;
809827
810828 if ( fallbackId ) {
811829 const findFallback = await this . botRepository . findFirst ( {
@@ -815,13 +833,16 @@ export abstract class BaseChatbotController<BotType = any, BotData extends BaseC
815833 } ) ;
816834
817835 findBot = findFallback ;
836+ this . logger . log ( `🔄 [${ this . integrationName } ] Fallback bot found: ${ findFallback ? 'YES' : 'NO' } ` ) ;
818837 } else {
838+ this . logger . warn ( `❌ [${ this . integrationName } ] No fallback bot available` ) ;
819839 return ;
820840 }
821841 }
822842
823843 // If we still don't have a bot, return
824844 if ( ! findBot ) {
845+ this . logger . warn ( `❌ [${ this . integrationName } ] Still no bot found, returning` ) ;
825846 return ;
826847 }
827848
@@ -904,29 +925,42 @@ export abstract class BaseChatbotController<BotType = any, BotData extends BaseC
904925
905926 // Process with debounce if needed
906927 if ( debounceTime && debounceTime > 0 ) {
928+ this . logger . log ( `⏱️ [${ this . integrationName } ] Processing with debounce (${ debounceTime } s)...` ) ;
907929 this . processDebounce ( this . userMessageDebounce , content , remoteJid , debounceTime , async ( debouncedContent ) => {
930+ this . logger . log ( `🚀 [${ this . integrationName } ] Debounce complete! Calling processBot...` ) ;
931+ try {
932+ await this . processBot (
933+ this . waMonitor . waInstances [ instance . instanceName ] ,
934+ remoteJid ,
935+ findBot ,
936+ session ,
937+ mergedSettings ,
938+ debouncedContent ,
939+ msg ?. pushName ,
940+ msg ,
941+ ) ;
942+ this . logger . log ( `✅ [${ this . integrationName } ] processBot completed successfully` ) ;
943+ } catch ( error ) {
944+ this . logger . error ( `❌ [${ this . integrationName } ] Error in processBot: ${ error . message } ` ) ;
945+ }
946+ } ) ;
947+ } else {
948+ this . logger . log ( `🚀 [${ this . integrationName } ] Processing without debounce...` ) ;
949+ try {
908950 await this . processBot (
909951 this . waMonitor . waInstances [ instance . instanceName ] ,
910952 remoteJid ,
911953 findBot ,
912954 session ,
913955 mergedSettings ,
914- debouncedContent ,
956+ content ,
915957 msg ?. pushName ,
916958 msg ,
917959 ) ;
918- } ) ;
919- } else {
920- await this . processBot (
921- this . waMonitor . waInstances [ instance . instanceName ] ,
922- remoteJid ,
923- findBot ,
924- session ,
925- mergedSettings ,
926- content ,
927- msg ?. pushName ,
928- msg ,
929- ) ;
960+ this . logger . log ( `✅ [${ this . integrationName } ] processBot completed successfully` ) ;
961+ } catch ( error ) {
962+ this . logger . error ( `❌ [${ this . integrationName } ] Error in processBot: ${ error . message } ` ) ;
963+ }
930964 }
931965 } catch ( error ) {
932966 this . logger . error ( error ) ;
0 commit comments