Skip to content

fix(feishu): strip bot mention in group context so slash commands are recognized#36016

Merged
Takhoffman merged 1 commit intoopenclaw:mainfrom
Sid-Qin:fix/feishu-group-slash-commands-35994
Mar 5, 2026
Merged

fix(feishu): strip bot mention in group context so slash commands are recognized#36016
Takhoffman merged 1 commit intoopenclaw:mainfrom
Sid-Qin:fix/feishu-group-slash-commands-35994

Conversation

@Sid-Qin
Copy link
Contributor

@Sid-Qin Sid-Qin commented Mar 5, 2026

Summary

  • Problem: Slash commands (/model, /reset, /new) in Feishu group chats are not intercepted by the Gateway command parser. Commands are passed to the agent as regular messages.
  • Why it matters: Any Feishu group using @Bot /command is unable to use system commands, forcing manual workarounds or DM-only command usage.
  • What changed: parseFeishuMessageEvent now strips the bot's own mention in both p2p and group contexts (previously p2p only). The mentionedBot boolean already captures whether the bot was addressed, so the mention tag in content only served to break command detection.
  • What did NOT change (scope boundary): Non-bot mentions are still normalized to <at> tags. Mention-forward detection, requireMention gating, and agent routing are unaffected.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

User-visible / Behavior Changes

  • @Bot /model, @Bot /reset, @Bot /new now work in Feishu group chats (previously silently passed to agent as text).

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • OS: macOS / Linux
  • Runtime: Node.js 22+

Steps

  1. Configure Feishu channel with commands.text: true
  2. Add bot to a Feishu group chat
  3. Send @Bot /model in the group

Expected

  • Command intercepted by Gateway, model info returned

Actual

  • Before: Command passed to agent as regular text
  • After: Command correctly intercepted and processed

Evidence

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

  • Verified scenarios: p2p mention strip (unchanged), group mention strip (new), group slash command detection, multi-mention normalization
  • Edge cases checked: mention-forward with bot + other user, regex metacharacters in mention keys, dollar signs in display names
  • What you did not verify: Live Feishu API integration (tested via unit tests with mock events)

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Failure Recovery (if this breaks)

  • How to disable/revert: Revert the single-line change in parseFeishuMessageEvent to restore event.message.chat_type === "p2p" ? botOpenId : undefined
  • Files/config to restore: extensions/feishu/src/bot.ts

Risks and Mitigations

  • Risk: Group messages that previously included the bot mention in agent context will no longer include it.
    • Mitigation: The mentionedBot flag and hasAnyMention field already provide this information to downstream consumers. The mention tag was redundant noise in the agent body.

… recognized

In group chats, @bot /model was normalized to <at user_id="...">Bot</at> /model,
which hasControlCommand() did not recognize as a slash command. The bot mention
is now stripped in both p2p and group contexts; the mentionedBot flag already
captures whether the bot was addressed.

Closes openclaw#35994

Made-with: Cursor
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 5, 2026

Greptile Summary

This PR fixes a bug where slash commands (/model, /reset, /new) prefixed with a bot mention (e.g. @Bot /model) were not recognized in Feishu group chats. The root cause was that parseFeishuMessageEvent only stripped the bot's own @mention from message content in p2p (direct-message) contexts; in group contexts the mention was preserved as an <at user_id="..."> tag, which prevented the Gateway command parser from seeing a leading /.

Change summary:

  • extensions/feishu/src/bot.ts: Remove the chat_type === "p2p" conditional so botOpenId is always forwarded to normalizeMentions, stripping the bot mention in both p2p and group contexts. The mentionedBot flag and hasAnyMention field still capture whether the bot was addressed.
  • extensions/feishu/src/bot.stripBotMention.test.ts: Update the existing group-mention test to match the new expected output ("hello" instead of '<at user_id="ou_bot">Bot</at> hello'), and add a dedicated test for the @Bot /model/model slash-command scenario.

The change is minimal, backward-compatible, and well-covered by the updated tests. No issues found.

Confidence Score: 5/5

  • This PR is safe to merge — it is a minimal, targeted bug fix with comprehensive test coverage and no side effects on other code paths.
  • The change is a single-line diff that removes an unnecessary conditional. The fix is logically sound: mentionedBot/hasAnyMention already record addressing intent, so stripping the bot mention from content in group chats is the correct behavior. All pre-existing tests still pass, and two new tests explicitly cover the group-mention stripping and slash-command recognition scenarios. No security, auth, or network behavior is affected.
  • No files require special attention.

Last reviewed commit: 5e9deee

Copy link

@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: 5e9deee2cb

ℹ️ 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".

event.message.mentions,
event.message.chat_type === "p2p" ? botOpenId : undefined,
);
const content = normalizeMentions(rawContent, event.message.mentions, botOpenId);

Choose a reason for hiding this comment

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

P1 Badge Gate bot-mention stripping on confirmed bot mention

parseFeishuMessageEvent now strips mentions using only botOpenId (normalizeMentions(..., botOpenId)), but checkBotMentioned explicitly guards against Feishu WS open_id remapping by requiring matching botName in multi-app groups. In that remapping scenario, mentionedBot is correctly false while this line still removes the mention text, so a message like @OtherBot /reset can be transformed into /reset and handled as our command when mention-gating is disabled (or at least loses intended context). The strip should be conditioned on a confirmed self-mention, not open_id alone.

Useful? React with 👍 / 👎.

@Takhoffman Takhoffman merged commit 995ae73 into openclaw:main Mar 5, 2026
32 checks passed
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Feishu group chat slash commands still not recognized in 2026.3.2 (regression from #10965)

2 participants