Skip to content

fix(feishu): preserve sender identity and resolve mentions in merge_forward messages#39001

Open
xiaoxinpan wants to merge 1 commit intoopenclaw:mainfrom
xiaoxinpan:fix/feishu-merge-forward-sender-mentions
Open

fix(feishu): preserve sender identity and resolve mentions in merge_forward messages#39001
xiaoxinpan wants to merge 1 commit intoopenclaw:mainfrom
xiaoxinpan:fix/feishu-merge-forward-sender-mentions

Conversation

@xiaoxinpan
Copy link
Copy Markdown

Summary

When users forward merged chat messages (合并转发) to a Feishu bot, the formatted output currently loses two critical pieces of information:

  1. Sender identity — each sub-message's sender.id (open_id) is available in the API response but discarded during formatting
  2. @mention resolution — Feishu replaces real user references with @_user_N placeholders in forwarded content, but the API provides a mentions array on each item that maps these placeholders back to real names and IDs

Before

[Merged and Forwarded Messages]
- 这个方案可行吗?
- @_user_1 @_user_2 帮忙看一下
- 我觉得没问题,可以推进

After

[Merged and Forwarded Messages]
- [ou_aaa111] 这个方案可行吗?
- [ou_bbb222] @张三(ou_ccc333) @李四(ou_ddd444) 帮忙看一下
- [ou_eee555] 我觉得没问题,可以推进

Changes

extensions/feishu/src/bot.tsparseMergeForwardContent()

  • Added mentions to the item type definition (the Feishu im.message.get API already returns this field, it was just not declared)
  • Prepend [sender.id] to each sub-message line
  • Resolve @_user_N placeholders using each item's mentions array, displaying as @name(open_id)

How it works

The Feishu API (/im/v1/messages/:message_id) returns merge_forward items with this structure:

{
  "sender": { "id": "ou_aaa111" },
  "mentions": [
    { "key": "@_user_1", "id": "ou_ccc333", "name": "张三" },
    { "key": "@_user_2", "id": "ou_ddd444", "name": "李四" }
  ],
  "body": { "content": "..." },
  "msg_type": "text"
}

The mentions array maps each @_user_N placeholder back to the real user. This PR uses that mapping to restore the original user references.

Test plan

  • Tested with real Feishu merge_forward messages containing @mentions — placeholders correctly resolved to @name(open_id)
  • Tested with merge_forward messages without @mentions — no regression, sender ID still shown
  • Verified mentions field structure via debug logging against live Feishu API responses

🤖 Generated with Claude Code

@openclaw-barnacle openclaw-barnacle Bot added channel: feishu Channel integration: feishu size: XS labels Mar 7, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Mar 7, 2026

Greptile Summary

This PR enhances the Feishu merge-forward message formatter by prepending each sub-message line with its sender's open_id and resolving @_user_N mention placeholders back to real names via the mentions array already present in the Feishu API response. The overall approach is sound and the added type declaration matches the documented API shape.

Issues found:

  • Mention-replacement ordering bug (logic): Using replaceAll(m.key, …) with a plain string on an unordered list of keys means a shorter key like @_user_1 will partially replace the longer key @_user_10, leaving stray digits and mis-resolving the second mention. This is reproducible any time a single sub-message mentions 10+ distinct users. The fix is to sort item.mentions by key.length descending before iterating, so longer tokens are replaced first.

Confidence Score: 3/5

  • Safe to merge for the common case, but contains a logic bug that produces incorrect output for merge-forward messages with 10+ distinct mentions.
  • The change is small and well-scoped. The sender-ID prepend works correctly. The mention-resolution logic is almost right but has a key-prefix collision bug: replaceAll('@_user_1', …) on a string that also contains @_user_10 will corrupt the longer token. This is an edge case (requires ≥10 unique mentions in a single sub-message) but is a real logical error worth fixing before merge.
  • extensions/feishu/src/bot.ts — the mention-replacement loop (lines 416–420)

Last reviewed commit: a3a2ba4

