Skip to content

fix(whatsapp): allow @lid contacts to bypass onWhatsApp validation#2544

Open
99ecarvalho wants to merge 1 commit into
evolution-foundation:mainfrom
99ecarvalho:fix/lid-validation-bypass
Open

fix(whatsapp): allow @lid contacts to bypass onWhatsApp validation#2544
99ecarvalho wants to merge 1 commit into
evolution-foundation:mainfrom
99ecarvalho:fix/lid-validation-bypass

Conversation

@99ecarvalho
Copy link
Copy Markdown

@99ecarvalho 99ecarvalho commented May 17, 2026

Problem

After WhatsApp's LID (Linked Identity) migration, contacts that resolve to @lid JIDs are rejected by sendMessageWithTyping and sendPresence because onWhatsApp returns exists: false for LID-based identifiers. This causes a BadRequestException for any DM to an @lid contact.

The existing validation already whitelists @broadcast JIDs 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 @broadcast bypass 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 @lid contacts now succeed without throwing BadRequestException.

Summary by Sourcery

Bug Fixes:

  • Prevent BadRequestException errors when sending messages or presence updates to @lid WhatsApp contacts by exempting them from onWhatsApp existence checks.

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.
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 17, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Allows 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 sendMessageWithTyping

sequenceDiagram
  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
Loading

File-Level Changes

Change Details Files
Relax WhatsApp contact existence validation to treat @lid JIDs as valid targets for messages and presence updates.
  • Extend the sendMessageWithTyping onWhatsApp validation to skip throwing BadRequestException when the resolved JID includes '@lid'.
  • Extend the sendPresence onWhatsApp validation to skip throwing BadRequestException when the resolved JID includes '@lid'.
  • Keep existing checks for group JIDs and @broadcast JIDs unchanged while adding the new @lid condition.
src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Possibly linked issues

  • #unknown: The PR fixes sending failures to @lid JIDs (BadRequestException), which is a key symptom tracked in the @lid meta-issue.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants