feat(slack): add require_mention and free_response_channels config support#5885
feat(slack): add require_mention and free_response_channels config support#5885dorukardahan wants to merge 3 commits into
Conversation
…pport
Port the mention gating pattern from Telegram, Discord, WhatsApp, and
Matrix adapters to the Slack platform adapter.
- Add _slack_require_mention() with env var fallback (SLACK_REQUIRE_MENTION)
- Add _slack_free_response_channels() with env var fallback (SLACK_FREE_RESPONSE_CHANNELS)
- Replace hardcoded mention check with configurable gating logic
- Bridge slack config.yaml settings to env vars (matching Discord/Telegram pattern)
- Add 21 tests covering config parsing, env fallback, gating logic, and config bridging
Config usage:
slack:
require_mention: false
free_response_channels:
- "C0AQWDLHY9M"
Default behavior unchanged: channels require @mention (backward compatible).
- Restore bot_uid guard in gating condition to prevent silent message drops when bot_uid is None (startup, new workspace before auth_test) - Switch to explicit-false parser for require_mention (matching Discord/Matrix pattern) so malformed values fail-closed instead of silently disabling mention gating - Add bot_uid=None regression test - Add malformed/empty string parser safety tests - Fix test env var hermiticity (monkeypatch.delenv in default tests) 26 tests pass.
dorukardahan
left a comment
There was a problem hiding this comment.
Self-review notes for maintainers
Key design decisions:
-
bot_uidguard (slack.py:775) — The original code hadif not is_dm and bot_uid and not is_mentioned. I preserved thebot_uidguard (if not is_dm and bot_uid:) because removing it would silently drop channel messages during startup or when a new workspace hasn't completedauth_testyet. This edge case is subtle but important for multi-workspace deployments. -
Explicit-false parser (slack.py:1063) — I used
not in ("false", "0", "no", "off")instead ofin ("true", "1", "yes", "on"). Since Slack defaults torequire_mention=true(gating ON), the parser should fail-closed: unrecognised values like""or"maybe"keep gating enabled. This matches the Discord and Matrix approach. Telegram/WhatsApp use the truthy parser because they default tofalse(gating OFF), where fail-open is the safe default. -
Config bridging — I added both the generic
free_response_channelskey to the platform bridging loop (line 531) AND a Slack-specific env var block (lines 547-556). The generic loop populatesPlatformConfig.extrafor the method-based lookup. The Slack block populates env vars for operators who prefer env-only configuration (Docker, systemd). This mirrors the Discord/Telegram/WhatsApp/Matrix pattern. -
Naming: Used
free_response_channels(notfree_response_chats) to match Discord's convention, since Slack calls them "channels". Telegram/WhatsApp usefree_response_chatsand Matrix usesfree_response_rooms— each adapter uses platform-native terminology.
Integrate free_response_channels and require_mention gating into upstream's expanded thread tracking (bot_message_ts, mentioned_threads). The gating precedence is now: 1. free_response_channels → always process 2. require_mention=false → always process 3. @mentioned → process 4. reply_to_bot_thread → process 5. in_mentioned_thread → process 6. has_active_session → process 7. otherwise → ignore
…pport
Port the mention gating pattern from Telegram, Discord, WhatsApp, and
Matrix adapters to the Slack platform adapter.
- Add _slack_require_mention() with explicit-false parsing and env var
fallback (SLACK_REQUIRE_MENTION)
- Add _slack_free_response_channels() with env var fallback
(SLACK_FREE_RESPONSE_CHANNELS)
- Replace hardcoded mention check with configurable gating logic
- Bridge slack config.yaml settings to env vars
- Bridge free_response_channels through the generic platform bridging loop
- Add 26 tests covering config parsing, env fallback, gating logic
Config usage:
slack:
require_mention: false
free_response_channels:
- "C0AQWDLHY9M"
Default behavior unchanged: channels require @mention (backward compatible).
Based on PR #5885 by dorukardahan, cherry-picked and adapted to current main.
…pport
Port the mention gating pattern from Telegram, Discord, WhatsApp, and
Matrix adapters to the Slack platform adapter.
- Add _slack_require_mention() with explicit-false parsing and env var
fallback (SLACK_REQUIRE_MENTION)
- Add _slack_free_response_channels() with env var fallback
(SLACK_FREE_RESPONSE_CHANNELS)
- Replace hardcoded mention check with configurable gating logic
- Bridge slack config.yaml settings to env vars
- Bridge free_response_channels through the generic platform bridging loop
- Add 26 tests covering config parsing, env fallback, gating logic
Config usage:
slack:
require_mention: false
free_response_channels:
- "C0AQWDLHY9M"
Default behavior unchanged: channels require @mention (backward compatible).
Based on PR #5885 by dorukardahan, cherry-picked and adapted to current main.
|
Merged via PR #6809 as part of a consolidated Slack adapter improvement. Your contribution was core feature (require_mention + free_response_channels) cherry-picked. Your authorship is preserved in git history. Thank you @dorukardahan for your work on this! |
…pport
Port the mention gating pattern from Telegram, Discord, WhatsApp, and
Matrix adapters to the Slack platform adapter.
- Add _slack_require_mention() with explicit-false parsing and env var
fallback (SLACK_REQUIRE_MENTION)
- Add _slack_free_response_channels() with env var fallback
(SLACK_FREE_RESPONSE_CHANNELS)
- Replace hardcoded mention check with configurable gating logic
- Bridge slack config.yaml settings to env vars
- Bridge free_response_channels through the generic platform bridging loop
- Add 26 tests covering config parsing, env fallback, gating logic
Config usage:
slack:
require_mention: false
free_response_channels:
- "C0AQWDLHY9M"
Default behavior unchanged: channels require @mention (backward compatible).
Based on PR NousResearch#5885 by dorukardahan, cherry-picked and adapted to current main.
…pport
Port the mention gating pattern from Telegram, Discord, WhatsApp, and
Matrix adapters to the Slack platform adapter.
- Add _slack_require_mention() with explicit-false parsing and env var
fallback (SLACK_REQUIRE_MENTION)
- Add _slack_free_response_channels() with env var fallback
(SLACK_FREE_RESPONSE_CHANNELS)
- Replace hardcoded mention check with configurable gating logic
- Bridge slack config.yaml settings to env vars
- Bridge free_response_channels through the generic platform bridging loop
- Add 26 tests covering config parsing, env fallback, gating logic
Config usage:
slack:
require_mention: false
free_response_channels:
- "C0AQWDLHY9M"
Default behavior unchanged: channels require @mention (backward compatible).
Based on PR NousResearch#5885 by dorukardahan, cherry-picked and adapted to current main.
…pport
Port the mention gating pattern from Telegram, Discord, WhatsApp, and
Matrix adapters to the Slack platform adapter.
- Add _slack_require_mention() with explicit-false parsing and env var
fallback (SLACK_REQUIRE_MENTION)
- Add _slack_free_response_channels() with env var fallback
(SLACK_FREE_RESPONSE_CHANNELS)
- Replace hardcoded mention check with configurable gating logic
- Bridge slack config.yaml settings to env vars
- Bridge free_response_channels through the generic platform bridging loop
- Add 26 tests covering config parsing, env fallback, gating logic
Config usage:
slack:
require_mention: false
free_response_channels:
- "C0AQWDLHY9M"
Default behavior unchanged: channels require @mention (backward compatible).
Based on PR NousResearch#5885 by dorukardahan, cherry-picked and adapted to current main.
…pport
Port the mention gating pattern from Telegram, Discord, WhatsApp, and
Matrix adapters to the Slack platform adapter.
- Add _slack_require_mention() with explicit-false parsing and env var
fallback (SLACK_REQUIRE_MENTION)
- Add _slack_free_response_channels() with env var fallback
(SLACK_FREE_RESPONSE_CHANNELS)
- Replace hardcoded mention check with configurable gating logic
- Bridge slack config.yaml settings to env vars
- Bridge free_response_channels through the generic platform bridging loop
- Add 26 tests covering config parsing, env fallback, gating logic
Config usage:
slack:
require_mention: false
free_response_channels:
- "C0AQWDLHY9M"
Default behavior unchanged: channels require @mention (backward compatible).
Based on PR NousResearch#5885 by dorukardahan, cherry-picked and adapted to current main.
…pport
Port the mention gating pattern from Telegram, Discord, WhatsApp, and
Matrix adapters to the Slack platform adapter.
- Add _slack_require_mention() with explicit-false parsing and env var
fallback (SLACK_REQUIRE_MENTION)
- Add _slack_free_response_channels() with env var fallback
(SLACK_FREE_RESPONSE_CHANNELS)
- Replace hardcoded mention check with configurable gating logic
- Bridge slack config.yaml settings to env vars
- Bridge free_response_channels through the generic platform bridging loop
- Add 26 tests covering config parsing, env fallback, gating logic
Config usage:
slack:
require_mention: false
free_response_channels:
- "C0AQWDLHY9M"
Default behavior unchanged: channels require @mention (backward compatible).
Based on PR NousResearch#5885 by dorukardahan, cherry-picked and adapted to current main.
…pport
Port the mention gating pattern from Telegram, Discord, WhatsApp, and
Matrix adapters to the Slack platform adapter.
- Add _slack_require_mention() with explicit-false parsing and env var
fallback (SLACK_REQUIRE_MENTION)
- Add _slack_free_response_channels() with env var fallback
(SLACK_FREE_RESPONSE_CHANNELS)
- Replace hardcoded mention check with configurable gating logic
- Bridge slack config.yaml settings to env vars
- Bridge free_response_channels through the generic platform bridging loop
- Add 26 tests covering config parsing, env fallback, gating logic
Config usage:
slack:
require_mention: false
free_response_channels:
- "C0AQWDLHY9M"
Default behavior unchanged: channels require @mention (backward compatible).
Based on PR NousResearch#5885 by dorukardahan, cherry-picked and adapted to current main.
…pport
Port the mention gating pattern from Telegram, Discord, WhatsApp, and
Matrix adapters to the Slack platform adapter.
- Add _slack_require_mention() with explicit-false parsing and env var
fallback (SLACK_REQUIRE_MENTION)
- Add _slack_free_response_channels() with env var fallback
(SLACK_FREE_RESPONSE_CHANNELS)
- Replace hardcoded mention check with configurable gating logic
- Bridge slack config.yaml settings to env vars
- Bridge free_response_channels through the generic platform bridging loop
- Add 26 tests covering config parsing, env fallback, gating logic
Config usage:
slack:
require_mention: false
free_response_channels:
- "C0AQWDLHY9M"
Default behavior unchanged: channels require @mention (backward compatible).
Based on PR NousResearch#5885 by dorukardahan, cherry-picked and adapted to current main.
Summary
require_mentionandfree_response_channelsconfig support with env var fallbacks (SLACK_REQUIRE_MENTION,SLACK_FREE_RESPONSE_CHANNELS)Changes
gateway/platforms/slack.py_slack_require_mention()and_slack_free_response_channels()methods; replace hardcoded mention check with configurable gatinggateway/config.pyfree_response_channelsto generic bridging loop; add Slack-specific env var wiring blocktests/gateway/test_slack_mention.pyConfig usage
Or via env vars:
SLACK_REQUIRE_MENTION=false,SLACK_FREE_RESPONSE_CHANNELS=C0AQWDLHY9M,C9999999999Design decisions
Explicit-false parser (like Discord/Matrix) instead of truthy parser (like Telegram/WhatsApp) — since Slack defaults to
require_mention=true, unrecognised/empty values keep gating ON (fail-closed). This matches Discord and Matrix which also default to require-mention.bot_uidguard preserved — the gating block is only entered whenbot_uidis resolved. This matches the original behavior: messages arriving beforeauth_testcompletes (startup, new workspace) pass through instead of being silently dropped.Env var fallback — follows the same pattern as every other adapter.
SLACK_REQUIRE_MENTIONandSLACK_FREE_RESPONSE_CHANNELSare supported alongside config.yaml.Gating precedence
bot_uidnot yet resolved → always processed (startup safety)free_response_channels→ always processedrequire_mentiondisabled → always processedRelated
Test plan
require_mention=true(default), channel msg without mention → ignoredrequire_mention=false, channel msg without mention → processedfree_response_channels→ processed without mentionSLACK_REQUIRE_MENTION,SLACK_FREE_RESPONSE_CHANNELS) worksbot_uid=None→ messages pass through (no silent drop)Platforms tested