feat(gateway): add require_mention_channels for per-channel mention overrides

Adds a new `require_mention_channels` config key (and corresponding env
vars) across all 7 gateway platforms that have mention-gating. This is
the inverse of `free_response_channels` — channels listed here always
require @mention even when the global `require_mention` setting is false.

Use case: a user runs multiple channels, most with a single agent where
no mention is needed, but a few 'agent group' channels where mentions
make sense to avoid noise. Previously this required require_mention=true
globally and listing every non-group channel in free_response_channels.

Priority logic (highest wins):
1. DMs → always respond
2. Channel in free_response_channels → never require mention
3. Channel in require_mention_channels → always require mention
4. Global require_mention setting → fallback

Also refactors:
- Mattermost: inline os.getenv() → proper helper methods matching
  Discord/Slack pattern, adds config.yaml support via config.extra
- Matrix: cached __init__ vars → helper methods with config.extra
  support
- Mattermost config bridging: adds missing YAML→env bridging in
  gateway/config.py (was completely absent)

New env vars:
- DISCORD_REQUIRE_MENTION_CHANNELS
- SLACK_REQUIRE_MENTION_CHANNELS
- TELEGRAM_REQUIRE_MENTION_CHATS
- WHATSAPP_REQUIRE_MENTION_CHATS
- DINGTALK_REQUIRE_MENTION_CHATS
- MATTERMOST_REQUIRE_MENTION_CHANNELS
- MATRIX_REQUIRE_MENTION_ROOMS

Naming follows each platform's convention (channels/chats/rooms).
Fully backward compatible — empty by default, no behavior change.

Requested by community member neeldhara on PR #3664.
This commit is contained in:
kshitijk4poor 2026-04-22 10:27:46 +05:30
parent ff9752410a
commit d4178e0977
19 changed files with 1000 additions and 23 deletions

View file

@ -1232,11 +1232,13 @@ Configure Discord-specific behavior for the messaging gateway:
```yaml
discord:
require_mention: true # Require @mention to respond in server channels
require_mention_channels: "" # Comma-separated channel IDs where @mention is always required (even when require_mention is false)
free_response_channels: "" # Comma-separated channel IDs where bot responds without @mention
auto_thread: true # Auto-create threads on @mention in channels
```
- `require_mention` — when `true` (default), the bot only responds in server channels when mentioned with `@BotName`. DMs always work without mention.
- `require_mention_channels` — comma-separated list of channel IDs where the bot always requires a mention, even when `require_mention` is `false`. This is the inverse of `free_response_channels` — use it to enforce mention-only behavior in specific noisy channels without changing the server-wide default. Available on all platforms: `require_mention_channels` (Discord, Slack, Mattermost), `require_mention_chats` (Telegram, WhatsApp, DingTalk), `require_mention_rooms` (Matrix).
- `free_response_channels` — comma-separated list of channel IDs where the bot responds to every message without requiring a mention.
- `auto_thread` — when `true` (default), mentions in channels automatically create a thread for the conversation, keeping channels clean (similar to Slack threading).