feat(gateway/feishu): skip @mention gate for small groups with configurable require_mention - #8169
Open
songlairui wants to merge 1 commit into
Open
Conversation
…quire_mention Add three-tier @mention bypass for Feishu group chats: 1. Per-group config: `require_mention: false` in `group_rules.<chat_id>` overrides everything for that specific chat. 2. Global config: `FEISHU_REQUIRE_MENTION=false` env var (or `require_mention: false` in platform extra config) disables the gate across all groups. 3. Auto-detection: if the Feishu API reports `member_count <= 2` (one human + the bot), the channel behaves like a DM and the @mention requirement is skipped automatically. Priority: per-group > global env/config > auto-detect > default (true). When a user @mentions the bot in a small group while auto-detection is active, the message still passes through exactly once — the member_count branch short-circuits before the mention check, so there is no risk of duplicate processing. `get_chat_info()` now extracts and caches `member_count` from the `im.v1.chat.get` API response. The field is pre-fetched (with cache) inside `_handle_message_event_data` for group messages and forwarded to `_should_accept_group_message()` via a keyword arg. Tests: 10 new cases covering global flag, per-group override in both directions, member_count thresholds, the no-duplicate guarantee, and `get_chat_info` member_count extraction/omission.
Collaborator
Contributor
|
Thanks for the small-group usability proposal. The global and per-chat controls in this PR are already present on current main via Problems
Suggested changes
Automated hermes-sweeper review. |
1 task
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.
What does this PR do?
Feishu group chats where only one human and the bot are present should behave like a DM — requiring an explicit @mention before every message is unnecessary friction. This PR adds a three-tier mention-gate bypass for the Feishu adapter.
Related Issue
Type of Change
Changes Made
gateway/platforms/feishu.pyFeishuGroupRule: addrequire_mention: Optional[bool] = None— per-group override,Noneinherits globalFeishuAdapterSettings: addrequire_mention: bool = True— global default_load_settings(): parseFEISHU_REQUIRE_MENTIONenv var and per-grouprequire_mentionkey from config_apply_settings(): storeself._require_mentionget_chat_info(): extract and cachemember_countfromim.v1.chat.getAPI response_handle_message_event_data(): pre-fetchchat_info(cached) for group messages to obtainmember_count_should_accept_group_message(): newmember_countparameter + three-tier logictests/gateway/test_feishu.pyTestRequireMentionConfigMention Gate Priority (highest wins)
group_rules.<chat_id>.require_mention: false/trueFEISHU_REQUIRE_MENTION=falseenv var (or config key)member_count <= 2auto-detectionNo Duplicate Replies
When
member_count <= 2and the user also @mentions the bot explicitly, the small-group branch short-circuits and returnsTrueimmediately — the @mention check is never reached. Combined with the existing_is_duplicate(message_id)dedup, each message is processed exactly once regardless.How to Test
Config flag (manual):
Auto-detection: Add the Feishu bot to a group with only yourself. Send a message without @mentioning it — it should respond.
Unit tests:
Checklist
Code
pytest tests/gateway/test_feishu.py -qand all relevant tests passDocumentation & Housekeeping
cli-config.yaml.examplehas no Feishu section; env var is documented in the commit message and PR body)cli-config.yaml.example— N/A (no Feishu config exists in the example file)CONTRIBUTING.mdorAGENTS.md— N/ANotes
One pre-existing test failure unrelated to this PR:
TestAdapterBehavior::test_build_event_handler_registers_reaction_and_card_processors— fails due to alark_oapiSDK version mismatch ('_Builder' object has no attribute 'register_p2_im_chat_member_bot_added_v1'). This failure exists onmainbefore this PR.