fix(whatsapp): restore reply/quote contextInfo in prepareMessage#2654
fix(whatsapp): restore reply/quote contextInfo in prepareMessage#2654diegocesarmg wants to merge 1 commit into
Conversation
prepareMessage sourced the message contextInfo from `message.message.messageContextInfo`, which only carries device-list / encryption metadata (threadId, deviceListMetadata, messageSecret) and never the quote. The reply context (stanzaId, participant, quotedMessage) lives on the content node instead, e.g. `extendedTextMessage.contextInfo`. Because the extendedTextMessage node is then flattened into `conversation` and deleted, the quote was lost entirely: inbound (and outbound) replies reach the `messages.upsert` webhook and the DB as plain `conversation` with no quotedMessage or stanzaId, so no integration can link a reply to the message it quotes. The existing `messageRaw.contextInfo.quotedMessage` handling right below became dead code. This restores the content-node source (`contentMsg?.contextInfo`) with a fallback to `messageContextInfo`, matching the behaviour that shipped through v2.3.7. The extendedTextMessage->conversation normalization is kept unchanged. Refs evolution-foundation#2078, evolution-foundation#1872. Co-Authored-By: Claude <noreply@anthropic.com>
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRestores proper handling of WhatsApp reply/quote context in prepareMessage by sourcing contextInfo from the message content node while keeping existing normalization logic. Flow diagram for restored contextInfo handling in prepareMessageflowchart TD
A[WAMessage.message] --> B[getContentType]
B --> C[contentType]
C --> D[contentMsg = message.message indexed by contentType]
D --> E{contentMsg.contextInfo exists}
E -- yes --> F[use contentMsg.contextInfo]
E -- no --> G[use message.messageContextInfo]
F --> H[deserializeMessageBuffers]
G --> H[deserializeMessageBuffers]
H --> I[Message.contextInfo]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
d32def5 to
6692b38
Compare
|
@diegocesarmg have you tried in the release cantidates after 2.3.7? exists 2.4.0-rc1, 2.4.0-rc2 (both using baileys rc13) |
|
@dpaes thanks! Yes — I checked, and the bug is already present in 2.4.0-rc1 and 2.4.0-rc2. It isn't a Baileys change. The regression is the
Because This PR just restores the content-node source (with a fallback to |
|
@pastoriniMatheus check this |
Problem
Inbound (and outbound) text replies lose their quote/reply context. A message that quotes another arrives at the
messages.upsertwebhook — and is persisted, and returned bychat/findMessages— asmessageType: "conversation"with nocontextInfo.quotedMessage, nostanzaId, noparticipant. There is no way for any integration (Chatwoot, n8n, custom webhooks) to link a reply to the message it quotes.This matches the long-standing report in #2078 ("Reply/Quote breaks on 2.3.3+") and is part of the
@lidmeta #1872, but the actual cause is a small regression inprepareMessage.Root cause
In
BaileysStartupService.prepareMessage, the messagecontextInfois sourced from the wrong field:message.message.messageContextInfoonly carries device-list / encryption metadata (threadId,deviceListMetadata,messageSecret,limitSharingV2) — it never contains the quote. The reply context (stanzaId,participant,quotedMessage) lives on the content node, e.g.message.message.extendedTextMessage.contextInfo.A few lines below, the
extendedTextMessagenode is flattened intoconversationand deleted:So the quote is dropped entirely, and the
messageRaw.contextInfo.quotedMessagehandling right after it becomes dead code (it can never see aquotedMessage).Regression window
Every stable release sourced
contextInfofrom the content node and quotes worked:contextInfo: contentMsg?.contextInfo(withcontentMsg = message.message[getContentType(...)])contextInfo: message.message?.messageContextInfo❌This is not a Baileys issue: 2.3.7 already runs Baileys
7.0.0-rc.9and delivers the quote correctly. Only the source field changed.Fix
Restore the content-node source, with a fallback to
messageContextInfoso nothing is lost, and reuse the already-computed content type. TheextendedTextMessage -> conversationnormalization is intentionally kept unchanged.After the fix,
messages.upsertagain exposescontextInfo.stanzaId/participant/quotedMessagefor replies, and the downstreamquotedMessagehandling inprepareMessageworks again.messageContextInforemains available undermessageRaw.message.messageContextInfo.Refs #2078, #1872.
Summary by Sourcery
Bug Fixes: