@@ -1970,11 +1970,16 @@ export class ChatwootService {
1970
1970
1971
1971
if ( body . key . remoteJid . includes ( '@g.us' ) ) {
1972
1972
const participantName = body . pushName ;
1973
- const rawPhoneNumber = body . key . remoteJid . split ( '@' ) [ 0 ] ;
1974
- const formattedPhoneNumber = `+${ rawPhoneNumber . slice ( 0 , 2 ) } (${ rawPhoneNumber . slice (
1975
- 2 ,
1976
- 4 ,
1977
- ) } ) ${ rawPhoneNumber . slice ( 4 , 8 ) } -${ rawPhoneNumber . slice ( 8 ) } `;
1973
+ const rawPhoneNumber = body . key . participant . split ( '@' ) [ 0 ] ;
1974
+ const phoneMatch = rawPhoneNumber . match ( / ^ ( \d { 2 } ) ( \d { 2 } ) ( \d { 4 } ) ( \d { 4 } ) $ / ) ;
1975
+
1976
+ let formattedPhoneNumber : string ;
1977
+
1978
+ if ( phoneMatch ) {
1979
+ formattedPhoneNumber = `+${ phoneMatch [ 1 ] } (${ phoneMatch [ 2 ] } ) ${ phoneMatch [ 3 ] } -${ phoneMatch [ 4 ] } ` ;
1980
+ } else {
1981
+ formattedPhoneNumber = `+${ rawPhoneNumber } ` ;
1982
+ }
1978
1983
1979
1984
let content : string ;
1980
1985
@@ -2104,11 +2109,16 @@ export class ChatwootService {
2104
2109
2105
2110
if ( body . key . remoteJid . includes ( '@g.us' ) ) {
2106
2111
const participantName = body . pushName ;
2107
- const rawPhoneNumber = body . key . remoteJid . split ( '@' ) [ 0 ] ;
2108
- const formattedPhoneNumber = `+${ rawPhoneNumber . slice ( 0 , 2 ) } (${ rawPhoneNumber . slice (
2109
- 2 ,
2110
- 4 ,
2111
- ) } ) ${ rawPhoneNumber . slice ( 4 , 8 ) } -${ rawPhoneNumber . slice ( 8 ) } `;
2112
+ const rawPhoneNumber = body . key . participant . split ( '@' ) [ 0 ] ;
2113
+ const phoneMatch = rawPhoneNumber . match ( / ^ ( \d { 2 } ) ( \d { 2 } ) ( \d { 4 } ) ( \d { 4 } ) $ / ) ;
2114
+
2115
+ let formattedPhoneNumber : string ;
2116
+
2117
+ if ( phoneMatch ) {
2118
+ formattedPhoneNumber = `+${ phoneMatch [ 1 ] } (${ phoneMatch [ 2 ] } ) ${ phoneMatch [ 3 ] } -${ phoneMatch [ 4 ] } ` ;
2119
+ } else {
2120
+ formattedPhoneNumber = `+${ rawPhoneNumber } ` ;
2121
+ }
2112
2122
2113
2123
let content : string ;
2114
2124
0 commit comments