fix(baileys): resolve @lid senders to a phone number (#362)#372
Merged
Conversation
… key (#362) senderPhone and GET /contacts/:id/phone always returned null for @lid contacts on Baileys: the resolver only used mappings from contacts.* / messaging-history.set (which don't fire for a fresh inbound @lid sender), and baileys@6.7.23 has no getPNForLID lookup. Learn the lid->pn pair Baileys attaches to the inbound message key (senderPn / participantPn) before canonicalizing, so the sender resolves to its number and later contact lookups succeed. Best-effort by design (only when WhatsApp delivers it).
f0b38f7 to
3bce16f
Compare
Merged
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #362.
Problem
On the Baileys engine,
senderPhoneandGET /sessions/:id/contacts/:contactId/phonealways returnednullfor privacy-id (@lid) contacts — the#263lid→phone feature was effectively non-functional there. Root cause (verified againstbaileys@6.7.23):BaileysSessionStore.resolvePhone()only consulted in-memory mappings populated fromcontacts.upsert/messaging-history.setlidPnMappings— neither fires for a fresh inbound@lidsender.getContactLidAndPhone) has no equivalent in baileys@6.7.23 — there is nosignalRepository.lidMapping.getPNForLID(confirmed absent in the installed lib), so a runtime lookup wasn't an option.Fix
Baileys attaches the sender's phone JID right on the inbound message key —
senderPn/participantPnalongsidesenderLid/participantLid(present in the 6.7.23WAMessageKeytype). The adapter now harvests that pair into the session store'slid → pnmap at the start ofprocessInboundMessage, before any id canonicalization. As a result:@lidsender of the incoming message resolves to<phone>@c.us, andGET /contacts/:id/phonefor that contact returns the number.Still best-effort by design (matching the issue): a number is only revealed once WhatsApp delivers the mapping — i.e. after an inbound message from that contact. Truly hidden-number contacts remain
null.Tests (TDD, watched fail first)
baileys-session-store.spec.ts: 4 cases forrecordKeyLidMappings(sender pair, participant pair, canonicalization after learning, ignores empty/half pairs).baileys.adapter.spec.ts: 1 end-to-end inbound case — an@lidmessage whose key carriessenderPnresolvesfromto<phone>@c.uswith no prior history-sync mapping.npx jest→ 933/933 pass (86 suites);npm run build+eslintclean.Notes
WaIdroadmap in [Feature]: typedWaIdidentity value object + alid <-> phoneresolution table #349.