← Back to PRs

#8224: feat(whatsapp): extract @mentions into dedicated module

by zurizuriaria open 2026-02-03 19:20 View on GitHub →
channel: whatsapp-web stale
## 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