← Back to PRs

#19590: fix(whatsapp): normalize Brazilian mobile numbers in JID conversion

by qualiobra open 2026-02-18 00:34 View on GitHub →
size: XS
## Summary Brazilian mobile numbers carry an extra '9' after the 2-digit area code (DDD) that WhatsApp does not use in its JID format. This PR strips it during JID conversion. ## Problem When sending outbound messages to Brazilian numbers entered with the full national format (e.g. `+55 69 9 9602-1005` or `+5569996021005`), the resulting JID `5569996021005@s.whatsapp.net` is invalid. WhatsApp expects 12-digit Brazilian JIDs (`556996021005@s.whatsapp.net`). ## Solution Add `normalizeBrazilianMobile()` helper in `toWhatsappJid()`: - Detects 13-digit numbers starting with `55` where the 5th digit is `9` - Strips the extra `9` to produce the 12-digit WhatsApp format - Landlines (no leading 9 after DDD) and non-Brazilian numbers pass through unchanged ## Tests Comprehensive test cases covering: - Brazilian mobile normalization (multiple DDDs) - `whatsapp:` prefix handling - Non-Brazilian numbers (US, Argentine) unchanged - Brazilian landlines unchanged - Already-correct 12-digit Brazilian numbers - Raw digits without `+` - Numbers with formatting characters <!-- greptile_comment --> <h3>Greptile Summary</h3> This PR adds normalization for Brazilian mobile numbers in WhatsApp JID conversion. Brazilian mobile numbers include an extra '9' digit after the 2-digit area code that WhatsApp doesn't use in its JID format (13 digits → 12 digits). **Key changes:** - Added `normalizeBrazilianMobile()` helper function in `src/utils.ts:140-148` that detects 13-digit numbers starting with `55` and strips the extra '9' at position 4 - Integrated into `toWhatsappJid()` to normalize before constructing the JID - Added comprehensive test coverage for Brazilian mobiles, landlines, non-Brazilian numbers, and edge cases - Landlines and already-correct 12-digit numbers pass through unchanged <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - The implementation is straightforward, well-tested, and focused. The logic correctly identifies Brazilian mobile numbers (13 digits starting with 55 where position 4 is '9') and strips the extra digit. All edge cases are covered: non-Brazilian numbers, landlines, already-correct numbers, and various input formats. The function is pure with no side effects, and the change is isolated to the WhatsApp JID conversion path. - No files require special attention <sub>Last reviewed commit: 8aa1845</sub> <!-- greptile_other_comments_section --> <sub>(5/5) You can turn off certain types of comments like style [here](https://app.greptile.com/review/github)!</sub> <!-- /greptile_comment -->

Most Similar PRs