Comment thread extensions/feishu/src/bot.ts Outdated
Copy link
Copy Markdown

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

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: a3a2ba4174

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread extensions/feishu/src/bot.ts Outdated
@xiaoxinpan xiaoxinpan force-pushed the fix/feishu-merge-forward-sender-mentions branch from efabb23 to 5f27a4f Compare March 7, 2026 16:53
Copy link
Copy Markdown

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

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: 5f27a4f915

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread extensions/feishu/src/bot.ts Outdated
@xiaoxinpan xiaoxinpan force-pushed the fix/feishu-merge-forward-sender-mentions branch from de9d3c6 to 0ad05ef Compare March 7, 2026 18:12
@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: S and removed size: XS labels Mar 7, 2026
@xiaoxinpan xiaoxinpan force-pushed the fix/feishu-merge-forward-sender-mentions branch from 6297723 to 4f91d64 Compare March 7, 2026 18:44
@openclaw-barnacle openclaw-barnacle Bot added size: XS and removed commands Command implementations size: S labels Mar 7, 2026
@xiaoxinpan xiaoxinpan force-pushed the fix/feishu-merge-forward-sender-mentions branch 4 times, most recently from de16aa0 to 4fbbce1 Compare March 14, 2026 02:52
Copy link
Copy Markdown

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

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: 4fbbce1815

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread extensions/feishu/src/bot.ts Outdated
@xiaoxinpan xiaoxinpan force-pushed the fix/feishu-merge-forward-sender-mentions branch from 4fbbce1 to dd72cb5 Compare March 21, 2026 06:38
@xiaoxinpan
Copy link
Copy Markdown
Author

xiaoxinpan commented Mar 21, 2026

Rebased onto latest main (1e98dbc) — single commit: 7e45868.

What changed:

  • Each sub-message line now includes the sender's open_id: - [ou_xxx] message text
  • @_user_N mention placeholders resolved to real names via mentions array
  • Mentions sorted by key length descending to prevent @_user_1/@_user_10 collision
  • m.id normalized for string and object shapes (with union_id fallback)
  • Uses callback replacement to avoid $ substitution in mention names

All previous review feedback has been incorporated. The remaining bot review comments above are outdated — they reference the old code structure (before upstream extracted bot-content.ts from bot.ts).

@xiaoxinpan xiaoxinpan force-pushed the fix/feishu-merge-forward-sender-mentions branch from dd72cb5 to d0fb87f Compare March 21, 2026 06:45
Copy link
Copy Markdown

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

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: d0fb87fe01

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread extensions/feishu/src/bot-content.ts Outdated
@xiaoxinpan xiaoxinpan force-pushed the fix/feishu-merge-forward-sender-mentions branch from 7f40ea2 to 7e45868 Compare March 22, 2026 03:31
@openclaw-barnacle
Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Apr 23, 2026
@clawsweeper
Copy link
Copy Markdown
Contributor

clawsweeper Bot commented Apr 26, 2026

Codex review: needs real behavior proof before merge.

Summary
The PR updates the Feishu merge_forward formatter to prepend sub-message sender IDs, resolve item-level mention placeholders, and adjust the merge_forward test expectation.

Reproducibility: yes. from source and fixture inspection rather than a live Feishu account. Current main fetches merge_forward sub-messages but formats only body text, and the existing test asserts that old transcript shape.

Real behavior proof
Needs stronger real behavior proof before merge: The body says real Feishu merge_forward messages were tested, but it does not include after-fix live output, logs, screenshots, or linked artifacts showing the fixed transcript.

Next step before merge
Contributor or maintainer action is needed because external real behavior proof is missing and automation cannot supply it for the contributor's Feishu setup.

Security
Cleared: The diff is limited to Feishu message parsing and tests, with no dependency, workflow, permission, secret-handling, generated-code, or package-execution changes.

Review findings

  • [P2] Add the required changelog entry — extensions/feishu/src/bot-content.ts:246
Review details

Best possible solution:

Land a completed Feishu plugin-local formatter fix with a changelog entry, real Feishu output proof, and regression coverage for sender prefixes plus mention replacement; no core change is needed.

Do we have a high-confidence way to reproduce the issue?

Yes, from source and fixture inspection rather than a live Feishu account. Current main fetches merge_forward sub-messages but formats only body text, and the existing test asserts that old transcript shape.

