From 27633aad5373788e761fa5c8ceaa6338957a95ab Mon Sep 17 00:00:00 2001 From: Victor Eduardo Date: Thu, 13 Nov 2025 09:47:53 -0300 Subject: [PATCH 1/2] feature: handle with interactive button message for pix --- .../chatwoot/services/chatwoot.service.ts | 54 ++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts b/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts index cc2bd9e4..9e799119 100644 --- a/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts +++ b/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts @@ -1666,6 +1666,13 @@ export class ChatwootService { return result; } + private isInteractiveButtonMessage(messageType: string, message: any) { + return ( + messageType === 'interactiveMessage' && + message.interactiveMessage?.nativeFlowMessage?.buttons?.length > 0 + ); + } + private getAdsMessage(msg: any) { interface AdsMessage { title: string; @@ -1984,8 +1991,9 @@ export class ChatwootService { const adsMessage = this.getAdsMessage(body); const reactionMessage = this.getReactionMessage(body.message); + const isInteractiveButtonMessage = this.isInteractiveButtonMessage(body.messageType, body.message); - if (!bodyMessage && !isMedia && !reactionMessage) { + if (!bodyMessage && !isMedia && !reactionMessage && !isInteractiveButtonMessage) { this.logger.warn('no body message found'); return; } @@ -2118,6 +2126,50 @@ export class ChatwootService { return; } + if (isInteractiveButtonMessage) { + const buttons = body.message.interactiveMessage.nativeFlowMessage.buttons; + this.logger.info('is Interactive Button Message: ' + JSON.stringify(buttons)); + + for (const button of buttons) { + const buttonParams = JSON.parse(button.buttonParamsJson); + const paymentSettings = buttonParams.payment_settings; + + if (button.name === 'payment_info' && paymentSettings[0].type === 'pix_static_code') { + const pixSettings = paymentSettings[0].pix_static_code; + const pixKeyType = (() => { + switch (pixSettings.key_type) { + case 'EVP': + return 'Chave Aleatória'; + case 'EMAIL': + return 'E-mail'; + case 'PHONE': + return 'Telefone'; + default: + return pixSettings.key_type; + } + })(); + const pixKey = pixSettings.key_type === 'PHONE' ? pixSettings.key.replace('+55', '') : pixSettings.key; + const content = `*${pixSettings.merchant_name}*\nChave PIX: ${pixKey} (${pixKeyType})`; + + const send = await this.createMessage( + instance, + getConversation, + content, + messageType, + false, + [], + body, + 'WAID:' + body.key.id, + quotedMsg, + ); + if (!send) this.logger.warn('message not sent'); + } else { + this.logger.warn('Interactive Button Message not mapped'); + } + } + return; + } + const isAdsMessage = (adsMessage && adsMessage.title) || adsMessage.body || adsMessage.thumbnailUrl; if (isAdsMessage) { const imgBuffer = await axios.get(adsMessage.thumbnailUrl, { responseType: 'arraybuffer' }); From 8707520a3e4c41714b725971586001a1b478b447 Mon Sep 17 00:00:00 2001 From: Victor Eduardo Date: Wed, 19 Nov 2025 16:12:16 -0300 Subject: [PATCH 2/2] lint --- .../chatbot/chatwoot/services/chatwoot.service.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts b/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts index 9e799119..c772926d 100644 --- a/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts +++ b/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts @@ -1667,10 +1667,7 @@ export class ChatwootService { } private isInteractiveButtonMessage(messageType: string, message: any) { - return ( - messageType === 'interactiveMessage' && - message.interactiveMessage?.nativeFlowMessage?.buttons?.length > 0 - ); + return messageType === 'interactiveMessage' && message.interactiveMessage?.nativeFlowMessage?.buttons?.length > 0; } private getAdsMessage(msg: any) {