Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Ephemeral media processing is skipped

When an ephemeral message contains media and the corresponding media handling is enabled, prepareMessage unwraps the content for messageRaw, but messages.upsert still checks the wrapped received.message. Media detection therefore fails, skipping S3 and local-webhook base64 processing, media-record creation, and audio transcription; callers receive messages without the configured media data or transcript.

Use the unwrapped content consistently in messages.upsert for media detection and downstream media handling.

Also at src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts:5180.

Prompt for AI agents
In `src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts` at line 5166:

**Ephemeral media processing is skipped**

When an ephemeral message contains media and the corresponding media handling is enabled, `prepareMessage` unwraps the content for `messageRaw`, but `messages.upsert` still checks the wrapped `received.message`. Media detection therefore fails, skipping S3 and local-webhook base64 processing, media-record creation, and audio transcription; callers receive messages without the configured media data or transcript.

Use the unwrapped content consistently in `messages.upsert` for media detection and downstream media handling.

Also at `src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts:5180`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Disappearing edits leave originals stale

When an ephemeral envelope contains an edit protocol message, messages.upsert checks only received.message for an edit protocol, so a wrapped edit is treated as an ordinary message instead. The existing message is never updated and the edit event is handled as a new message, leaving stored content stale.

Use the unwrapped content when detecting and handling edit protocol messages in messages.upsert.

Prompt for AI agents
In `src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts` at line 5166:

**Disappearing edits leave originals stale**

When an ephemeral envelope contains an edit protocol message, `messages.upsert` checks only `received.message` for an edit protocol, so a wrapped edit is treated as an ordinary message instead. The existing message is never updated and the edit event is handled as a new message, leaving stored content stale.

Use the unwrapped content when detecting and handling edit protocol messages in `messages.upsert`.


const messageRaw: any = {
key: {
...message.key,
Expand All @@ -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),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Poll votes cannot be decrypted

When an ephemeral poll carries messageContextInfo on the outer envelope rather than inside the wrapped message, prepareMessage reads messageContextInfo only from the inner content and drops the outer messageSecret. getMessage and baileysDecryptPollVote cannot retrieve the stored secret, so votes on these polls cannot be decrypted.

When storing contextInfo, fall back to the outer envelope's messageContextInfo if the inner content does not provide it.

Prompt for AI agents
In `src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts` at line 5187:

**Poll votes cannot be decrypted**

When an ephemeral poll carries `messageContextInfo` on the outer envelope rather than inside the wrapped message, `prepareMessage` reads `messageContextInfo` only from the inner content and drops the outer `messageSecret`. `getMessage` and `baileysDecryptPollVote` cannot retrieve the stored secret, so votes on these polls cannot be decrypted.

When storing `contextInfo`, fall back to the outer envelope's `messageContextInfo` if the inner content does not provide it.

};

if (!messageRaw.status && message.key.fromMe === false) {
Expand Down
Loading