From cfa475d47beb4e7db1438fe4381e7a63d28a38c1 Mon Sep 17 00:00:00 2001 From: ValdecirMysian Date: Sun, 1 Feb 2026 15:37:20 -0300 Subject: [PATCH] Implement quoted product message handling Added handling for quoted product messages including price extraction and formatting. --- .../chatwoot/services/chatwoot.service.ts | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts b/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts index b0bd12d2..49111962 100644 --- a/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts +++ b/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts @@ -1827,6 +1827,7 @@ export class ChatwootService { listMessage: msg.listMessage, listResponseMessage: msg.listResponseMessage, orderMessage: msg.orderMessage, + quotedProductMessage: msg.contextInfo?.quotedMessage?.productMessage, viewOnceMessageV2: msg?.message?.viewOnceMessageV2?.message?.imageMessage?.url || msg?.message?.viewOnceMessageV2?.message?.videoMessage?.url || @@ -1861,6 +1862,40 @@ export class ChatwootService { } this.processedOrderIds.set(result.orderId, now); } + // Tratamento de Produto citado (WhatsApp Desktop) +if (typeKey === 'quotedProductMessage' && result?.product) { + const product = result.product; + + // Extrai preΓ§o + let rawPrice = 0; + const amount = product.priceAmount1000; + + if (Long.isLong(amount)) { + rawPrice = amount.toNumber(); + } else if (amount && typeof amount === 'object' && 'low' in amount) { + rawPrice = Long.fromValue(amount).toNumber(); + } else if (typeof amount === 'number') { + rawPrice = amount; + } + + const price = (rawPrice / 1000).toLocaleString('pt-BR', { + style: 'currency', + currency: product.currencyCode || 'BRL', + }); + + const productTitle = product.title || 'Produto do catΓ‘logo'; + const productId = product.productId || 'N/A'; + + return ( + `πŸ›’ *PRODUTO DO CATÁLOGO (Desktop)*\n` + + `━━━━━━━━━━━━━━━━━━━━━\n` + + `πŸ“¦ *Produto:* ${productTitle}\n` + + `πŸ’° *PreΓ§o:* ${price}\n` + + `πŸ†” *CΓ³digo:* ${productId}\n` + + `━━━━━━━━━━━━━━━━━━━━━\n` + + `_Cliente perguntou: "${types.conversation || 'Me envia este produto?'}"_` + ); +} if (typeKey === 'orderMessage') { // Extrai o valor - pode ser Long, objeto {low, high}, ou nΓΊmero direto let rawPrice = 0;