mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-08-29 02:36:11 -06:00
Add develop debug branch
This commit is contained in:
parent
9cdb897a0f
commit
2786f17008
@ -775,29 +775,46 @@ export abstract class BaseChatbotController<BotType = any, BotData extends BaseC
|
|||||||
|
|
||||||
// Base implementation for emit
|
// Base implementation for emit
|
||||||
public async emit({ instance, remoteJid, msg }: EmitData) {
|
public async emit({ instance, remoteJid, msg }: EmitData) {
|
||||||
if (!this.integrationEnabled) return;
|
this.logger.log(`🚀 [${this.integrationName}] EMIT STARTED - remoteJid: ${remoteJid}, instance: ${instance.instanceName}`);
|
||||||
|
|
||||||
|
if (!this.integrationEnabled) {
|
||||||
|
this.logger.warn(`❌ [${this.integrationName}] Integration is DISABLED`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
this.logger.log(`🔍 [${this.integrationName}] Looking for settings...`);
|
||||||
const settings = await this.settingsRepository.findFirst({
|
const settings = await this.settingsRepository.findFirst({
|
||||||
where: {
|
where: {
|
||||||
instanceId: instance.instanceId,
|
instanceId: instance.instanceId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.checkIgnoreJids(settings?.ignoreJids, remoteJid)) return;
|
this.logger.log(`⚙️ [${this.integrationName}] Settings found: ${settings ? 'YES' : 'NO'}`);
|
||||||
|
|
||||||
|
if (this.checkIgnoreJids(settings?.ignoreJids, remoteJid)) {
|
||||||
|
this.logger.warn(`🚫 [${this.integrationName}] Message ignored due to ignoreJids`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.log(`🔍 [${this.integrationName}] Looking for session...`);
|
||||||
const session = await this.getSession(remoteJid, instance);
|
const session = await this.getSession(remoteJid, instance);
|
||||||
|
this.logger.log(`📱 [${this.integrationName}] Session found: ${session ? 'YES' : 'NO'}`);
|
||||||
|
|
||||||
const content = getConversationMessage(msg);
|
const content = getConversationMessage(msg);
|
||||||
|
this.logger.log(`💬 [${this.integrationName}] Content: ${content}`);
|
||||||
|
|
||||||
// Get integration type
|
// Get integration type
|
||||||
// const integrationType = this.getIntegrationType();
|
// const integrationType = this.getIntegrationType();
|
||||||
|
|
||||||
// Find a bot for this message
|
// Find a bot for this message
|
||||||
|
this.logger.log(`🤖 [${this.integrationName}] Looking for bot trigger...`);
|
||||||
let findBot: any = await this.findBotTrigger(this.botRepository, content, instance, session);
|
let findBot: any = await this.findBotTrigger(this.botRepository, content, instance, session);
|
||||||
|
this.logger.log(`🤖 [${this.integrationName}] Bot found: ${findBot ? 'YES' : 'NO'} - ID: ${findBot?.id || 'NONE'}`);
|
||||||
|
|
||||||
// If no bot is found, try to use fallback
|
// If no bot is found, try to use fallback
|
||||||
if (!findBot) {
|
if (!findBot) {
|
||||||
|
this.logger.warn(`⚠️ [${this.integrationName}] No bot found, trying fallback...`);
|
||||||
const fallback = await this.settingsRepository.findFirst({
|
const fallback = await this.settingsRepository.findFirst({
|
||||||
where: {
|
where: {
|
||||||
instanceId: instance.instanceId,
|
instanceId: instance.instanceId,
|
||||||
@ -806,6 +823,7 @@ export abstract class BaseChatbotController<BotType = any, BotData extends BaseC
|
|||||||
|
|
||||||
// Get the fallback ID for this integration type
|
// Get the fallback ID for this integration type
|
||||||
const fallbackId = this.getFallbackBotId(fallback);
|
const fallbackId = this.getFallbackBotId(fallback);
|
||||||
|
this.logger.log(`🔄 [${this.integrationName}] Fallback ID: ${fallbackId || 'NONE'}`);
|
||||||
|
|
||||||
if (fallbackId) {
|
if (fallbackId) {
|
||||||
const findFallback = await this.botRepository.findFirst({
|
const findFallback = await this.botRepository.findFirst({
|
||||||
@ -815,13 +833,16 @@ export abstract class BaseChatbotController<BotType = any, BotData extends BaseC
|
|||||||
});
|
});
|
||||||
|
|
||||||
findBot = findFallback;
|
findBot = findFallback;
|
||||||
|
this.logger.log(`🔄 [${this.integrationName}] Fallback bot found: ${findFallback ? 'YES' : 'NO'}`);
|
||||||
} else {
|
} else {
|
||||||
|
this.logger.warn(`❌ [${this.integrationName}] No fallback bot available`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we still don't have a bot, return
|
// If we still don't have a bot, return
|
||||||
if (!findBot) {
|
if (!findBot) {
|
||||||
|
this.logger.warn(`❌ [${this.integrationName}] Still no bot found, returning`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -904,29 +925,42 @@ export abstract class BaseChatbotController<BotType = any, BotData extends BaseC
|
|||||||
|
|
||||||
// Process with debounce if needed
|
// Process with debounce if needed
|
||||||
if (debounceTime && debounceTime > 0) {
|
if (debounceTime && debounceTime > 0) {
|
||||||
|
this.logger.log(`⏱️ [${this.integrationName}] Processing with debounce (${debounceTime}s)...`);
|
||||||
this.processDebounce(this.userMessageDebounce, content, remoteJid, debounceTime, async (debouncedContent) => {
|
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(
|
await this.processBot(
|
||||||
this.waMonitor.waInstances[instance.instanceName],
|
this.waMonitor.waInstances[instance.instanceName],
|
||||||
remoteJid,
|
remoteJid,
|
||||||
findBot,
|
findBot,
|
||||||
session,
|
session,
|
||||||
mergedSettings,
|
mergedSettings,
|
||||||
debouncedContent,
|
content,
|
||||||
msg?.pushName,
|
msg?.pushName,
|
||||||
msg,
|
msg,
|
||||||
);
|
);
|
||||||
});
|
this.logger.log(`✅ [${this.integrationName}] processBot completed successfully`);
|
||||||
} else {
|
} catch (error) {
|
||||||
await this.processBot(
|
this.logger.error(`❌ [${this.integrationName}] Error in processBot: ${error.message}`);
|
||||||
this.waMonitor.waInstances[instance.instanceName],
|
}
|
||||||
remoteJid,
|
|
||||||
findBot,
|
|
||||||
session,
|
|
||||||
mergedSettings,
|
|
||||||
content,
|
|
||||||
msg?.pushName,
|
|
||||||
msg,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(error);
|
this.logger.error(error);
|
||||||
|
@ -52,7 +52,10 @@ export class OpenaiService extends BaseChatbotService<OpenaiBot, OpenaiSetting>
|
|||||||
msg?: any,
|
msg?: any,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
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
|
// Handle audio message transcription
|
||||||
if (content.startsWith('audioMessage|') && msg) {
|
if (content.startsWith('audioMessage|') && msg) {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import { advancedOperatorsSearch } from './advancedOperatorsSearch';
|
import { advancedOperatorsSearch } from './advancedOperatorsSearch';
|
||||||
|
|
||||||
export const findBotByTrigger = async (botRepository: any, content: string, instanceId: string) => {
|
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)
|
// Check for triggerType 'all' or 'none' (both should match any message)
|
||||||
const findTriggerAllOrNone = await botRepository.findFirst({
|
const findTriggerAllOrNone = await botRepository.findFirst({
|
||||||
where: {
|
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) {
|
if (findTriggerAllOrNone) {
|
||||||
|
console.log(`✅ [findBotByTrigger] Returning bot with triggerType: ${findTriggerAllOrNone.triggerType}`);
|
||||||
return findTriggerAllOrNone;
|
return findTriggerAllOrNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user