Skip to content

feat(slack): add require_mention and free_response_channels config support#5885

Closed
dorukardahan wants to merge 3 commits into
NousResearch:mainfrom
dorukardahan:feat/slack-mention-gating
Closed

feat(slack): add require_mention and free_response_channels config support#5885
dorukardahan wants to merge 3 commits into
NousResearch:mainfrom
dorukardahan:feat/slack-mention-gating

Conversation

@dorukardahan

@dorukardahan dorukardahan commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Port the mention gating pattern from Telegram, Discord, WhatsApp, and Matrix adapters to the Slack platform adapter
  • Add require_mention and free_response_channels config support with env var fallbacks (SLACK_REQUIRE_MENTION, SLACK_FREE_RESPONSE_CHANNELS)
  • Default behavior unchanged: channels require @mention (backward compatible)

Changes

File Change
gateway/platforms/slack.py Add _slack_require_mention() and _slack_free_response_channels() methods; replace hardcoded mention check with configurable gating
gateway/config.py Add free_response_channels to generic bridging loop; add Slack-specific env var wiring block
tests/gateway/test_slack_mention.py 26 tests covering config parsing, env var fallback, gating logic, parser safety, bot_uid edge case, and config bridging

Config usage

slack:
  require_mention: false
  # OR allow specific channels without mention:
  free_response_channels:
    - "C0AQWDLHY9M"

Or via env vars: SLACK_REQUIRE_MENTION=false, SLACK_FREE_RESPONSE_CHANNELS=C0AQWDLHY9M,C9999999999

Design decisions

  1. 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.

  2. bot_uid guard preserved — the gating block is only entered when bot_uid is resolved. This matches the original behavior: messages arriving before auth_test completes (startup, new workspace) pass through instead of being silently dropped.

  3. Env var fallback — follows the same pattern as every other adapter. SLACK_REQUIRE_MENTION and SLACK_FREE_RESPONSE_CHANNELS are supported alongside config.yaml.

Gating precedence

  1. DMs → always processed
  2. bot_uid not yet resolved → always processed (startup safety)
  3. Channel in free_response_channels → always processed
  4. require_mention disabled → always processed
  5. Bot @mentioned → processed (mention stripped from text)
  6. Thread reply with active session → processed
  7. Otherwise → ignored

Related

Test plan

  • require_mention=true (default), channel msg without mention → ignored
  • require_mention=false, channel msg without mention → processed
  • Channel in free_response_channels → processed without mention
  • DM always processed regardless of setting
  • Thread reply with active session → processed without mention
  • Env var fallback (SLACK_REQUIRE_MENTION, SLACK_FREE_RESPONSE_CHANNELS) works
  • Config bridging from config.yaml → env vars verified
  • Malformed/empty strings keep gating ON (explicit-false parser safety)
  • bot_uid=None → messages pass through (no silent drop)
  • All 26 tests pass

Platforms tested

  • macOS (Darwin 25.4.0, Python 3.14)

…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 dorukardahan left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Self-review notes for maintainers

Key design decisions:

  1. bot_uid guard (slack.py:775) — The original code had if not is_dm and bot_uid and not is_mentioned. I preserved the bot_uid guard (if not is_dm and bot_uid:) because removing it would silently drop channel messages during startup or when a new workspace hasn't completed auth_test yet. This edge case is subtle but important for multi-workspace deployments.

  2. Explicit-false parser (slack.py:1063) — I used not in ("false", "0", "no", "off") instead of in ("true", "1", "yes", "on"). Since Slack defaults to require_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 to false (gating OFF), where fail-open is the safe default.

  3. Config bridging — I added both the generic free_response_channels key to the platform bridging loop (line 531) AND a Slack-specific env var block (lines 547-556). The generic loop populates PlatformConfig.extra for 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.

  4. Naming: Used free_response_channels (not free_response_chats) to match Discord's convention, since Slack calls them "channels". Telegram/WhatsApp use free_response_chats and Matrix uses free_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
teknium1 pushed a commit that referenced this pull request Apr 9, 2026
…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.
teknium1 pushed a commit that referenced this pull request Apr 9, 2026
…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.
@teknium1

teknium1 commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

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!

@teknium1 teknium1 closed this Apr 9, 2026
Tommyeds pushed a commit to Tommyeds/hermes-agent that referenced this pull request Apr 12, 2026
…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.
angelburgosrosado pushed a commit to angelburgosrosado/hermes-agent that referenced this pull request Apr 28, 2026
…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.
ulasbilgen pushed a commit to ulasbilgen/hermes-adhd-agent that referenced this pull request May 1, 2026
…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.
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
…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.
olympus-terminal pushed a commit to olympus-terminal/hermes-agent that referenced this pull request May 16, 2026
…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.
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
…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.
Egavasyug pushed a commit to Egavasyug/hermes-agent that referenced this pull request Jun 10, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants