@@ -668,29 +668,30 @@ 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 ,
683675 { instanceName : this . instance . name , instanceId : this . instanceId } ,
684676 messageRaw ,
685677 ) ;
686678
687- if ( chatwootSentMessage ?. id ) {
679+ if ( chatwootSentMessage ) {
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+ await chatbotController . emit ( {
689+ instance : { instanceName : this . instance . name , instanceId : this . instanceId } ,
690+ remoteJid : messageRaw . key . remoteJid ,
691+ msg : messageRaw ,
692+ pushName : messageRaw . pushName ,
693+ } ) ;
694+
694695 if ( ! this . isMediaMessage ( message ) && message . type !== 'sticker' ) {
695696 await this . prismaRepository . message . create ( {
696697 data : messageRaw ,
0 commit comments