From 61884d80ce0df45f8564ecb40c87ffcdb2525a04 Mon Sep 17 00:00:00 2001 From: MailoncBerni Date: Fri, 8 Aug 2025 22:04:44 -0300 Subject: [PATCH] Update whatsapp.baileys.service.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Alteração realizada para preservar todos os metadados recebidos no contextInfo (incluindo ctwa_clid, ctwaPayload, conversionData e entryPointConversion*), unificando dados vindos de: - message.message[contentType].contextInfo - message.message.contextInfo - message.messageContextInfo Essa mudança evita a perda de informações enviadas pela Meta em diferentes níveis da estrutura da mensagem, garantindo que esses campos sejam repassados integralmente para o webhook, permitindo integrações completas com a API de Conversões. --- .../whatsapp/whatsapp.baileys.service.ts | 51 ++++++++++++------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index 758a5bf9..905baed7 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -4250,24 +4250,41 @@ export class BaileysStartupService extends ChannelStartupService { } private prepareMessage(message: proto.IWebMessageInfo): any { - const contentType = getContentType(message.message); - const contentMsg = message?.message[contentType] as any; + const contentType = getContentType(message.message); + const contentMsg = message?.message[contentType] as any; - const messageRaw = { - key: message.key, - pushName: - message.pushName || - (message.key.fromMe - ? 'Você' - : message?.participant || (message.key?.participant ? message.key.participant.split('@')[0] : null)), - status: status[message.status], - message: { ...message.message }, - contextInfo: contentMsg?.contextInfo, - messageType: contentType || 'unknown', - messageTimestamp: message.messageTimestamp as number, - instanceId: this.instanceId, - source: getDevice(message.key.id), - }; + // [ADD] Merge seguro de contextInfo + const mm = message.message as Record | undefined; + const contentCtx = + contentType && mm && typeof mm[contentType] === 'object' + ? mm[contentType]?.contextInfo + : undefined; + + const mergedContext: Record = { + ...(contentCtx || {}), + ...(message.message?.contextInfo || {}), + ...(message.messageContextInfo || {}), + }; + + const contextInfoFinal = Object.keys(mergedContext).length > 0 ? mergedContext : undefined; + + const messageRaw = { + key: message.key, + pushName: + message.pushName || + (message.key.fromMe + ? 'Você' + : message?.participant || + (message.key?.participant ? message.key.participant.split('@')[0] : null)), + status: status[message.status], + message: { ...message.message }, + // [REPLACE] antes: contextInfo: contentMsg?.contextInfo, + contextInfo: contextInfoFinal, + messageType: contentType || 'unknown', + messageTimestamp: message.messageTimestamp as number, + instanceId: this.instanceId, + source: getDevice(message.key.id), + }; if (!messageRaw.status && message.key.fromMe === false) { messageRaw.status = status[3]; // DELIVERED MESSAGE