diff --git a/src/core/utils/PhoneJidNormalizer.test.ts b/src/core/utils/PhoneJidNormalizer.test.ts index 047b5795..591b884f 100644 --- a/src/core/utils/PhoneJidNormalizer.test.ts +++ b/src/core/utils/PhoneJidNormalizer.test.ts @@ -20,25 +20,18 @@ describe('E164Parser.fromJid', () => { expect(E164Parser.fromJid('@s.whatsapp.net')).toBeNull(); }); - it('applies Brazil add-9 rule when local has 8 digits (any first digit)', () => { - // +55 - expect(E164Parser.fromJid('553188888888@s.whatsapp.net')).toBe( - '+5531988888888', + it('does not add 9 for BR landline (local starts with 2..5)', () => { + expect(E164Parser.fromJid('558540423147@s.whatsapp.net')).toBe( + '+558540423147', + ); + expect(E164Parser.fromJid('558820181896@s.whatsapp.net')).toBe( + '+558820181896', ); }); - it('554999111111 => 5549999111111', () => { - expect(E164Parser.fromJid('554999111111@s.whatsapp.net')).toBe( - '+5549999111111', - ); - }); - - it('adds 9 even when local already starts with 9 (Brazil)', () => { - expect(E164Parser.fromJid('553198888888@s.whatsapp.net')).toBe( - '+5531998888888', - ); - expect(E164Parser.fromJid('553199999999@s.whatsapp.net')).toBe( - '+5531999999999', + it('adds 9 for BR mobile/others (local not starting with 2..5)', () => { + expect(E164Parser.fromJid('558591203123@s.whatsapp.net')).toBe( + '+5585991203123', ); }); diff --git a/src/core/utils/PhoneJidNormalizer.ts b/src/core/utils/PhoneJidNormalizer.ts index c855e3f3..4eb7fc86 100644 --- a/src/core/utils/PhoneJidNormalizer.ts +++ b/src/core/utils/PhoneJidNormalizer.ts @@ -56,7 +56,15 @@ export class PhoneJidNormalizer { } const RULES = [ - // Brazil - ensure mobile numbers have 9 digits after DDD + // Brazil landline (fixed line) heuristic: + // +55 where local[0] is 2..5 => do NOT add extra 9 + { + name: 'br-no-add-9-for-landline', + re: /^\+55(\d{2})([2-5]\d{7})$/, + replace: '+55$1$2', + }, + // Brazil mobile/others: + // +55 => add extra 9 after DDD { name: 'br-add-9-after-ddd', re: /^\+55(\d{2})(\d{8})$/,