Merge pull request #2429 from sosamilton/fix/meta-cloud-api-chatbot

Fix/meta cloud api chatbot
This commit is contained in:
Davidson Gomes
2026-02-24 12:18:46 -03:00
committed by GitHub
4 changed files with 28 additions and 18 deletions
@@ -668,6 +668,21 @@ export class BusinessStartupService extends ChannelStartupService {
sendTelemetry(`received.message.${messageRaw.messageType ?? 'unknown'}`);
// Normalized order: Chatwoot first, then bot (consistent with Baileys channel)
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled) {
const chatwootSentMessage = await this.chatwootService.eventWhatsapp(
Events.MESSAGES_UPSERT,
{ instanceName: this.instance.name, instanceId: this.instanceId },
messageRaw,
);
if (chatwootSentMessage) {
messageRaw.chatwootMessageId = chatwootSentMessage.id;
messageRaw.chatwootInboxId = chatwootSentMessage.inbox_id;
messageRaw.chatwootConversationId = chatwootSentMessage.conversation_id;
}
}
this.sendDataWebhook(Events.MESSAGES_UPSERT, messageRaw);
await chatbotController.emit({
@@ -677,20 +692,6 @@ export class BusinessStartupService extends ChannelStartupService {
pushName: messageRaw.pushName,
});
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled) {
const chatwootSentMessage = await this.chatwootService.eventWhatsapp(
Events.MESSAGES_UPSERT,
{ instanceName: this.instance.name, instanceId: this.instanceId },
messageRaw,
);
if (chatwootSentMessage?.id) {
messageRaw.chatwootMessageId = chatwootSentMessage.id;
messageRaw.chatwootInboxId = chatwootSentMessage.id;
messageRaw.chatwootConversationId = chatwootSentMessage.id;
}
}
if (!this.isMediaMessage(message) && message.type !== 'sticker') {
await this.prismaRepository.message.create({
data: messageRaw,
@@ -797,7 +797,7 @@ export abstract class BaseChatbotController<BotType = any, BotData extends BaseC
if (this.checkIgnoreJids(settings?.ignoreJids, remoteJid)) return;
const session = await this.getSession(remoteJid, instance);
let session = await this.getSession(remoteJid, instance);
const content = getConversationMessage(msg);
@@ -896,9 +896,9 @@ export abstract class BaseChatbotController<BotType = any, BotData extends BaseC
return;
}
// Skip if session exists but not awaiting user input
// If session is closed, nullify it so processBot creates a new conversation
if (session && session.status === 'closed') {
return;
session = null;
}
// Merged settings
+8
View File
@@ -1,6 +1,8 @@
import { advancedOperatorsSearch } from './advancedOperatorsSearch';
export const findBotByTrigger = async (botRepository: any, content: string, instanceId: string) => {
const normalizedContent = content?.trim() || '';
// Check for triggerType 'all' or 'none' (both should match any message)
const findTriggerAllOrNone = await botRepository.findFirst({
where: {
@@ -16,6 +18,12 @@ export const findBotByTrigger = async (botRepository: any, content: string, inst
return findTriggerAllOrNone;
}
// If content is empty (null, undefined, whitespace-only, or media-only messages),
// only 'all'/'none' triggers apply — skip keyword/regex matching
if (!normalizedContent) {
return null;
}
const findTriggerAdvanced = await botRepository.findMany({
where: {
enabled: true,
+2 -1
View File
@@ -85,5 +85,6 @@ const getMessageContent = (types: any) => {
export const getConversationMessage = (msg: any) => {
const types = getTypeMessage(msg);
const messageContent = getMessageContent(types);
return messageContent;
return messageContent ?? '';
};