@@ -1021,10 +1021,12 @@ export class ChatwootService {
10211021 body . conversation . meta . sender ?. phone_number ?. replace ( '+' , '' ) || body . conversation . meta . sender ?. identifier ;
10221022 // Chatwoot to Whatsapp
10231023 const messageReceived = body . content
1024- . replaceAll ( / (?< ! \* ) \* ( (? ! \s ) ( [ ^ \n * ] + ?) (?< ! \s ) ) \* (? ! \* ) / g, '_$1_' ) // Substitui * por _
1025- . replaceAll ( / \* { 2 } ( (? ! \s ) ( [ ^ \n * ] + ?) (?< ! \s ) ) \* { 2 } / g, '*$1*' ) // Substitui ** por *
1026- . replaceAll ( / ~ { 2 } ( (? ! \s ) ( [ ^ \n * ] + ?) (?< ! \s ) ) ~ { 2 } / g, '~$1~' ) // Substitui ~~ por ~
1027- . replaceAll ( / (?< ! ` ) ` ( (? ! \s ) ( [ ^ ` * ] + ?) (?< ! \s ) ) ` (? ! ` ) / g, '```$1```' ) ; // Substitui ` por ```
1024+ ? body . content
1025+ . replaceAll ( / (?< ! \* ) \* ( (? ! \s ) ( [ ^ \n * ] + ?) (?< ! \s ) ) \* (? ! \* ) / g, '_$1_' ) // Substitui * por _
1026+ . replaceAll ( / \* { 2 } ( (? ! \s ) ( [ ^ \n * ] + ?) (?< ! \s ) ) \* { 2 } / g, '*$1*' ) // Substitui ** por *
1027+ . replaceAll ( / ~ { 2 } ( (? ! \s ) ( [ ^ \n * ] + ?) (?< ! \s ) ) ~ { 2 } / g, '~$1~' ) // Substitui ~~ por ~
1028+ . replaceAll ( / (?< ! ` ) ` ( (? ! \s ) ( [ ^ ` * ] + ?) (?< ! \s ) ) ` (? ! ` ) / g, '```$1```' ) // Substitui ` por ```
1029+ : body . content ;
10281030
10291031 const senderName = body ?. sender ?. name ;
10301032 const waInstance = this . waMonitor . waInstances [ instance . instanceName ] ;
@@ -1484,10 +1486,13 @@ export class ChatwootService {
14841486 this . logger . verbose ( 'get conversation message' ) ;
14851487
14861488 // Whatsapp to Chatwoot
1487- const bodyMessage = await this . getConversationMessage ( body . message )
1488- . replaceAll ( / \* ( (? ! \s ) ( [ ^ \n * ] + ?) (?< ! \s ) ) \* / g, '**$1**' )
1489- . replaceAll ( / _ ( (? ! \s ) ( [ ^ \n _ ] + ?) (?< ! \s ) ) _ / g, '*$1*' )
1490- . replaceAll ( / ~ ( (? ! \s ) ( [ ^ \n ~ ] + ?) (?< ! \s ) ) ~ / g, '~~$1~~' ) ;
1489+ const originalMessage = await this . getConversationMessage ( body . message ) ;
1490+ const bodyMessage = originalMessage
1491+ ? originalMessage
1492+ . replaceAll ( / \* ( (? ! \s ) ( [ ^ \n * ] + ?) (?< ! \s ) ) \* / g, '**$1**' )
1493+ . replaceAll ( / _ ( (? ! \s ) ( [ ^ \n _ ] + ?) (?< ! \s ) ) _ / g, '*$1*' )
1494+ . replaceAll ( / ~ ( (? ! \s ) ( [ ^ \n ~ ] + ?) (?< ! \s ) ) ~ / g, '~~$1~~' )
1495+ : originalMessage ;
14911496
14921497 this . logger . verbose ( 'body message: ' + bodyMessage ) ;
14931498
0 commit comments