Files
waha/src/apps/chatwoot/client/ids.ts
T
2025-07-13 18:32:53 +07:00

35 lines
1.0 KiB
TypeScript

import { isLidUser } from '@adiwajshing/baileys/lib/WABinary/jid-utils';
import { AttributeKey } from '@waha/apps/chatwoot/const';
import { WhatsAppMessage } from '@waha/apps/chatwoot/storage';
import { buildMessageId } from '@waha/core/engines/noweb/session.noweb.core';
export function GetJID(contact: any): string | null {
return contact?.custom_attributes?.[AttributeKey.WA_JID];
}
export function GetLID(contact: any): string | null {
return contact?.custom_attributes?.[AttributeKey.WA_LID];
}
export function GetChatID(contact: any): string | null {
return contact?.custom_attributes?.[AttributeKey.WA_CHAT_ID];
}
export function SerializeWhatsAppKey(message: WhatsAppMessage): string {
const key = {
id: message.message_id,
remoteJid: message.chat_id,
fromMe: Boolean(message.from_me),
participant: message.participant,
};
return buildMessageId(key);
}
export function ContactAttr(chatId: string): AttributeKey {
if (isLidUser(chatId)) {
return AttributeKey.WA_LID;
} else {
return AttributeKey.WA_JID;
}
}