Enhance order message structure and content

Refactor order message handling and improve formatting.
This commit is contained in:
ValdecirMysian
2026-01-28 05:26:42 -03:00
committed by GitHub
parent 2d729a3a35
commit 2ff572d80c
@@ -1774,7 +1774,6 @@ export class ChatwootService {
liveLocationMessage: msg.liveLocationMessage, liveLocationMessage: msg.liveLocationMessage,
listMessage: msg.listMessage, listMessage: msg.listMessage,
listResponseMessage: msg.listResponseMessage, listResponseMessage: msg.listResponseMessage,
// Adicione a linha abaixo. Atenção à vírgula na linha de cima!
orderMessage: msg.orderMessage, orderMessage: msg.orderMessage,
viewOnceMessageV2: viewOnceMessageV2:
msg?.message?.viewOnceMessageV2?.message?.imageMessage?.url || msg?.message?.viewOnceMessageV2?.message?.imageMessage?.url ||
@@ -1795,21 +1794,40 @@ export class ChatwootService {
result = result.split('externalAdReplyBody|').filter(Boolean).join(''); result = result.split('externalAdReplyBody|').filter(Boolean).join('');
} }
// Tratamento de Pedidos do Catálogo // Tratamento de Pedidos do Catálogo (WhatsApp Business Catalog)
if (typeKey === 'orderMessage') { if (typeKey === 'orderMessage') {
// Extrai o valor - pode ser Long, objeto {low, high}, ou número direto
let rawPrice = 0;
const amount = result.totalAmount1000; const amount = result.totalAmount1000;
// Converte o objeto Long para número antes da divisão
const rawPrice = (Long.isLong(amount) ? amount.toNumber() : amount) || 0; if (Long.isLong(amount)) {
rawPrice = amount.toNumber();
} else if (amount && typeof amount === 'object' && 'low' in amount) {
// Formato {low: number, high: number, unsigned: boolean}
rawPrice = Long.fromValue(amount).toNumber();
} else if (typeof amount === 'number') {
rawPrice = amount;
}
const price = (rawPrice / 1000).toLocaleString('pt-BR', { const price = (rawPrice / 1000).toLocaleString('pt-BR', {
style: 'currency', style: 'currency',
currency: result.totalCurrencyCode || 'BRL', currency: result.totalCurrencyCode || 'BRL',
}); });
return `🛒 *NOVO PEDIDO NO CATÁLOGO*\n\n` + const itemCount = result.itemCount || 1;
`*Produto:* ${result.orderTitle}\n` + const orderTitle = result.orderTitle || 'Produto do catálogo';
`*Valor:* ${price}\n` + const orderId = result.orderId || 'N/A';
`*ID:* ${result.orderId}\n\n` +
`_Atenda agora para finalizar a venda!_`; return (
`🛒 *NOVO PEDIDO NO CATÁLOGO*\n` +
`━━━━━━━━━━━━━━━━━━━━━\n` +
`📦 *Produto:* ${orderTitle}\n` +
`📊 *Quantidade:* ${itemCount}\n` +
`💰 *Total:* ${price}\n` +
`🆔 *Pedido:* #${orderId}\n` +
`━━━━━━━━━━━━━━━━━━━━━\n` +
`_Responda para atender este pedido!_`
);
} }
if (typeKey === 'locationMessage' || typeKey === 'liveLocationMessage') { if (typeKey === 'locationMessage' || typeKey === 'liveLocationMessage') {