#11166: fix(whatsapp): detect LID @mentions in self-chat mode
channel: whatsapp-web
size: S
trusted-contributor
experienced-contributor
Cluster:
WhatsApp and Google Chat Fixes
Fixes #8487
#### Summary
WhatsApp group @mentions using LID format (e.g. `181891881787642@lid`) are silently ignored when `isSelfChatMode` is true (i.e. the bot's own number is in `allowFrom`). The `else if (hasMentions && isSelfChat)` branch in `isBotMentionedFromTargets()` was completely empty, causing all JID mentions to fall through to text-based matching — which fails because the message body contains LID strings, not phone numbers.
lobster-biscuit
#### Repro Steps
1. Configure WhatsApp with `allowFrom` containing the bot's own phone number (triggers `isSelfChatMode`)
2. Have another group member @mention the bot
3. WhatsApp sends LID-format JID in `mentionedJids` (e.g. `181891881787642@lid`)
4. `normalizedMentions` correctly resolves the LID to the bot's E164
5. **Bug**: Empty `else if` branch discards this information; `wasMentioned` is `false`
#### Root Cause
The `else if (hasMentions && isSelfChat)` branch at `src/web/auto-reply/mentions.ts:59-61` was intentionally empty to suppress WhatsApp's auto-included owner JID mentions. However, this also suppressed legitimate @mentions from external group members — including LID-format mentions that `normalizedMentions` correctly resolves to E164.
#### Fix
Use `msg.senderE164` to distinguish between the owner's own messages (where WhatsApp auto-includes their JID) and external users' messages (where the @mention is intentional):
- **Sender IS owner** → suppress JID mentions (preserves original intent)
- **Sender is NOT owner** → check `normalizedMentions` against `selfE164` (fixes the bug)
#### Behavior Changes
- External users @mentioning the bot in a group now correctly triggers the agent session when `isSelfChatMode` is true
- Owner's own messages with auto-included JID mentions remain suppressed
- Text-based mention patterns (e.g. typing "openclaw") continue to work in all cases
#### Codebase and GitHub Search
- Searched `isBotMentionedFromTargets`, `isSelfChatMode`, `wasMentioned LID`, `mentionedJids` — no competing PRs
- Reviewed PR #5607 (closed, different feature: reply-based implicit mentions)
- Verified `normalizeE164` import was already available in `mentions.ts`
#### Tests
- [x] 3 new unit tests in `mentions.test.ts` (LID from external sender, JID from owner, LID of non-bot user)
- [x] Updated integration test to verify owner's messages are still suppressed while external mentions now trigger
- [x] All 3 new tests fail before fix, pass after (TDD)
- [x] Full suite: 848 test files, 5386 tests pass, 0 failures
- [x] `pnpm build` passes
- [x] `pnpm check` passes (pre-existing lint error in `memory-lancedb` unrelated to this change)
**Sign-Off**
- Submitter effort: autonomous
- Agent notes: The fix uses `msg.senderE164` (already available on `WebInboundMessage`) to disambiguate the owner's auto-included JID from intentional external mentions. Minimal, targeted fix — no new dependencies, no architectural changes.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This change fixes WhatsApp self-chat mode mention detection when group @mentions arrive as LID-format JIDs (e.g. `...@lid`). In `src/web/auto-reply/mentions.ts`, the previously-empty `hasMentions && isSelfChat` branch now distinguishes between messages sent by the owner (where WhatsApp auto-includes the owner’s JID in `mentionedJids` and should remain suppressed) and messages sent by other users (where `normalizedMentions` should be honored to detect bot mentions).
Tests were updated accordingly:
- `src/web/auto-reply/mentions.test.ts` adds unit coverage for LID mentions from external senders, suppression for owner-sent messages, and non-bot LID mentions.
- `src/web/auto-reply.web-auto-reply.supports-always-group-activation-silent-token-preserves.test.ts` extends the existing integration test to ensure owner messages remain suppressed while external JID mentions now trigger in self-chat mode.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk.
- The change is narrowly scoped to self-chat mention handling and is covered by new unit and integration tests that exercise the previously-broken scenario (external LID/JID mentions) and the intended suppression behavior for owner-sent messages. The logic relies on existing fields (`senderE164`, `selfE164`) and existing normalization utilities, and no other code paths are affected.
- No files require special attention
<!-- greptile_other_comments_section -->
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#12069: fix(whatsapp): handle native group @mentions with requireMention
by abhishek0450 · 2026-02-08
90.1%
#23046: fix(whatsapp): detect LID JID in implicit reply-to-bot mention check
by hydro13 · 2026-02-21
88.4%
#23059: fix(whatsapp): resolve LID JIDs for reply-to-bot implicit mention d...
by azisseno · 2026-02-21
88.0%
#22106: fix(whatsapp): honor selfChatMode override for group mentions
by sportclaw · 2026-02-20
86.4%
#2772: fix: search WhatsApp account subdirs for LID mapping files
by impozzible · 2026-01-27
86.3%
#16655: fix(whatsapp): resolve reply-to sender E.164 for LID JIDs (have bot...
by mascarenhas · 2026-02-15
85.8%
#17256: fix: allow text regex fallback when bot JID not in mentionedJids
by DarlingtonDeveloper · 2026-02-15
85.6%
#8224: feat(whatsapp): extract @mentions into dedicated module
by zurizuriaria · 2026-02-03
83.2%
#15786: fix: strip device suffix from selfJid in WhatsApp mention matching
by kenken64 · 2026-02-13
81.3%
#6567: fix: include paired users in WhatsApp group sender allowlist
by giannisanni · 2026-02-01
80.5%