Skip to content

fix: extract reply/quoted message context from WhatsApp#92

Open
IamAdamJowett wants to merge 2 commits into
nanocoai:mainfrom
IamAdamJowett:fix/whatsapp-reply-context
Open

fix: extract reply/quoted message context from WhatsApp#92
IamAdamJowett wants to merge 2 commits into
nanocoai:mainfrom
IamAdamJowett:fix/whatsapp-reply-context

Conversation

@IamAdamJowett

Copy link
Copy Markdown

What

Extracts contextInfo from 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 extracted contextInfo from Baileys messages. Agents could not see what message was being replied to.

How it works

Reads contextInfo from extendedTextMessage, imageMessage, videoMessage, documentMessage, and audioMessage. When a stanzaId and quotedMessage are 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

  • Fix

🤖 Generated with Claude Code

…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>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/channels/whatsapp.ts Outdated
Comment on lines +345 to +346
const quotedParticipant = contextInfo.participant || '';
if (quotedParticipant) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 59a8cef — falls back to chatJid when contextInfo.participant is empty (DMs), so replyToSenderName is always populated when quoted content exists.

Comment thread src/channels/whatsapp.ts Outdated
Comment on lines +333 to +334
if (contextInfo?.stanzaId && contextInfo?.quotedMessage) {
replyToMessageId = contextInfo.stanzaId;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant