@@ -1970,11 +1970,16 @@ export class ChatwootService {
19701970
19711971 if ( body . key . remoteJid . includes ( '@g.us' ) ) {
19721972 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+ }
19781983
19791984 let content : string ;
19801985
@@ -2104,11 +2109,16 @@ export class ChatwootService {
21042109
21052110 if ( body . key . remoteJid . includes ( '@g.us' ) ) {
21062111 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+ }
21122122
21132123 let content : string ;
21142124
0 commit comments