mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2026-03-21 20:18:40 -06:00
Implement quoted product message handling
Added handling for quoted product messages including price extraction and formatting.
This commit is contained in:
@@ -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 ||
|
||||
@@ -1860,6 +1861,40 @@ export class ChatwootService {
|
||||
return undefined; // Ignora duplicado
|
||||
}
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user