diff --git a/src/apps/chatwoot/client/ids.ts b/src/apps/chatwoot/client/ids.ts index b15a2c06..e4203f64 100644 --- a/src/apps/chatwoot/client/ids.ts +++ b/src/apps/chatwoot/client/ids.ts @@ -2,7 +2,7 @@ import { AttributeKey, INBOX_CONTACT_CHAT_ID } from '@waha/apps/chatwoot/const'; import * as lodash from 'lodash'; import { WhatsAppMessage } from '@waha/apps/chatwoot/storage'; import { buildMessageId } from '@waha/core/engines/noweb/session.noweb.core'; -import { isLidUser } from '@waha/core/utils/jids'; +import { isLidUser, normalizeJid } from '@waha/core/utils/jids'; export function GetJID(contact: any): string | null { return contact?.custom_attributes?.[AttributeKey.WA_JID]; @@ -23,20 +23,13 @@ export function GetAllChatIDs(contact: any): Array { attrs[AttributeKey.WA_JID], attrs[AttributeKey.WA_LID], ]; - return lodash.uniq(ids.filter(Boolean)); + return lodash.uniq(ids.filter(Boolean).map(normalizeJid)); } export function FindChatID(contact: any): string | null { - if (GetChatID(contact)) { - return GetChatID(contact); - } - if (GetJID(contact)) { - return GetJID(contact); - } - if (GetLID(contact)) { - return GetLID(contact); - } - return null; + const chatId = + GetChatID(contact) ?? GetJID(contact) ?? GetLID(contact) ?? null; + return chatId ? normalizeJid(chatId) : null; } export function SerializeWhatsAppKey(message: WhatsAppMessage): string { diff --git a/src/apps/chatwoot/contacts/WhatsAppContactInfo.ts b/src/apps/chatwoot/contacts/WhatsAppContactInfo.ts index 9dc31ba0..273184d4 100644 --- a/src/apps/chatwoot/contacts/WhatsAppContactInfo.ts +++ b/src/apps/chatwoot/contacts/WhatsAppContactInfo.ts @@ -13,6 +13,7 @@ import { isJidStatusBroadcast, isLidUser, isPnUser, + normalizeJid, } from '@waha/core/utils/jids'; import { UnknownJIDFormat } from '@waha/apps/chatwoot/errors'; import { E164Parser } from '@waha/core/utils/PhoneJidNormalizer'; @@ -270,7 +271,7 @@ export function WhatsAppContactInfo( } else if (isJidBroadcast(chatId)) { return new BroadcastContactInfo(session, chatId, locale); } else if (isLidUser(chatId)) { - return new LidContactInfo(session, chatId, locale); + return new LidContactInfo(session, normalizeJid(chatId), locale); } else if (isPnUser(chatId)) { return new JidContactInfo(session, chatId, locale); } else {