Is this the best way to solve the issue?

Yes. The Feishu formatter is the narrowest maintainable place to preserve sender and mention identity, but the PR needs the changelog/proof gaps closed before merge.

Full review comments:

  • [P2] Add the required changelog entry — extensions/feishu/src/bot-content.ts:246
    This changes user-visible Feishu merge_forward transcripts, but the PR head does not add a CHANGELOG.md entry. OpenClaw policy requires user-facing fixes to be recorded under the active Fixes section before merge.
    Confidence: 0.92

Overall correctness: patch is incorrect
Overall confidence: 0.87

Acceptance criteria:

  • pnpm test extensions/feishu/src/bot.test.ts
  • pnpm check:changed

What I checked:

  • Current main omits requested data: parseMergeForwardContent currently types sender.id but not item-level mentions, then emits only the formatted sub-message body without a sender prefix or mention replacement. (extensions/feishu/src/bot-content.ts:212, 121ac44fa8f5)
  • Runtime path uses this formatter: handleFeishuMessage fetches merge_forward items through im.message.get and passes response.data.items into parseMergeForwardContent for the agent-visible content. (extensions/feishu/src/bot.ts:431, 121ac44fa8f5)
  • Existing test confirms old transcript shape: The current merge_forward test fixture expects '- alpha' and '- [File: report.pdf]' without sender prefixes or mention-resolution coverage. (extensions/feishu/src/bot.test.ts:1885, 121ac44fa8f5)
  • PR head addresses parser behavior: The PR head adds item-level mentions, sender prefixes, descending-length mention replacement, object/string/union_id ID normalization, and functional replacement. (extensions/feishu/src/bot-content.ts:246, d353baafbd0f)
  • Changelog entry missing: The PR head's active Unreleased Fixes section has no Feishu merge_forward sender/mention entry for this user-facing fix. (CHANGELOG.md:69, d353baafbd0f)
  • Prior review feedback incorporated: The discussion flagged prefix collisions, object mention IDs, union_id fallback, and $ replacement handling; the latest PR head includes fixes for those points. (extensions/feishu/src/bot-content.ts:253, d353baafbd0f)

Likely related people:

  • tsu-builds: Merged PR feat(feishu): add support for merge_forward message parsing #28707 introduced the Feishu merge_forward fetch/format path and associated tests that this PR extends. (role: introduced behavior; confidence: high; commits: f53ef73a2b24; files: extensions/feishu/src/bot.ts, extensions/feishu/src/bot.test.ts, extensions/feishu/src/bot-content.ts)
  • m1heng: Feishu package metadata names @m1heng as community maintainer, and the PR timeline pulled m1heng into Feishu review context. (role: community maintainer / likely domain owner; confidence: medium; files: extensions/feishu/package.json, extensions/feishu/src/bot.ts, extensions/feishu/src/bot-content.ts)

Remaining risk / open question:

  • The PR body asserts live Feishu testing, but it does not attach copied live output, redacted logs, screenshots, or linked artifacts showing the after-fix transcript.
  • The updated test covers sender prefixes but not mention-placeholder resolution edge cases such as key-prefix collisions, object IDs, union_id fallback, or literal $ in names.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 121ac44fa8f5.

@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Apr 26, 2026
…orward messages

Prepend each sub-message with its sender open_id and resolve @_user_N
mention placeholders back to real names via the mentions array in the
Feishu API response.

- Sort mentions by key length descending to prevent partial-match
  collisions (e.g. @_user_1 matching @_user_10)
- Normalize mention IDs for both string and object shapes, with
  union_id fallback
- Use callback replacement to avoid $ substitution in display names

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@xiaoxinpan xiaoxinpan force-pushed the fix/feishu-merge-forward-sender-mentions branch from 7e45868 to d353baa Compare May 5, 2026 07:15
@openclaw-barnacle openclaw-barnacle Bot added triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. triage: refactor-only Candidate: refactor/cleanup-only PR without maintainer context. labels May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: feishu Channel integration: feishu size: XS triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. triage: refactor-only Candidate: refactor/cleanup-only PR without maintainer context.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant