Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/api/integrations/channel/meta/whatsapp.business.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,29 +668,30 @@ export class BusinessStartupService extends ChannelStartupService {

sendTelemetry(`received.message.${messageRaw.messageType ?? 'unknown'}`);

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,
});

// 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?.id) {
if (chatwootSentMessage) {
messageRaw.chatwootMessageId = chatwootSentMessage.id;
messageRaw.chatwootInboxId = chatwootSentMessage.id;
messageRaw.chatwootConversationId = chatwootSentMessage.id;
messageRaw.chatwootInboxId = chatwootSentMessage.inbox_id;
messageRaw.chatwootConversationId = chatwootSentMessage.conversation_id;
}
}

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,
});

if (!this.isMediaMessage(message) && message.type !== 'sticker') {
await this.prismaRepository.message.create({
data: messageRaw,
Expand Down
6 changes: 3 additions & 3 deletions src/api/integrations/chatbot/base-chatbot.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/utils/findBotByTrigger.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/getConversationMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ export const getConversationMessage = (msg: any) => {

const messageContent = getMessageContent(types);

return messageContent;
return messageContent ?? '';
};