Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

docs(contact): describe the Baileys id mapping that block needs

Yudhi Armyndharis018bf3c3df66
diff --git a/src/modules/contact/contact.service.spec.ts b/src/modules/contact/contact.service.spec.ts
index dacbfd27f..c9073735f 100644
--- a/src/modules/contact/contact.service.spec.ts
+++ b/src/modules/contact/contact.service.spec.ts
@@ -136,8 +136,7 @@ describe('ContactService', () => {
describe('block/unblock reject ids that do not name a person', () => {
// whatsapp-web.js's Contact.block()/unblock() return false for a group id (nothing blocked,
- // answered 200 "blocked"); Baileys hands the id to updateBlockStatus whose Boom for an
- // unresolvable jid surfaces as an opaque 500. Both engines share this 400 guard.
+ // answered 200 "blocked"). Both engines share this 400 guard.
it.each([
['blockContact', (svc: ContactService) => svc.blockContact('s1', '[email protected]')],
['unblockContact', (svc: ContactService) => svc.unblockContact('s1', '[email protected]')],
diff --git a/src/modules/contact/contact.service.ts b/src/modules/contact/contact.service.ts
index 3cde9b8cd..73549a289 100644
--- a/src/modules/contact/contact.service.ts
+++ b/src/modules/contact/contact.service.ts
@@ -132,9 +132,10 @@ export class ContactService {
/**
* Guarded because whatsapp-web.js's Contact.block()/unblock() silently return false for a group id
- * (nothing blocked, reported as success), and Baileys passes the id to updateBlockStatus, whose
- * Boom for an unresolvable jid has no HttpException mapping (opaque 500). See `assertBlockable`
- * for why this guard is wider than the addressbook one.
+ * (nothing blocked, reported as success). Baileys' updateBlockStatus refuses an id it cannot map
+ * between the phone and privacy-id dialects, which the adapter reports as 400
+ * RecipientUnreachableError. See `assertBlockable` for why this guard is wider than the
+ * addressbook one.
*/
blockContact(sessionId: string, contactId: string) {
this.assertBlockable(contactId);
@@ -149,10 +150,12 @@ export class ContactService {
* the wid as-is), so refusing them made the very ids this API hands out unusable for the matching
* write and left such a contact listed as blocked with no way to unblock it.
*
- * Neither engine needs a phone here: Baileys passes the jid straight to `updateBlockStatus`, and
- * whatsapp-web.js only short-circuits (`Contact.block()` returns false without acting) for a
- * group. What must still be refused is an id that names no individual at all, which is what made
- * whatsapp-web.js answer 200 "blocked" while nothing was blocked.
+ * whatsapp-web.js needs no phone here and only short-circuits (`Contact.block()` returns false
+ * without acting) for a group. Baileys' `updateBlockStatus` maps the id first: blocking a lid
+ * needs its phone mapping, and a phone-based id (block or unblock) needs its lid mapping; an
+ * unmapped id answers 400 RecipientUnreachableError from the adapter. What must still be refused
+ * up front is an id that names no individual at all, which is what made whatsapp-web.js answer
+ * 200 "blocked" while nothing was blocked.
*/
private assertBlockable(contactId: string): void {
if (isIndividualWid(contactId) || this.isBareNumber(contactId)) return;