Update whatsapp.baileys.service.ts

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.
This commit is contained in:
MailoncBerni 2025-08-08 22:04:44 -03:00 committed by GitHub
parent 9cdb897a0f
commit 61884d80ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4253,16 +4253,33 @@ export class BaileysStartupService extends ChannelStartupService {
const contentType = getContentType(message.message); const contentType = getContentType(message.message);
const contentMsg = message?.message[contentType] as any; const contentMsg = message?.message[contentType] as any;
// [ADD] Merge seguro de contextInfo
const mm = message.message as Record<string, any> | undefined;
const contentCtx =
contentType && mm && typeof mm[contentType] === 'object'
? mm[contentType]?.contextInfo
: undefined;
const mergedContext: Record<string, any> = {
...(contentCtx || {}),
...(message.message?.contextInfo || {}),
...(message.messageContextInfo || {}),
};
const contextInfoFinal = Object.keys(mergedContext).length > 0 ? mergedContext : undefined;
const messageRaw = { const messageRaw = {
key: message.key, key: message.key,
pushName: pushName:
message.pushName || message.pushName ||
(message.key.fromMe (message.key.fromMe
? 'Você' ? 'Você'
: message?.participant || (message.key?.participant ? message.key.participant.split('@')[0] : null)), : message?.participant ||
(message.key?.participant ? message.key.participant.split('@')[0] : null)),
status: status[message.status], status: status[message.status],
message: { ...message.message }, message: { ...message.message },
contextInfo: contentMsg?.contextInfo, // [REPLACE] antes: contextInfo: contentMsg?.contextInfo,
contextInfo: contextInfoFinal,
messageType: contentType || 'unknown', messageType: contentType || 'unknown',
messageTimestamp: message.messageTimestamp as number, messageTimestamp: message.messageTimestamp as number,
instanceId: this.instanceId, instanceId: this.instanceId,