#23046: fix(whatsapp): detect LID JID in implicit reply-to-bot mention check
channel: whatsapp-web
size: S
Cluster:
WhatsApp and Google Chat Fixes
Fixes #23029.
When someone swipe-replies to a bot message in a WhatsApp group, the reply's `participant` field sometimes comes back as `XXXX@lid` instead of `XXXX@s.whatsapp.net`. This is WhatsApp's LID (Linked Identity Device) format, and it's becoming more common as WhatsApp migrates to it.
The `implicitMention` check in `applyGroupGating` only compares against `selfJid` (regular JID) and `selfE164` (phone number). When the reply sender shows up as a LID, both comparisons fail silently and the reply is dropped as "no mention detected."
The bot's own LID is available at `sock.user?.lid`, but it was never extracted or threaded through to the gating check.
## What changed
Three small changes:
1. `types.ts` — added `selfLid?: string | null` to `WebInboundMessage`
2. `monitor.ts` — extracted `selfLid = sock.user?.lid ?? null` and passed it into the inbound message object
3. `group-gating.ts` — added a third condition to `implicitMention`: `(selfLid && replySenderJid && selfLid === replySenderJid)`
The device-suffix stripping (`.replace(/:\d+/, "")`) already handles `"98765432:1@lid"` → `"98765432@lid"` correctly, so no extra logic needed there.
## Relationship to #16655
PR #16655 resolves LID JIDs to E.164 via `lidLookup` when a mapping file exists. This handles the fallback case where that mapping is unavailable. Both fixes work together.
## Tests
- New: reply with matching LID triggers implicit mention → `shouldProcess: true`
- New: reply with non-matching LID does not trigger → `shouldProcess: false`
- Existing 15 group gating tests unchanged
Closes #23029
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR fixes a bug where swipe-replies to bot messages in WhatsApp groups were silently dropped when the reply's `participant` field used WhatsApp's LID (Linked Identity Device) format (`XXXX@lid`) instead of the standard JID format (`XXXX@s.whatsapp.net`).
- Adds `selfLid` (from `sock.user?.lid`) to the `WebInboundMessage` type and threads it through from the inbound monitor to the group gating logic
- Extends the `implicitMention` check in `applyGroupGating` with a third condition comparing the bot's own LID against the reply sender's JID, so LID-format replies are correctly recognized as replies to the bot
- Complements PR #16655's `lidLookup` approach by handling the fallback case where no LID-to-E164 mapping is available
- Adds two focused tests covering the matching and non-matching LID scenarios
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge — it adds a narrowly scoped fallback check with no impact on existing behavior.
- The change is minimal and well-contained: one new optional field on a type, one new line extracting a value from an existing API, and one additional OR condition in a Boolean expression. The existing 15 group gating tests are unaffected, and two new tests specifically cover the LID matching logic. The device-suffix stripping regex is consistent with existing patterns. No security, performance, or correctness concerns.
- No files require special attention.
<sub>Last reviewed commit: 4615437</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#23059: fix(whatsapp): resolve LID JIDs for reply-to-bot implicit mention d...
by azisseno · 2026-02-21
93.2%
#16655: fix(whatsapp): resolve reply-to sender E.164 for LID JIDs (have bot...
by mascarenhas · 2026-02-15
88.9%
#11166: fix(whatsapp): detect LID @mentions in self-chat mode
by mcaxtr · 2026-02-07
88.4%
#23251: fix(whatsapp): include LID in implicit mention detection for group ...
by SidQin-cyber · 2026-02-22
87.9%
#2772: fix: search WhatsApp account subdirs for LID mapping files
by impozzible · 2026-01-27
86.7%
#12069: fix(whatsapp): handle native group @mentions with requireMention
by abhishek0450 · 2026-02-08
83.6%
#15786: fix: strip device suffix from selfJid in WhatsApp mention matching
by kenken64 · 2026-02-13
82.9%
#22106: fix(whatsapp): honor selfChatMode override for group mentions
by sportclaw · 2026-02-20
82.7%
#17256: fix: allow text regex fallback when bot JID not in mentionedJids
by DarlingtonDeveloper · 2026-02-15
81.7%
#16608: feat(whatsapp): resolve outbound @mentions to clickable WhatsApp me...
by lucasmpramos · 2026-02-14
80.4%