Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(identity): send group participants in their neutral form

Yudhi Armyndharis80e7719a5aca
diff --git a/src/engine/identity/wa-id.spec.ts b/src/engine/identity/wa-id.spec.ts
index b44cbfebe..fef196749 100644
--- a/src/engine/identity/wa-id.spec.ts
+++ b/src/engine/identity/wa-id.spec.ts
@@ -138,10 +138,22 @@ describe('wa-id', () => {
expect(toParticipantWid('628123456789')).toBe('[email protected]');
});
- it('leaves an already-qualified id untouched', () => {
+ it('leaves an already-neutral id untouched', () => {
expect(toParticipantWid('[email protected]')).toBe('[email protected]');
expect(toParticipantWid('12345678901234567890@lid')).toBe('12345678901234567890@lid');
- expect(toParticipantWid('[email protected]')).toBe('[email protected]');
+ });
+
+ it.each([
+ [' 628123456789:[email protected] ', '[email protected]'],
+ ['628123456789@hosted', '[email protected]'],
+ ['12345678901234567890:5@LID', '12345678901234567890@lid'],
+ ['[email protected]', '12345678901234567890@lid'],
+ ])('reduces the accepted variant %s to the neutral id %s, keeping a lid a lid', (value, expected) => {
+ // isIndividualWid accepts every one of these, so forwarding the raw string would hand the
+ // engine an id the group's participant list is not keyed by.
+ expect(isIndividualWid(value)).toBe(true);
+ expect(toParticipantWid(value)).toBe(expected);
});
it.each([['abc@weird'], ['abc'], ['NOT A USER'], ['']])(
diff --git a/src/engine/identity/wa-id.ts b/src/engine/identity/wa-id.ts
index 548d78b2f..9ec34868d 100644
--- a/src/engine/identity/wa-id.ts
+++ b/src/engine/identity/wa-id.ts
@@ -114,7 +114,11 @@ export function isAddressableParticipant(value: string): boolean {
}
/**
- * Qualify a bare number to the neutral `@c.us` dialect. Anything else passes through verbatim.
+ * Qualify a bare number to the neutral `@c.us` dialect, and reduce an individual id to its neutral
+ * form (`<phone>@c.us` or `<lid>@lid`: lowercased, `:device` suffix dropped, the `s.whatsapp.net`
+ * and hosted dialects folded). {@link isIndividualWid} accepts every one of those variants, so the id
+ * handed to the engine has to be the one a group's participant list is keyed by, or a real member is
+ * reported as not a member. A lid is not resolved: it stays a lid. Anything else passes through verbatim.
*
* Deliberately keyed on the bare-number shape rather than on the absence of `@`: the old rule
* (`p.includes('@') ? p : p + '@c.us'`) minted an id out of ANY un-domained string, so `abc` became
@@ -122,7 +126,8 @@ export function isAddressableParticipant(value: string): boolean {
*/
export function toParticipantWid(value: string): string {
const trimmed = value.trim();
- return NUMERIC_ID.test(trimmed) ? `${trimmed}@c.us` : trimmed;
+ if (NUMERIC_ID.test(trimmed)) return `${trimmed}@c.us`;
+ return isIndividualWid(trimmed) ? toNeutralJid(trimmed) : trimmed;
}
/**