fix(whatsapp): unify contact identity and reduce realtime latency

This commit is contained in:
wmq
2026-08-03 00:54:59 +08:00
parent bb696c7de8
commit 7e739ad7b8
11 changed files with 280 additions and 75 deletions
+10 -1
View File
@@ -1,7 +1,16 @@
import crypto from 'node:crypto'
export function canonicalWhatsAppJid(jid, identity = {}) {
const raw = String(jid || '').trim().toLowerCase()
if (!raw || raw.endsWith('@g.us') || raw.endsWith('@newsletter')) return raw
const canonical = String(identity?.canonicalJid || '').trim().toLowerCase()
if (canonical.endsWith('@s.whatsapp.net')) return canonical
const phone = String(identity?.phone || '').replace(/\D/g, '')
return phone ? `${phone}@s.whatsapp.net` : raw
}
export function whatsappCustomerStableId(jid) {
const normalized = String(jid || '').trim().toLowerCase()
const normalized = canonicalWhatsAppJid(jid)
const hash = crypto.createHash('sha256').update(normalized).digest('hex').slice(0, 24)
return `wa-customer-${hash}`
}