Skip to content

Commit cfa475d

Browse files
Implement quoted product message handling
Added handling for quoted product messages including price extraction and formatting.
1 parent 796bc4c commit cfa475d

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,6 +1827,7 @@ export class ChatwootService {
18271827
listMessage: msg.listMessage,
18281828
listResponseMessage: msg.listResponseMessage,
18291829
orderMessage: msg.orderMessage,
1830+
quotedProductMessage: msg.contextInfo?.quotedMessage?.productMessage,
18301831
viewOnceMessageV2:
18311832
msg?.message?.viewOnceMessageV2?.message?.imageMessage?.url ||
18321833
msg?.message?.viewOnceMessageV2?.message?.videoMessage?.url ||
@@ -1861,6 +1862,40 @@ export class ChatwootService {
18611862
}
18621863
this.processedOrderIds.set(result.orderId, now);
18631864
}
1865+
// Tratamento de Produto citado (WhatsApp Desktop)
1866+
if (typeKey === 'quotedProductMessage' && result?.product) {
1867+
const product = result.product;
1868+
1869+
// Extrai preço
1870+
let rawPrice = 0;
1871+
const amount = product.priceAmount1000;
1872+
1873+
if (Long.isLong(amount)) {
1874+
rawPrice = amount.toNumber();
1875+
} else if (amount && typeof amount === 'object' && 'low' in amount) {
1876+
rawPrice = Long.fromValue(amount).toNumber();
1877+
} else if (typeof amount === 'number') {
1878+
rawPrice = amount;
1879+
}
1880+
1881+
const price = (rawPrice / 1000).toLocaleString('pt-BR', {
1882+
style: 'currency',
1883+
currency: product.currencyCode || 'BRL',
1884+
});
1885+
1886+
const productTitle = product.title || 'Produto do catálogo';
1887+
const productId = product.productId || 'N/A';
1888+
1889+
return (
1890+
`🛒 *PRODUTO DO CATÁLOGO (Desktop)*\n` +
1891+
`━━━━━━━━━━━━━━━━━━━━━\n` +
1892+
`📦 *Produto:* ${productTitle}\n` +
1893+
`💰 *Preço:* ${price}\n` +
1894+
`🆔 *Código:* ${productId}\n` +
1895+
`━━━━━━━━━━━━━━━━━━━━━\n` +
1896+
`_Cliente perguntou: "${types.conversation || 'Me envia este produto?'}"_`
1897+
);
1898+
}
18641899
if (typeKey === 'orderMessage') {
18651900
// Extrai o valor - pode ser Long, objeto {low, high}, ou número direto
18661901
let rawPrice = 0;

0 commit comments

Comments
 (0)