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

@ -4250,24 +4250,41 @@ export class BaileysStartupService extends ChannelStartupService {
} }
private prepareMessage(message: proto.IWebMessageInfo): any { private prepareMessage(message: proto.IWebMessageInfo): any {
const contentType = getContentType(message.message); const contentType = getContentType(message.message);
const contentMsg = message?.message[contentType] as any; const contentMsg = message?.message[contentType] as any;
const messageRaw = { // [ADD] Merge seguro de contextInfo
key: message.key, const mm = message.message as Record<string, any> | undefined;
pushName: const contentCtx =
message.pushName || contentType && mm && typeof mm[contentType] === 'object'
(message.key.fromMe ? mm[contentType]?.contextInfo
? 'Você' : undefined;
: message?.participant || (message.key?.participant ? message.key.participant.split('@')[0] : null)),
status: status[message.status], const mergedContext: Record<string, any> = {
message: { ...message.message }, ...(contentCtx || {}),
contextInfo: contentMsg?.contextInfo, ...(message.message?.contextInfo || {}),
messageType: contentType || 'unknown', ...(message.messageContextInfo || {}),
messageTimestamp: message.messageTimestamp as number, };
instanceId: this.instanceId,
source: getDevice(message.key.id), 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) { if (!messageRaw.status && message.key.fromMe === false) {
messageRaw.status = status[3]; // DELIVERED MESSAGE messageRaw.status = status[3]; // DELIVERED MESSAGE