#8224: feat(whatsapp): extract @mentions into dedicated module
channel: whatsapp-web
stale
Cluster:
WhatsApp and Google Chat Fixes
## Summary
Adds WhatsApp @mention support for outbound messages. When the bot sends a message containing `@<phone>` patterns (e.g. `@5541999990000`), the phone numbers are extracted and passed to Baileys as proper `mentions` JIDs, making them appear as tappable mentions in WhatsApp.
## Changes
- **New:** `src/whatsapp/mentions.ts` — `extractMentions()` helper that parses `@`-prefixed phone numbers (10–15 digits) into `<number>@s.whatsapp.net` JIDs
- **New:** `src/whatsapp/mentions.test.ts` — 8 unit tests covering single/multiple mentions, empty/null input, edge cases
- **Modified:** `src/web/inbound/send-api.ts` — imports `extractMentions`, always includes `mentions` array in outbound payloads (image, video, document, text). Audio unchanged (no caption field). Baileys handles empty arrays gracefully.
## Approach
- Mentions module lives in `src/whatsapp/` alongside `normalize.ts`
- Always pass `mentions` (even if empty) instead of conditional spreading — simpler, no runtime cost
- Regex: `/@(\d{10,15})/g` matches international phone formats
## Testing
- `pnpm build` ✅
- `pnpm check` ✅ (lint + format)
- `pnpm test src/whatsapp/mentions.test.ts` ✅ (8/8)
- Manually tested on WhatsApp (DM + group) — mentions render as tappable
Successor to #2505 (closed during release freeze), rebased on latest main.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
Adds WhatsApp outbound `@<phone>` mention support by introducing `src/whatsapp/mentions.ts` (`extractMentions`) and wiring it into the WhatsApp web send API so image/video/document captions and text messages include a `mentions` JID array. Includes a focused Vitest suite covering core parsing behavior and edge cases.
<h3>Confidence Score: 4/5</h3>
- This PR looks safe to merge; changes are small, isolated, and covered by unit tests.
- Wiring is straightforward (mentions extracted from `text` and passed through to Baileys payloads) and the new helper has tests. Main remaining concerns are minor: doing work for audio messages where mentions are unused, and potential duplicate mention entries.
- src/web/inbound/send-api.ts (audio branch behavior), src/whatsapp/mentions.ts (duplicate handling)
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
**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
#11166: fix(whatsapp): detect LID @mentions in self-chat mode
by mcaxtr · 2026-02-07
83.2%
#16608: feat(whatsapp): resolve outbound @mentions to clickable WhatsApp me...
by lucasmpramos · 2026-02-14
82.3%
#10196: fix(whatsapp): sanitize raw mention IDs in outbound messages
by koala73 · 2026-02-06
80.9%
#12069: fix(whatsapp): handle native group @mentions with requireMention
by abhishek0450 · 2026-02-08
80.3%
#20003: feat(whatsapp): follow-up window for group conversations with requi...
by alexmelges · 2026-02-18
79.7%
#22106: fix(whatsapp): honor selfChatMode override for group mentions
by sportclaw · 2026-02-20
79.2%
#17256: fix: allow text regex fallback when bot JID not in mentionedJids
by DarlingtonDeveloper · 2026-02-15
78.5%
#17326: fix(whatsapp): group composing indicator, echo prevention, and pres...
by globalcaos · 2026-02-15
78.1%
#7287: feat(whatsapp): expose group admin functions
by balthazar-bot · 2026-02-02
78.1%
#23579: feat(whatsapp): add sender attribution to inbound message logs
by svan058 · 2026-02-22
77.6%