Skip to content

feat(feishu): add require_mention config option for group chats - #4591

Closed
Leegenux wants to merge 5 commits into
NousResearch:mainfrom
Leegenux:feishu-require-mention
Closed

feat(feishu): add require_mention config option for group chats#4591
Leegenux wants to merge 5 commits into
NousResearch:mainfrom
Leegenux:feishu-require-mention

Conversation

@Leegenux

@Leegenux Leegenux commented Apr 2, 2026

Copy link
Copy Markdown

Summary

Adds a require_mention config option for Feishu/Lark group chats, allowing users to control whether @mention is required for the bot to respond.

Changes

  • Add require_mention field to FeishuAdapterSettings dataclass
  • Add FEISHU_REQUIRE_MENTION environment variable (default: true)
  • Add feishu.require_mention config.yaml option (mapped to env var)
  • Update _should_accept_group_message() to respect the setting

Usage

Users can disable @mention requirement via:

# ~/.hermes/config.yaml
feishu:
  require_mention: false  # Respond to all group messages without @mention

Or via environment variable:

export FEISHU_REQUIRE_MENTION=false

Behavior

  • require_mention=true (default): Only respond when bot is @mentioned or @_all
  • require_mention=false: Respond to all allowed group messages

This matches the existing Discord require_mention pattern for consistency.

Add feishu.require_mention config option (default: true) to control
whether @mention is required for bot to respond in group chats.

Previously, group_policy="open" would bypass @mention check, but this
was hardcoded behavior. Now users can configure this independently:

- require_mention=true (default): Only respond when bot is @mentioned or @_all
- require_mention=false: Respond to all allowed group messages without @mention

Configuration via config.yaml:
  feishu:
    require_mention: false

Or via environment variable:
  FEISHU_REQUIRE_MENTION=false

This matches the pattern used by Discord's require_mention setting.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 2, 2026 13:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a Feishu/Lark configuration switch to control whether the bot requires an @mention to respond in group chats, aligning the behavior with other gateway adapters that support mention-gating.

Changes:

  • Add require_mention to Feishu adapter settings and apply it during adapter initialization.
  • Bridge feishu.require_mention from config.yaml into FEISHU_REQUIRE_MENTION (env var takes precedence).
  • Update Feishu group-message routing gate to respect require_mention (defaulting to enabled).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
hermes_cli/config.py Adds a default feishu.require_mention: True entry to the generated/example config.
gateway/platforms/feishu.py Introduces require_mention setting and uses it to bypass mention checks when disabled.
gateway/config.py Maps config.yaml feishu.require_mention to FEISHU_REQUIRE_MENTION when the env var isn’t set.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 1021 to 1025
str(extra.get("webhook_path") or os.getenv("FEISHU_WEBHOOK_PATH", _DEFAULT_WEBHOOK_PATH)).strip()
or _DEFAULT_WEBHOOK_PATH
),
require_mention=os.getenv("FEISHU_REQUIRE_MENTION", "true").strip().lower() not in ("false", "0", "no"),
)

Copilot AI Apr 2, 2026

Copy link

Choose a reason for hiding this comment

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

require_mention is currently only read from FEISHU_REQUIRE_MENTION. Since _load_settings() already accepts extra (and other Feishu settings like app_id, connection_mode, webhook_* can be configured via config.extra / gateway.json), it would be more consistent to also honor extra.get("require_mention") when present (e.g., bool or truthy/falsey string) and fall back to the env var otherwise. As-is, platforms.feishu.extra.require_mention (including values bridged into PlatformConfig.extra) has no effect.

Copilot uses AI. Check for mistakes.
Comment on lines 2677 to +2681
if not self._allow_group_message(sender_id):
return False
# If require_mention is disabled, accept all allowed group messages
if not self._require_mention:
return True

Copilot AI Apr 2, 2026

Copy link

Choose a reason for hiding this comment

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

There are existing unit tests for _should_accept_group_message() in tests/gateway/test_feishu.py, but none currently cover the new require_mention=false behavior. Please add a test case asserting that when FEISHU_REQUIRE_MENTION=false (and group policy allows the sender), a group message without mentions is accepted, and that the default behavior remains unchanged when the env var is unset.

Copilot uses AI. Check for mistakes.
- Allow require_mention from extra.get() (platforms.feishu.extra) with env var fallback
- Add TestRequireMentionDisabled test class covering:
  - require_mention=false accepts messages without @mention
  - require_mention=true requires @mention (default)
  - Default behavior when env var unset
  - Allowlist policy still respected when require_mention=false

Addresses Copilot PR NousResearch#4591 review comments.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread gateway/platforms/feishu.py Outdated
Comment on lines +1024 to +1027
require_mention=(
str(extra.get("require_mention") or os.getenv("FEISHU_REQUIRE_MENTION", "true")).strip().lower()
not in ("false", "0", "no")
),

Copilot AI Apr 2, 2026

Copy link

