From 2c2e14512e53f3ed84b86136a361d041110d3b79 Mon Sep 17 00:00:00 2001 From: Rafael Silverio Date: Thu, 3 Dec 2026 01:41:57 -0300 Subject: [PATCH] fix(baileys): unwrap ephemeralMessage so disappearing messages are not dropped When a contact has disappearing messages enabled, WhatsApp delivers the payload wrapped in an `ephemeralMessage` envelope. `prepareMessage` derived `messageType` from `getContentType(message.message)`, which returns `ephemeralMessage`, leaving the real content (text, media, etc.) buried. Downstream consumers don't recognise that type, so the message is never stored or forwarded and the event is effectively dropped. Unwrap the envelope before deriving the type, payload and contextInfo, mirroring how `prepareMessage` already flattens `extendedTextMessage` and `documentWithCaptionMessage`. Non-ephemeral messages are unaffected thanks to the `?? message.message` fallback. Fixes #2773 Co-Authored-By: Claude Opus 4.8 --- .../channel/whatsapp/whatsapp.baileys.service.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index 22839fd451..ce3206121c 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -5155,6 +5155,16 @@ export class BaileysStartupService extends ChannelStartupService { private prepareMessage(message: WAMessage): Message { const keyAny = message.key as any; + + // When a contact has disappearing messages enabled, WhatsApp wraps the + // real payload in an `ephemeralMessage` envelope. `getContentType` then + // reports `ephemeralMessage` and the actual content (text, media, etc.) + // stays buried, so downstream consumers never see a usable message and the + // event is effectively dropped (issue #2773). Unwrap the envelope so the + // message is processed as its inner type. Non-ephemeral messages are left + // untouched by the `?? message.message` fallback. + const content = message.message?.ephemeralMessage?.message ?? message.message; + const messageRaw: any = { key: { ...message.key, @@ -5166,15 +5176,15 @@ export class BaileysStartupService extends ChannelStartupService { (message.key.fromMe ? 'VocĂȘ' : message?.participant || (message.key?.participant ? message.key.participant.split('@')[0] : null)), - message: this.deserializeMessageBuffers({ ...message.message }), - messageType: getContentType(message.message), + message: this.deserializeMessageBuffers({ ...content }), + messageType: getContentType(content), messageTimestamp: Long.isLong(message.messageTimestamp) ? message.messageTimestamp.toNumber() : (message.messageTimestamp as number), source: getDevice(keyAny.id), instanceId: this.instanceId, status: status[message.status], - contextInfo: this.deserializeMessageBuffers(message.message?.messageContextInfo), + contextInfo: this.deserializeMessageBuffers(content?.messageContextInfo), }; if (!messageRaw.status && message.key.fromMe === false) {