#20190: WhatsApp: normalize BR 9th-digit outbound targets
channel: whatsapp-web
size: S
Cluster:
WhatsApp Enhancements and Fixes
## Summary
- add WhatsApp-specific Brazilian mobile normalization for outbound targets
- when target matches `+55DD9XXXXXXXX` and DDD is outside `11-28`, strip the carrier-added `9` before send
- keep DDD `11-28` unchanged
- apply this normalization for both plain numbers and WhatsApp user JID inputs
Closes #20187
## Validation
- `corepack pnpm exec vitest run src/whatsapp/normalize.test.ts`
- `corepack pnpm exec vitest run src/whatsapp/resolve-outbound-target.test.ts`
- `corepack pnpm dlx oxfmt@0.33.0 --check src/whatsapp/normalize.ts src/whatsapp/normalize.test.ts`
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Adds WhatsApp-specific Brazilian mobile number normalization to strip the carrier-added 9th digit for outbound targets when the DDD (area code) falls outside the 11-28 range. Numbers with DDDs 11-28 (São Paulo, Rio de Janeiro, Espírito Santo regions) are kept unchanged, matching WhatsApp's internal number storage behavior.
- New `normalizeBrazilianMobileForWhatsApp` function in `src/whatsapp/normalize.ts` that post-processes E.164 numbers
- Applied consistently in both code paths of `normalizeWhatsAppTarget` (plain numbers and user JID inputs)
- Tests cover DDD inside range (11), DDD outside range (47), and all three input formats (`+55...`, `whatsapp:+55...`, `...@s.whatsapp.net`)
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge - a well-scoped, targeted normalization change with matching tests.
- Score of 4 reflects a clean, focused change with correct logic, consistent application across both code paths, and good test coverage. The DDD boundary (11-28) aligns with known WhatsApp behavior for Brazilian mobile numbers. No logic, syntax, or security issues found.
- No files require special attention.
<sub>Last reviewed commit: a1957da</sub>
<!-- 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))
<!-- /greptile_comment -->
Most Similar PRs
#19590: fix(whatsapp): normalize Brazilian mobile numbers in JID conversion
by qualiobra · 2026-02-18
90.2%
#4181: fix(whatsapp): resolve Brazilian mobile JID variants (8/9 digit)
by lucasmpramos · 2026-01-29
77.4%
#7395: fix(whatsapp): strip markdown bold/italic from URLs before sending
by lailoo · 2026-02-02
76.0%
#22335: fix: harden normalizeE164 against empty/invalid inputs returning ba...
by CZH-THU · 2026-02-21
74.9%
#13424: feat(whatsapp): add Newsletter/Channel JID support
by agentz-manfred · 2026-02-10
74.7%
#10196: fix(whatsapp): sanitize raw mention IDs in outbound messages
by koala73 · 2026-02-06
72.9%
#8052: fix(whatsapp): strip leading whitespace from outbound messages
by FelixFoster · 2026-02-03
72.6%
#13431: feat(whatsapp): add built-in Markdown to WhatsApp format transform
by asklee-klawd · 2026-02-10
72.5%
#15786: fix: strip device suffix from selfJid in WhatsApp mention matching
by kenken64 · 2026-02-13
72.4%
#5665: fix: match group JIDs in groupAllowFrom allowlist
by koala73 · 2026-01-31
71.5%