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.
This commit is contained in:
Davidson Gomes 2025-06-13 09:10:29 -03:00
parent 534c54a171
commit c17b48bca0

View File

@ -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) {