Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(engine): look a contact up within one identity kind
Yudhi Armyndharisacc9a84466a4
diff --git a/src/engine/adapters/baileys-contact-lookup-kind.spec.ts b/src/engine/adapters/baileys-contact-lookup-kind.spec.tsnew file mode 100644index 000000000..fb93f2094--- /dev/null+++ b/src/engine/adapters/baileys-contact-lookup-kind.spec.ts@@ -0,0 +1,24 @@+import { BaileysSessionStore } from './baileys-session-store';++describe('findContact across identity kinds', () => {+ it('does not answer a phone lookup with a lid contact whose digits are the same', () => {+ const store = new BaileysSessionStore();+ store.upsertContacts([+ { id: '628111@lid', name: 'Other' },+ { id: '777@lid', phoneNumber: '[email protected]', name: 'Right' },+ ]);++ expect(store.findContact('[email protected]')?.name).toBe('Right');+ });++ it('does not answer a lid lookup with a phone contact whose digits are the same', () => {+ const store = new BaileysSessionStore();+ store.upsertContacts([+ { id: '[email protected]', name: 'Other' },+ { id: '[email protected]', name: 'Other twin' },+ { id: '[email protected]', lid: '777@lid', name: 'Right' },+ ]);++ expect(store.findContact('777@lid')?.name).toBe('Right');+ });+});diff --git a/src/engine/adapters/baileys-session-store.ts b/src/engine/adapters/baileys-session-store.tsindex 8cbd3fc27..70d1f67fe 100644--- a/src/engine/adapters/baileys-session-store.ts+++ b/src/engine/adapters/baileys-session-store.ts@@ -614,7 +614,8 @@ export class BaileysSessionStore {? userPart(c.id): '';const lid = c.lid ? userPart(c.lid) : c.id.endsWith('@lid') ? userPart(c.id) : '';- if (phone !== want && lid !== want) continue;+ // Digits are only comparable within one kind: a lid and a phone number can read the same.+ if ((parsed.kind === 'user' ? phone : lid) !== want) continue;if (c.name) return this.toNeutralContact(c);unnamed ??= c;}