Repository navigation
fix(baileys): unwrap ephemeralMessage so disappearing messages are not dropped (#2773) #2817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, Use the unwrapped content when detecting and handling edit protocol messages in Prompt for AI agentsIn `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, | ||
|
|
@@ -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), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Poll votes cannot be decrypted When an ephemeral poll carries When storing Prompt for AI agentsIn `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) { | ||
|
|
||
There was a problem hiding this comment.
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,
prepareMessageunwraps the content formessageRaw, butmessages.upsertstill checks the wrappedreceived.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.upsertfor media detection and downstream media handling.Also at
src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts:5180.Prompt for AI agents