fix(whatsapp): pass Baileys quoted reply text to the agent - #53228
Closed
herbalizer404 wants to merge 1 commit into
Closed
fix(whatsapp): pass Baileys quoted reply text to the agent#53228herbalizer404 wants to merge 1 commit into
herbalizer404 wants to merge 1 commit into
Conversation
herbalizer404
force-pushed
the
fix/whatsapp-baileys-quoted-replies
branch
from
June 26, 2026 19:31
1749286 to
4da5a71
Compare
Contributor
|
This fix landed on main via PR #58865 (salvage of #58704), which made the same change — quoted-reply context moved from a pre-rendered Your PR was submitted first and correctly diagnosed both the duplication and the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Baileys WhatsApp bridge already forwards reply metadata such as
quotedMessageId,quotedParticipant, andhasQuotedMessage, and the Python adapter has logic that looks for aquotedTextfield.However,
scripts/whatsapp-bridge/bridge.jsnever populatedquotedTextfrom Baileys'contextInfo.quotedMessage. As a result, replies such as "approve", "ok", or "what about this?" reached the agent without the actual text of the quoted WhatsApp message. The model could see that the incoming message was a reply, but not what it was replying to.This is the same user-visible class of issue addressed for WhatsApp Cloud in #52957, but on the Baileys/Web bridge path.
Root cause
Baileys exposes the quoted payload under
contextInfo.quotedMessage, but the bridge event only serialized:quotedMessageIdquotedParticipantquotedRemoteJidhasQuotedMessageThe downstream adapter therefore had no text to pass into the platform-neutral reply context fields.
Fix
This PR updates the Baileys bridge and adapter path to preserve quoted reply text using the existing
MessageEventreply-context mechanism:scripts/whatsapp-bridge/bridge.jsextractTextFromMessageContent(...)for quoted Baileys payloadsquotedTextin the bridge eventplugins/platforms/whatsapp/adapter.py[Replying to: ...]directly intobodyMessageEvent.reply_to_message_idMessageEvent.reply_to_textMessageEvent.reply_to_is_own_messageThis leaves
gateway/run.pyresponsible for the standard reply-context injection path, which keeps the behavior aligned with other platform adapters and avoids duplicating reply-context formatting inside the WhatsApp adapter.Tests
Added/extended coverage in
tests/gateway/test_whatsapp_formatting.pyfor:reply_to_textreply_to_message_idreply_to_is_own_messageValidation run on a clean worktree rebased on current
origin/main:Result:
Additional checks:
Both passed.
Notes / limitations
If Baileys does not include
contextInfo.quotedMessagefor older messages or unsupported message types, Hermes will still preserve the quoted message id, butreply_to_textwill remain unset. The extractor covers the common text/caption/button/list reply shapes and can be extended for additional WhatsApp message types later.