fix: extract reply/quoted message context from WhatsApp#92
fix: extract reply/quoted message context from WhatsApp#92IamAdamJowett wants to merge 2 commits into
Conversation
…ages The generic reply context fields (reply_to_message_id, reply_to_message_content, reply_to_sender_name) were added to NewMessage, the DB schema, and the router in ee599b9 but the WhatsApp channel never extracted contextInfo from incoming messages. Extracts stanzaId, quoted message text, and participant from extendedText, image, video, document, and audio message types so agents can see what message is being replied to. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ed6dca7c20
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const quotedParticipant = contextInfo.participant || ''; | ||
| if (quotedParticipant) { |
There was a problem hiding this comment.
Populate quoted sender for non-group replies
This only derives replyToSenderName from contextInfo.participant, which can be empty outside group chats; in that case the quoted sender stays undefined even when stanzaId and quoted text are present. Because formatMessages only emits <quoted_message> when both content and sender are set (src/router.ts), reply context is dropped for those chats. Add a fallback sender source when participant is missing so quoted context is preserved consistently.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Addressed in 59a8cef — falls back to chatJid when contextInfo.participant is empty (DMs), so replyToSenderName is always populated when quoted content exists.
| if (contextInfo?.stanzaId && contextInfo?.quotedMessage) { | ||
| replyToMessageId = contextInfo.stanzaId; |
There was a problem hiding this comment.
Preserve reply ID even without quoted payload
replyToMessageId is assigned only when both stanzaId and quotedMessage exist, so any message that carries a reply ID but no embedded quoted payload loses the reply_to linkage entirely. Downstream formatting already supports rendering a reply attribute without quoted text, so this should set replyToMessageId whenever stanzaId is present and only gate content extraction on quotedMessage.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Addressed in 59a8cef — replyToMessageId is now set whenever stanzaId is present, independently of quotedMessage.
Address two review findings: 1. Set reply_to_message_id whenever stanzaId is present, even without an embedded quotedMessage — the router already supports rendering reply_to as an attribute without <quoted_message>. 2. Fall back to chatJid when contextInfo.participant is empty (DMs), so reply context is preserved in non-group chats where participant is not populated by WhatsApp. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
What
Extracts
contextInfofrom incoming WhatsApp messages so the reply-to fields (reply_to_message_id,reply_to_message_content,reply_to_sender_name) are populated and passed to the agent.Why
The generic reply context infrastructure was added in ee599b9 (types, DB columns, router formatting as
<quoted_message>XML) but the WhatsApp channel never extractedcontextInfofrom Baileys messages. Agents could not see what message was being replied to.How it works
Reads
contextInfofromextendedTextMessage,imageMessage,videoMessage,documentMessage, andaudioMessage. When astanzaIdandquotedMessageare present, extracts the quoted text and resolves the sender (including LID→phone translation for group participants).How it was tested
Deployed and tested on a live NanoClaw instance. Verified that replying to a message in WhatsApp now shows the quoted content in the agent's context via the existing
<quoted_message>XML formatting.Change type
🤖 Generated with Claude Code