Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(engine): list a blocked wwebjs contact once
Yudhi Armyndharisd3d53118f797
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 5be1fc2e7..07d91ae09 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -80,7 +80,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- Create the built-in PostgreSQL container with the saved `DATABASE_PASSWORD`, so a custom password saved with the built-in database no longer fails the next boot.- Serialize a plugin upload with an uninstall or update of the same plugin id.- Show hours for a session active within the last day on the Sessions page, as the Dashboard does.-- List a whatsapp-web.js contact held under both its LID and its phone once, with the phone as `number`, instead of twice with the LID's digits.+- List a whatsapp-web.js contact held under both its LID and its phone once in the contacts and blocked lists, with the phone as `number`, instead of twice with the LID's digits.## [0.25.0] - 2026-10-15diff --git a/docs/06-api-specification.md b/docs/06-api-specification.mdindex 322accce3..434d9802a 100644--- a/docs/06-api-specification.md+++ b/docs/06-api-specification.md@@ -2539,7 +2539,8 @@ On Baileys the list is the saved address book: contacts with a name saved on theThe contacts this account has blocked — the read half of the block/unblock endpoints. A bare arrayof neutral contact ids, and ids only: whatsapp-web.js resolves full contact models, but Baileys'blocklist query answers bare jids, and inventing the other fields on one engine would make the two-engines claim different things about the same account.+engines claim different things about the same account. An id is listed once, even when whatsapp-web.js+holds the contact under both its LID and its phone.**Auth:** API keydiff --git a/src/engine/adapters/blocked-contacts.spec.ts b/src/engine/adapters/blocked-contacts.spec.tsindex 69e7f2cb4..12a17c906 100644--- a/src/engine/adapters/blocked-contacts.spec.ts+++ b/src/engine/adapters/blocked-contacts.spec.ts@@ -43,6 +43,19 @@ describe('WwebjsContacts.getBlockedContacts', () => {await expect(contacts.getBlockedContacts()).resolves.toEqual(['[email protected]']);});+ it('lists an id once when the blocklist holds a contact under both its LID and its phone', async () => {+ const { contacts, client } = makeContacts();+ // whatsapp-web.js answers a LID entry under the contact's phone id (a plain string), so the two+ // entries read as the same id.+ client.getBlockedContacts.mockResolvedValue([+ { id: '[email protected]' },+ { id: { _serialized: '[email protected]' } },+ { id: { _serialized: '[email protected]' } },+ ]);++ await expect(contacts.getBlockedContacts()).resolves.toEqual(['[email protected]', '[email protected]']);+ });+it('resolves [] for an empty blocklist', async () => {const { contacts, client } = makeContacts();client.getBlockedContacts.mockResolvedValue([]);diff --git a/src/engine/adapters/wwebjs-contacts.ts b/src/engine/adapters/wwebjs-contacts.tsindex 7d631b4ff..e48717553 100644--- a/src/engine/adapters/wwebjs-contacts.ts+++ b/src/engine/adapters/wwebjs-contacts.ts@@ -310,12 +310,14 @@ export class WwebjsContacts {/*** The read half of block/unblockContact. Ids only — the neutral common subset with Baileys,* whose blocklist query answers bare jids. An entry whose wid is unreadable (#747 rename- * hazard) is dropped rather than reported as the literal "undefined".+ * hazard) is dropped rather than reported as the literal "undefined". A contact blocked under both+ * its LID and its phone is two entries that read as one id, which is listed once.*/async getBlockedContacts(): Promise<string[]> {this.host.ensureReady();const contacts = await withPage(this.host, 'getBlockedContacts', () => this.client().getBlockedContacts());- return contacts.map(c => readWid(c.id as unknown as SerializedWid)).filter((id): id is string => Boolean(id));+ const ids = contacts.map(c => readWid(c.id as unknown as SerializedWid)).filter((id): id is string => Boolean(id));+ return [...new Set(ids)];}async unblockContact(contactId: string): Promise<void> {