From 3d51b45e2b22504ac73a3ba4a9ebad4fb0ffc717 Mon Sep 17 00:00:00 2001 From: Richards0n Date: Fri, 8 Nov 2024 00:25:00 -0300 Subject: [PATCH] feat: format participant phone number in messages --- .../chatbot/chatwoot/services/chatwoot.service.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts b/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts index 503a5cc9..adcc9c3c 100644 --- a/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts +++ b/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts @@ -1970,11 +1970,16 @@ export class ChatwootService { if (body.key.remoteJid.includes('@g.us')) { const participantName = body.pushName; + const rawPhoneNumber = body.key.remoteJid.split('@')[0]; + const formattedPhoneNumber = `+${rawPhoneNumber.slice(0, 2)} (${rawPhoneNumber.slice( + 2, + 4, + )}) ${rawPhoneNumber.slice(4, 8)}-${rawPhoneNumber.slice(8)}`; let content: string; if (!body.key.fromMe) { - content = `**${participantName}:**\n\n${bodyMessage}`; + content = `**${formattedPhoneNumber} - ${participantName}:**\n\n${bodyMessage}`; } else { content = `${bodyMessage}`; } @@ -2099,11 +2104,16 @@ export class ChatwootService { if (body.key.remoteJid.includes('@g.us')) { const participantName = body.pushName; + const rawPhoneNumber = body.key.remoteJid.split('@')[0]; + const formattedPhoneNumber = `+${rawPhoneNumber.slice(0, 2)} (${rawPhoneNumber.slice( + 2, + 4, + )}) ${rawPhoneNumber.slice(4, 8)}-${rawPhoneNumber.slice(8)}`; let content: string; if (!body.key.fromMe) { - content = `**${participantName}**\n\n${bodyMessage}`; + content = `**${formattedPhoneNumber} - ${participantName}:**\n\n${bodyMessage}`; } else { content = `${bodyMessage}`; }