Skip to content

Commit 7ed6a67

Browse files
committed
fix(meta): normalize execution order chatwoot-first and fix chatwootIds assignment bug
- Reorder Meta Business API to process Chatwoot before bot (consistent with Baileys) - Fix chatwootInboxId using .inbox_id instead of .id - Fix chatwootConversationId using .conversation_id instead of .id
1 parent cd800f2 commit 7ed6a67

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

src/api/integrations/channel/meta/whatsapp.business.service.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -668,15 +668,7 @@ export class BusinessStartupService extends ChannelStartupService {
668668

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

671-
this.sendDataWebhook(Events.MESSAGES_UPSERT, messageRaw);
672-
673-
await chatbotController.emit({
674-
instance: { instanceName: this.instance.name, instanceId: this.instanceId },
675-
remoteJid: messageRaw.key.remoteJid,
676-
msg: messageRaw,
677-
pushName: messageRaw.pushName,
678-
});
679-
671+
// Normalized order: Chatwoot first, then bot (consistent with Baileys channel)
680672
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled) {
681673
const chatwootSentMessage = await this.chatwootService.eventWhatsapp(
682674
Events.MESSAGES_UPSERT,
@@ -686,11 +678,22 @@ export class BusinessStartupService extends ChannelStartupService {
686678

687679
if (chatwootSentMessage?.id) {
688680
messageRaw.chatwootMessageId = chatwootSentMessage.id;
689-
messageRaw.chatwootInboxId = chatwootSentMessage.id;
690-
messageRaw.chatwootConversationId = chatwootSentMessage.id;
681+
messageRaw.chatwootInboxId = chatwootSentMessage.inbox_id;
682+
messageRaw.chatwootConversationId = chatwootSentMessage.conversation_id;
691683
}
692684
}
693685

686+
this.sendDataWebhook(Events.MESSAGES_UPSERT, messageRaw);
687+
688+
this.logger.log(`[CloudAPI] chatbotController.emit() remoteJid=${messageRaw.key.remoteJid}, messageType=${messageRaw.messageType}, fromMe=${messageRaw.key.fromMe}`);
689+
690+
await chatbotController.emit({
691+
instance: { instanceName: this.instance.name, instanceId: this.instanceId },
692+
remoteJid: messageRaw.key.remoteJid,
693+
msg: messageRaw,
694+
pushName: messageRaw.pushName,
695+
});
696+
694697
if (!this.isMediaMessage(message) && message.type !== 'sticker') {
695698
await this.prismaRepository.message.create({
696699
data: messageRaw,

0 commit comments

Comments
 (0)