fix(whatsapp): allow @lid contacts to bypass onWhatsApp validation#2544
Open
99ecarvalho wants to merge 1 commit into
Open
fix(whatsapp): allow @lid contacts to bypass onWhatsApp validation#254499ecarvalho wants to merge 1 commit into
99ecarvalho wants to merge 1 commit into
Conversation
After WhatsApp's LID (Linked Identity) migration, DMs to contacts that resolve to @lid JIDs fail with a BadRequestException because onWhatsApp returns exists:false for LID-based identifiers. Add @lid to the whitelist alongside @broadcast in both sendMessageWithTyping and sendPresence so these contacts are not rejected by the existence check.
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAllows WhatsApp LID (@lid) contacts to bypass the onWhatsApp existence check in message sending and presence update flows, mirroring the existing @broadcast bypass so DMs to @lid contacts no longer throw BadRequestException. Sequence diagram for WhatsApp LID bypass in sendMessageWithTypingsequenceDiagram
actor User
participant BaileysStartupService
participant WhatsappProvider as whatsappNumber
User->>BaileysStartupService: sendMessageWithTyping(number, message)
BaileysStartupService->>WhatsappProvider: whatsappNumber(numbers)
WhatsappProvider-->>BaileysStartupService: isWA
alt !isWA.exists && !isJidGroup(isWA.jid) && !isWA.jid.includes('@broadcast') && !isWA.jid.includes('@lid')
BaileysStartupService->>User: throw BadRequestException(isWA)
else isWA.jid includes '@lid' or '@broadcast' or is group
BaileysStartupService->>User: proceed with message send
end
File-Level Changes
Possibly linked issuesTips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The checks assume
isWAis always defined; consider guarding against anull/undefinedresult fromwhatsappNumberbefore accessingisWA.existsorisWA.jidto avoid potential runtime errors. - The
!isWA.exists && !isJidGroup(isWA.jid) && !isWA.jid.includes('@broadcast') && !isWA.jid.includes('@lid')validation logic is duplicated in both methods; consider extracting it into a shared helper to keep the logic consistent and easier to maintain. - Instead of using
isWA.jid.includes('@lid'), consider a more explicit JID type check (e.g., parsing the JID or checking its suffix) to avoid accidental matches if@lidappears elsewhere in the string.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The checks assume `isWA` is always defined; consider guarding against a `null`/`undefined` result from `whatsappNumber` before accessing `isWA.exists` or `isWA.jid` to avoid potential runtime errors.
- The `!isWA.exists && !isJidGroup(isWA.jid) && !isWA.jid.includes('@broadcast') && !isWA.jid.includes('@lid')` validation logic is duplicated in both methods; consider extracting it into a shared helper to keep the logic consistent and easier to maintain.
- Instead of using `isWA.jid.includes('@lid')`, consider a more explicit JID type check (e.g., parsing the JID or checking its suffix) to avoid accidental matches if `@lid` appears elsewhere in the string.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
Problem
After WhatsApp's LID (Linked Identity) migration, contacts that resolve to
@lidJIDs are rejected bysendMessageWithTypingandsendPresencebecauseonWhatsAppreturnsexists: falsefor LID-based identifiers. This causes aBadRequestExceptionfor any DM to an@lidcontact.The existing validation already whitelists
@broadcastJIDs but does not account for@lid.Fix
Add
&& !isWA.jid.includes('@lid')to the validation checks in both:sendMessageWithTyping(line 2099)sendPresence(line 2347)This mirrors the existing
@broadcastbypass logic.Related
This fix works in conjunction with a corresponding Baileys fix (evolution-foundation/Baileys#8) that preserves per-participant JID domains in group message encryption.
Testing
Tested with Evolution API v2.2.3 and WhatsApp accounts that have undergone the LID migration. DMs to
@lidcontacts now succeed without throwing BadRequestException.Summary by Sourcery
Bug Fixes: