Repository navigation
Conversation
…t 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 evolution-foundation#2773 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Reviewer's GuideImplementationUnwraps ephemeral message envelopes before deriving the payload, message type, and context info so disappearing messages reach downstream consumers.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts" line_range="5166" />
<code_context>
+ // 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 = {
</code_context>
<issue_to_address>
**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`.
</issue_to_address>
### Comment 2
<location path="src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts" line_range="5187" />
<code_context>
instanceId: this.instanceId,
status: status[message.status],
- contextInfo: this.deserializeMessageBuffers(message.message?.messageContextInfo),
+ contextInfo: this.deserializeMessageBuffers(content?.messageContextInfo),
};
</code_context>
<issue_to_address>
**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.
</issue_to_address>
### Comment 3
<location path="src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts" line_range="5166" />
<code_context>
+ // 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 = {
</code_context>
<issue_to_address>
**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`.
</issue_to_address>Sourcery assessment
Approval pending. 3 findings to address first.
Blocking findings: src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts:5166, src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts:5187, src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts:5166
| // 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; |
There was a problem hiding this comment.
🟡 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`.| instanceId: this.instanceId, | ||
| status: status[message.status], | ||
| contextInfo: this.deserializeMessageBuffers(message.message?.messageContextInfo), | ||
| contextInfo: this.deserializeMessageBuffers(content?.messageContextInfo), |
There was a problem hiding this comment.
🟡 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.| // 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; |
There was a problem hiding this comment.
🟡 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`.
📋 Description
When a contact has disappearing messages enabled, WhatsApp delivers the inbound payload wrapped in an
ephemeralMessageenvelope. InprepareMessage(),messageTypeis derived fromgetContentType(message.message), which returnsephemeralMessage, so the real content (text, media, etc.) stays buried one level down. Downstream consumers don't recognise that type, so the message is never stored or forwarded — effectively dropped, which is what #2773 reports.This unwraps the
ephemeralMessageenvelope before deriving the type, payload andcontextInfo, mirroring howprepareMessage()already flattensextendedTextMessageanddocumentWithCaptionMessage. Non-ephemeral messages are left untouched by the?? message.messagefallback, so there is no behaviour change for regular messages.🔗 Related Issue
Closes #2773
🧪 Type of Change
🧪 Testing
Validated on a clean checkout of
develop:npm run build(tsc --noEmit+tsup) passes.eslintreports no issues on the changed file.ephemeralMessagepayloadgetContentType(message.message)returnsephemeralMessage, so the existing code never reaches the inner content. The one-level unwrap resolves the actual inner type; regular messages are unchanged becausecontent === message.messagewhen there is no envelope.✅ Checklist
Summary by Sourcery
Bug Fixes: