Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(engine): keep a chat id under an unknown domain literal
Yudhi Armyndharis3cc1df87ce98
diff --git a/src/engine/identity/jid-candidates.spec.ts b/src/engine/identity/jid-candidates.spec.tsindex 7620972d8..ef05c8449 100644--- a/src/engine/identity/jid-candidates.spec.ts+++ b/src/engine/identity/jid-candidates.spec.ts@@ -33,6 +33,12 @@ describe('resolveJidCandidates', () => {expect(await resolveJidCandidates('123@newsletter', directory)).toEqual(['123@newsletter']);});+ // An unrecognised domain (a Baileys `@bot` chat, say) is not a phone: minting `@c.us` from its digits+ // would let the chat-scope guard admit an id the list filter refuses, and widen the chat filter.+ it('keeps an id with an unrecognised domain literal', async () => {+ expect(await resolveJidCandidates(`${PHONE}@bot`, directory)).toEqual([`${PHONE}@bot`]);+ });+it('qualifies a bare number', async () => {const out = await resolveJidCandidates(PHONE, directory);expect(out).toContain(`${PHONE}@c.us`);diff --git a/src/engine/identity/jid-candidates.ts b/src/engine/identity/jid-candidates.tsindex 5f61b5b05..c3b63a6fd 100644--- a/src/engine/identity/jid-candidates.ts+++ b/src/engine/identity/jid-candidates.ts@@ -10,7 +10,8 @@ import { parseWaId } from './wa-id';* deliberately does NOT mint `<lid-digits>@c.us`: a lid's digits are not a phone number, and* treating them as one would let `555000111@lid` match a `[email protected]` chat.* - a group / status / newsletter / broadcast id has exactly one stored form, so it yields only the- * literal (expanding a group's digits into the user dialects could match an unrelated person).+ * literal (expanding a group's digits into the user dialects could match an unrelated person), and+ * so does an id under an unrecognised domain; only a bare number is qualified as a phone.** The last rule is why a non-user kind returns just the input: it fails closed on the literal id.*/@@ -26,7 +27,8 @@ export async function resolveJidCandidates(value: string, directory?: ContactDir// Group ids are stored in the neutral `<id>@g.us` form, so normalize rather than echo the input:// an upper-case domain must not make the guard's answer disagree with the list filter's.if (parsed.kind === 'group') return [`${parsed.userPart}@g.us`];- if (parsed.kind !== 'user' && parsed.kind !== 'lid' && parsed.kind !== 'unknown') {+ // Only a bare number is qualified into the user dialects; an unrecognised domain is not a phone.+ if (parsed.kind !== 'user' && parsed.kind !== 'lid' && (parsed.kind !== 'unknown' || value.includes('@'))) {return [value];}if (parsed.kind === 'lid') {