Skip to content

Commit 076f2b4

Browse files
fix: chatwoot media process
1 parent fb24b7e commit 076f2b4

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/whatsapp/services/chatwoot.service.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)