Skip to content

fix: pass ref_msg content as structured ReplyTo fields for inbound_meta - #223

Open
ralf003 wants to merge 1 commit into
Tencent:mainfrom
ralf003:fix/ref-msg-inbound-meta
Open

ralf003 wants to merge 1 commit into
Tencent:mainfrom
ralf003:fix/ref-msg-inbound-meta

Conversation

@ralf003

@ralf003 ralf003 commented Jul 11, 2026

Copy link
Copy Markdown

Summary

When a user sends a message that quotes another message (ref_msg), the plugin previously only prepended the quoted content as [引用: ...] prefix in the Body text. This meant the quoted content did not appear in the framework's structured inbound_meta (untrusted reply target block) that buildInboundUserContextPrefix() generates from ReplyToBody / ReplyToId fields.

Root Cause

The weixinMessageToMsgContext() function extracted ref_msg content solely into the Body text prefix. The OpenClaw core framework uses MsgContext fields like ReplyToBody, ReplyToId, ReplyToSender, ReplyToIsQuote to include the quoted message as a structured "Reply target of current user message (untrusted, for context)" block in the agent's inbound_meta. These fields were never populated by the weixin plugin.

Changes

  • Add ReplyToBody, ReplyToId, ReplyToSender, ReplyToIsQuote fields to WeixinMsgContext type
  • Extract ref_msg content and populate these fields in weixinMessageToMsgContext() so the framework includes the quoted message in the untrusted reply target metadata block
  • Refactor: extract extractRefBody() helper from bodyFromItemList() to eliminate duplicated ref_msg content extraction logic

Verification

  • npm run build — clean
  • npm test — 396/397 pass (1 pre-existing Windows path separator issue in state-dir.test.ts)
  • Inbound tests (src/messaging/inbound.test.ts) — all 25 pass
  • TypeScript: tsc --noEmit — clean

Closes #222

fixes Tencent#222)

Squashed from two commits:
- 3359efd fix: pass ref_msg content as structured ReplyTo fields for inbound_meta
- 5d9361a fix: use quoted message_id for ReplyToId, exclude title from ReplyToBody

Three fixes:
1. ReplyToId uses quoted message_id (not item's own ID)
2. ReplyToBody excludes title (title goes to ReplyToSender independently)
3. Media refs (IMAGE/VIDEO/FILE/VOICE) skip ReplyToBody

Refactored extractRefBody() and findRefMsg() to eliminate duplication.
Added 5 boundary tests for ReplyTo fields.

Reviewed-by: Dennis (tech), Bishop (QA)
@ralf003
ralf003 force-pushed the fix/ref-msg-inbound-meta branch from 5d9361a to c412e60 Compare July 11, 2026 17:13
@NewFuture

Copy link
Copy Markdown

The current community-maintained openclaw-weixin v3.0.1 has partial overlap with this PR, but this PR has not been fully ported:

https://github.com/NewFuture/openclaw-weixin

Currently released behavior preserves quoted text in the message body using the [引用: ...] prefix (including voice STT quote handling). However, it does not populate the structured ReplyToBody, ReplyToId, ReplyToSender, or ReplyToIsQuote fields requested here. Therefore structured inbound_meta support remains outstanding, and this PR is still valuable.

For users who only need the existing body-level quote support, the community package can be installed/replaced in place (requires OpenClaw >=2026.6.1; do not uninstall the official package first):

openclaw plugins install npm:openclaw-weixin --force

The plugin/channel ID and state paths are unchanged, so this normally preserves existing configuration and login state.

For clarity: the linked repository/package is a community-maintained distribution, not the official Tencent/Weixin release. This upstream Tencent PR is still open, and this comment does not claim that its structured metadata change has been merged.

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.

[Bug] ref_msg(引用消息)内容未传递到 OpenClaw inbound_meta

2 participants