Skip to content

Commit 8fbf7fa

Browse files
committed
[core] ChatWoot - brazil phone number
fix #1261
1 parent af0bba3 commit 8fbf7fa

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/core/utils/PhoneJidNormalizer.test.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,25 @@ describe('E164Parser.fromJid', () => {
1212
expect(E164Parser.fromJid('@s.whatsapp.net')).toBeNull();
1313
});
1414

15-
it('applies Brazil DDD + add-9 rule when local has 8 digits and not starting with 9', () => {
16-
// +55 <DDD:2> <local:8> and local does not start with 9
15+
it('applies Brazil add-9 rule when local has 8 digits (any first digit)', () => {
16+
// +55 <DDD:2> <local:8>
1717
expect(E164Parser.fromJid('[email protected]')).toBe(
1818
'+5531988888888',
1919
);
2020
});
2121

22-
it('does not add 9 when local already starts with 9 (Brazil)', () => {
22+
it('554999111111 => 5549999111111', () => {
23+
expect(E164Parser.fromJid('[email protected]')).toBe(
24+
'+5549999111111',
25+
);
26+
});
27+
28+
it('adds 9 even when local already starts with 9 (Brazil)', () => {
2329
expect(E164Parser.fromJid('[email protected]')).toBe(
24-
'+553198888888',
30+
'+5531998888888',
2531
);
2632
expect(E164Parser.fromJid('[email protected]')).toBe(
27-
'+553199999999',
33+
'+5531999999999',
2834
);
2935
});
3036

src/core/utils/PhoneJidNormalizer.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,10 @@ export class PhoneJidNormalizer {
5353
}
5454

5555
const RULES = [
56-
// Brazil - add 9 before Direct Distance Dialing
57-
// +55 <DDD:2> <local:8>, not already starting with 9
58-
// +553188888888 => +5531988888888
56+
// Brazil - ensure mobile numbers have 9 digits after DDD
5957
{
6058
name: 'br-add-9-after-ddd',
61-
re: /^\+55(\d{2})(?!9)(\d{8})$/,
59+
re: /^\+55(\d{2})(\d{8})$/,
6260
replace: '+55$19$2',
6361
},
6462
];

0 commit comments

Comments
 (0)