@@ -1774,8 +1774,7 @@ export class ChatwootService {
17741774 liveLocationMessage : msg . liveLocationMessage ,
17751775 listMessage : msg . listMessage ,
17761776 listResponseMessage : msg . listResponseMessage ,
1777- // Adicione a linha abaixo. Atenção à vírgula na linha de cima!
1778- orderMessage : msg . orderMessage ,
1777+ orderMessage : msg . orderMessage ,
17791778 viewOnceMessageV2 :
17801779 msg ?. message ?. viewOnceMessageV2 ?. message ?. imageMessage ?. url ||
17811780 msg ?. message ?. viewOnceMessageV2 ?. message ?. videoMessage ?. url ||
@@ -1795,21 +1794,40 @@ export class ChatwootService {
17951794 result = result . split ( 'externalAdReplyBody|' ) . filter ( Boolean ) . join ( '' ) ;
17961795 }
17971796
1798- // Tratamento de Pedidos do Catálogo
1797+ // Tratamento de Pedidos do Catálogo (WhatsApp Business Catalog)
17991798 if ( typeKey === 'orderMessage' ) {
1799+ // Extrai o valor - pode ser Long, objeto {low, high}, ou número direto
1800+ let rawPrice = 0 ;
18001801 const amount = result . totalAmount1000 ;
1801- // Converte o objeto Long para número antes da divisão
1802- const rawPrice = ( Long . isLong ( amount ) ? amount . toNumber ( ) : amount ) || 0 ;
1802+
1803+ if ( Long . isLong ( amount ) ) {
1804+ rawPrice = amount . toNumber ( ) ;
1805+ } else if ( amount && typeof amount === 'object' && 'low' in amount ) {
1806+ // Formato {low: number, high: number, unsigned: boolean}
1807+ rawPrice = Long . fromValue ( amount ) . toNumber ( ) ;
1808+ } else if ( typeof amount === 'number' ) {
1809+ rawPrice = amount ;
1810+ }
1811+
18031812 const price = ( rawPrice / 1000 ) . toLocaleString ( 'pt-BR' , {
18041813 style : 'currency' ,
18051814 currency : result . totalCurrencyCode || 'BRL' ,
18061815 } ) ;
18071816
1808- return `🛒 *NOVO PEDIDO NO CATÁLOGO*\n\n` +
1809- `*Produto:* ${ result . orderTitle } \n` +
1810- `*Valor:* ${ price } \n` +
1811- `*ID:* ${ result . orderId } \n\n` +
1812- `_Atenda agora para finalizar a venda!_` ;
1817+ const itemCount = result . itemCount || 1 ;
1818+ const orderTitle = result . orderTitle || 'Produto do catálogo' ;
1819+ const orderId = result . orderId || 'N/A' ;
1820+
1821+ return (
1822+ `🛒 *NOVO PEDIDO NO CATÁLOGO*\n` +
1823+ `━━━━━━━━━━━━━━━━━━━━━\n` +
1824+ `📦 *Produto:* ${ orderTitle } \n` +
1825+ `📊 *Quantidade:* ${ itemCount } \n` +
1826+ `💰 *Total:* ${ price } \n` +
1827+ `🆔 *Pedido:* #${ orderId } \n` +
1828+ `━━━━━━━━━━━━━━━━━━━━━\n` +
1829+ `_Responda para atender este pedido!_`
1830+ ) ;
18131831 }
18141832
18151833 if ( typeKey === 'locationMessage' || typeKey === 'liveLocationMessage' ) {
0 commit comments