Choose a reason for hiding this comment

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

Bug: extra.get("require_mention") or os.getenv(...) treats False / 0 / empty values from extra as “not provided” and falls back to the env var/default. This makes it impossible to disable mention gating via PlatformConfig.extra (and via platforms.feishu.extra.require_mention config paths) unless an env var is also set. Use an explicit is not None / key-exists check (similar to telegram._telegram_require_mention) before falling back to the env var.

Copilot uses AI. Check for mistakes.
Comment on lines +2485 to +2493
def test_group_message_accepted_without_mention_when_require_mention_false(self):
"""When require_mention=false, group messages are accepted without @mention."""
from gateway.config import PlatformConfig
from gateway.platforms.feishu import FeishuAdapter

adapter = FeishuAdapter(PlatformConfig())
message = SimpleNamespace(content='{"text":"hello"}', mentions=[])
sender_id = SimpleNamespace(open_id="ou_any", user_id=None)
self.assertTrue(adapter._should_accept_group_message(message, sender_id))

Copilot AI Apr 2, 2026

Copy link

Choose a reason for hiding this comment

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

Test coverage gap: the new behavior is only tested via FEISHU_REQUIRE_MENTION env var. Since _load_settings() also reads config.extra["require_mention"], add a test that sets PlatformConfig(extra={"require_mention": False}) (with FEISHU_REQUIRE_MENTION unset) to ensure the adapter honors an explicit False value from config and doesn’t regress due to falsy or fallbacks.

Copilot uses AI. Check for mistakes.
Use explicit None check instead of 'or' fallback to correctly handle
require_mention=False from PlatformConfig.extra. Previously the 'or'
operator treated False/0/empty string as 'not provided' and fell back
to env var, making it impossible to disable mention gating via config.

- Add _resolve_require_mention() helper with explicit None check
- Add tests for require_mention via PlatformConfig.extra (True/False)
- Add test for extra precedence over env var when explicitly False

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread gateway/platforms/feishu.py Outdated
Comment thread gateway/platforms/feishu.py Outdated
Leegenux and others added 2 commits April 2, 2026 21:51
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Leegenux pushed a commit to Leegenux/hermes-agent that referenced this pull request Apr 5, 2026
- Allow require_mention from extra.get() (platforms.feishu.extra) with env var fallback
- Add TestRequireMentionDisabled test class covering:
  - require_mention=false accepts messages without @mention
  - require_mention=true requires @mention (default)
  - Default behavior when env var unset
  - Allowlist policy still respected when require_mention=false

Addresses Copilot PR NousResearch#4591 review comments.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Leegenux pushed a commit to Leegenux/hermes-agent that referenced this pull request Apr 5, 2026
- Allow require_mention from extra.get() (platforms.feishu.extra) with env var fallback
- Add TestRequireMentionDisabled test class covering:
  - require_mention=false accepts messages without @mention
  - require_mention=true requires @mention (default)
  - Default behavior when env var unset
  - Allowlist policy still respected when require_mention=false

Addresses Copilot PR NousResearch#4591 review comments.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Leegenux pushed a commit to Leegenux/hermes-agent that referenced this pull request Apr 10, 2026
- Allow require_mention from extra.get() (platforms.feishu.extra) with env var fallback
- Add TestRequireMentionDisabled test class covering:
  - require_mention=false accepts messages without @mention
  - require_mention=true requires @mention (default)
  - Default behavior when env var unset
  - Allowlist policy still respected when require_mention=false

Addresses Copilot PR NousResearch#4591 review comments.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/gateway Gateway runner, session dispatch, delivery platform/feishu Feishu / Lark adapter duplicate This issue or pull request already exists labels May 1, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #12887 (and #15058, #5219, #7546) — same feature: require_mention config toggle for Feishu group chats.

1 similar comment
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #12887 (and #15058, #5219, #7546) — same feature: require_mention config toggle for Feishu group chats.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the Feishu configuration work. This is an automated hermes-sweeper review; current main already provides this behavior, including a more granular per-chat form.

  • plugins/platforms/feishu/adapter.py:1600 resolves require_mention from platform config or FEISHU_REQUIRE_MENTION (defaulting to true), and :4274 enforces it in the active group-admission path.
  • gateway/config.py:1182 bridges feishu.require_mention into the platform configuration consumed by that adapter.
  • tests/gateway/test_feishu_bot_admission.py:100 covers default/env/config resolution, and the admission matrix includes an unmentioned group message accepted when require_mention is false.
  • The fuller implementation landed in b94cb8e2c4e (feat(feishu): operator-configurable bot admission and mention policy) and shipped in v2026.5.7.
  • The member discussion also identified this as overlapping Feishu mention-toggle work.

@teknium1 teknium1 closed this Jul 12, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists P3 Low — cosmetic, nice to have platform/feishu Feishu / Lark adapter sweeper:implemented-on-main Sweeper: behavior already present on current main type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants