From b825f141f327be47157a17e7b05d84ce7a7e5a04 Mon Sep 17 00:00:00 2001 From: Marcus Neves Date: Wed, 26 Nov 2025 12:43:48 -0300 Subject: [PATCH] fix: add @lid format support and allowFrom wildcard handling - Add support for WhatsApp Linked ID (@lid) format in jidToE164() - Use existing lid-mapping-*_reverse.json files for LID resolution - Fix allowFrom wildcard '*' to actually allow all senders - Maintain backward compatibility with @s.whatsapp.net format Fixes issues where: - Messages from newer WhatsApp versions are silently dropped - allowFrom: ['*'] configuration doesn't work as documented --- src/auto-reply/reply.ts | 3 ++- src/utils.ts | 23 ++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/auto-reply/reply.ts b/src/auto-reply/reply.ts index b32fa0415..5728ff061 100644 --- a/src/auto-reply/reply.ts +++ b/src/auto-reply/reply.ts @@ -148,7 +148,8 @@ export async function getReplyFromConfig( const allowFrom = cfg.inbound?.allowFrom; if (Array.isArray(allowFrom) && allowFrom.length > 0) { const from = (ctx.From ?? "").replace(/^whatsapp:/, ""); - if (!allowFrom.includes(from)) { + // Support "*" as wildcard to allow all senders + if (!allowFrom.includes("*") && !allowFrom.includes(from)) { logVerbose( `Skipping auto-reply: sender ${from || ""} not in allowFrom list`, ); diff --git a/src/utils.ts b/src/utils.ts index eba16782b..eab2a9aa6 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -38,9 +38,26 @@ export function toWhatsappJid(number: string): string { export function jidToE164(jid: string): string | null { // Convert a WhatsApp JID (with optional device suffix, e.g. 1234:1@s.whatsapp.net) back to +1234. const match = jid.match(/^(\d+)(?::\d+)?@s\.whatsapp\.net$/); - if (!match) return null; - const digits = match[1]; - return `+${digits}`; + if (match) { + const digits = match[1]; + return `+${digits}`; + } + + // Support @lid format (WhatsApp Linked ID) - look up reverse mapping + const lidMatch = jid.match(/^(\d+)(?::\d+)?@lid$/); + if (lidMatch) { + const lid = lidMatch[1]; + try { + const mappingPath = `${CONFIG_DIR}/credentials/lid-mapping-${lid}_reverse.json`; + const data = fs.readFileSync(mappingPath, "utf8"); + const phone = JSON.parse(data); + if (phone) return `+${phone}`; + } catch { + // Mapping not found, fall through + } + } + + return null; } export function sleep(ms: number) {