From 833cf06d4c9c11fbb22338bea658eddf6a463895 Mon Sep 17 00:00:00 2001 From: OrionDesign Date: Mon, 19 May 2025 11:18:02 -0300 Subject: [PATCH] =?UTF-8?q?Corre=C3=A7=C3=A3o=20do=20Markdown=20na=20integ?= =?UTF-8?q?ra=C3=A7=C3=A3o=20N8N?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Descrição Esta PR implementa melhorias no processamento de mensagens do serviço N8n, especificamente no método `sendMessageWhatsApp`. As alterações visam melhorar o tratamento de links e formatação markdown nas mensagens. ## Mudanças - Ajustada a desestruturação do objeto `match` para capturar corretamente o texto completo do link markdown - Modificado o tratamento de links que não são mídia para preservar a formatação original - Mantida a expressão regular para detecção de links markdown ## Impacto - Mensagens com links markdown agora são processadas de forma mais consistente - A formatação original dos links é preservada quando não são tratados como mídia - Melhor tratamento de casos onde o link não corresponde a um tipo de mídia suportado --- src/api/integrations/chatbot/n8n/services/n8n.service.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/api/integrations/chatbot/n8n/services/n8n.service.ts b/src/api/integrations/chatbot/n8n/services/n8n.service.ts index a2556882..ef7cb691 100644 --- a/src/api/integrations/chatbot/n8n/services/n8n.service.ts +++ b/src/api/integrations/chatbot/n8n/services/n8n.service.ts @@ -194,7 +194,7 @@ export class N8nService { } private async sendMessageWhatsApp(instance: any, remoteJid: string, message: string, settings: N8nSetting) { - const linkRegex = /(!?)\[(.*?)\]\((.*?)\)/g; + const linkRegex = /!?\[(.*?)\]\((.*?)\)/g; let textBuffer = ''; let lastIndex = 0; let match: RegExpExecArray | null; @@ -211,7 +211,7 @@ export class N8nService { return null; }; while ((match = linkRegex.exec(message)) !== null) { - const [altText, url] = match; + const [fullMatch, altText, url] = match; const mediaType = getMediaType(url); const beforeText = message.slice(lastIndex, match.index); if (beforeText) { @@ -282,7 +282,7 @@ export class N8nService { ); } } else { - textBuffer += `[${altText}](${url})`; + textBuffer += fullMatch; } lastIndex = linkRegex.lastIndex; }