fix(whatsapp): normalize device-qualified contact ids
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
import crypto from 'node:crypto'
|
||||
|
||||
export function canonicalWhatsAppJid(jid, identity = {}) {
|
||||
const raw = String(jid || '').trim().toLowerCase()
|
||||
const normalizeDevice = (value) => String(value || '')
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.replace(/:\d+(?=@s\.whatsapp\.net$)/, '')
|
||||
const raw = normalizeDevice(jid)
|
||||
if (!raw || raw.endsWith('@g.us') || raw.endsWith('@newsletter')) return raw
|
||||
const canonical = String(identity?.canonicalJid || '').trim().toLowerCase()
|
||||
const canonical = normalizeDevice(identity?.canonicalJid)
|
||||
if (canonical.endsWith('@s.whatsapp.net')) return canonical
|
||||
const phone = String(identity?.phone || '').replace(/\D/g, '')
|
||||
const phone = String(identity?.phone || '').split(':')[0].replace(/\D/g, '')
|
||||
return phone ? `${phone}@s.whatsapp.net` : raw
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user