From c17b48bca042a75164564641641f11b5b10e5468 Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Fri, 13 Jun 2025 09:10:29 -0300 Subject: [PATCH] fix(chatwoot.service): improve number retrieval logic for message senders - Enhanced the logic for retrieving sender numbers by introducing a new method that prioritizes senderPn, followed by participant and remoteJid. - This change ensures more reliable identification of message senders across different scenarios. --- .../chatbot/chatwoot/services/chatwoot.service.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts b/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts index 55ab1540..3fd655f0 100644 --- a/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts +++ b/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts @@ -569,7 +569,12 @@ export class ChatwootService { } // If it doesn't have @lid, return the normal number - return msg.key.participant?.split('@')[0] || msg.key.remoteJid?.split('@')[0]; + // Try to get the number from senderPn first, then participant, then remoteJid + const getNumber = (value: string) => { + return value?.includes('@s.whatsapp.net') ? value.split('@')[0] : value; + }; + + return getNumber(msg.key.senderPn) || getNumber(msg.key.participant) || getNumber(msg.key.remoteJid); } public async createConversation(instance: InstanceDto, body: any) {