fix(lark): recognize commands after leading bot mention - #9872
Open
Ars1027 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #9848
Problem
In Lark group chats, a message sent as
@bot /stopkeeps the leading bot mention inmessage_str. The mention wakes the bot, but wake-prefix and command matching still receive text such as@Bot /stop, so built-in and plugin commands are not recognized. An active Agent may then capture the message as a follow-up instead of stopping.Solution
Normalize the textual projection in the Lark adapter. When the first parsed component is an
Attargeting the bot, omit that component frommessage_strwhile preserving it in the structured message chain.The bot OpenID is the primary identity. The display name is used only when the mention has no identifier. Keeping this normalization in the platform adapter avoids changing shared wake or command behavior for other platforms.
Changes
Extend
_build_message_str_from_components()with optional bot identity parameters while preserving its default behavior.Remove only a leading bot-self mention from Lark's textual message projection.
Preserve non-self mentions, non-leading mentions, structured
Atcomponents, and existing callers.Add regression tests for built-in commands, plugin commands, natural-language messages, missing mention IDs, same-name users with different OpenIDs, empty input, and backward compatibility.
No public API changes or new dependencies.
This is NOT a breaking change.
Testing
Automated checks completed locally:
ruff format .ruff check .python -m py_compile astrbot/core/platform/sources/lark/lark_adapter.py tests/test_lark_adapter.pygit diff --checkThe added pytest coverage exercises:
@bot /stop->/stop@bot /plugin_command->/plugin_command@bot hello->helloManual end-to-end verification was completed on AstrBot v4.27.4 in Ubuntu Docker:
@bot /helpinvoked the built-in help handler.@bot /stopstopped an active Agent run.@bot <natural language>continued through the normal LLM path./helpremained functional.Sanitized runtime evidence:
Notes for Reviewer
Atcomponent is intentionally preserved; onlymessage_stris normalized.Checklist / 检查清单
Summary by Sourcery
Fix Lark command recognition by normalizing leading bot mentions in message text without altering the structured message chain.
Bug Fixes:
Enhancements:
Tests: