Skip to content

feat(slack): add SLACK_ALLOW_BOTS env var for bot-to-bot communication#3200

Closed
Mibayy wants to merge 1 commit into
NousResearch:mainfrom
Mibayy:feat/slack-allow-bots-3198
Closed

feat(slack): add SLACK_ALLOW_BOTS env var for bot-to-bot communication#3200
Mibayy wants to merge 1 commit into
NousResearch:mainfrom
Mibayy:feat/slack-allow-bots-3198

Conversation

@Mibayy

@Mibayy Mibayy commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #3198

Adds SLACK_ALLOW_BOTS env var to the Slack adapter, bringing it to parity with DISCORD_ALLOW_BOTS.

Modes

Value Behavior
none (default) Ignore all bot messages — backward-compatible
mentions Accept bot messages only when they @mention the Hermes bot
all Accept all bot messages from other bots

The self-message guard is always active regardless of mode — the bot never processes its own messages (prevents echo loops).

Implementation

Two changes in gateway/platforms/slack.py:

1. Store bot_id from auth.test — used to identify our own messages:

self._bot_id = auth_response.get("bot_id")

2. Replace the hard filter with the three-mode check:

if event.get("bot_id") or event.get("subtype") == "bot_message":
    allow_bots = os.getenv("SLACK_ALLOW_BOTS", "none").lower().strip()
    if allow_bots == "none":
        return
    elif allow_bots == "mentions":
        if self._bot_user_id and f"<@{self._bot_user_id}>" not in text_check:
            return
    # "all" falls through
    if self._bot_id and event.get("bot_id") == self._bot_id:
        return  # always drop our own messages

Note on SLACK_ALLOWED_USERS: bot user IDs are not subject to the allowlist check (the allowlist is applied later in handle_message via the base class, keyed on the user field which bots don't populate). No change needed there.

Tests

6 new tests in TestMessageRouting:

  • test_allow_bots_all_accepts_other_bot
  • test_allow_bots_all_still_ignores_own_messages
  • test_allow_bots_mentions_accepts_when_mentioned
  • test_allow_bots_mentions_ignores_without_mention
  • test_allow_bots_none_explicit_still_ignores
  • test_allow_bots_subtype_bot_message

All 70 tests pass.

Parity with Discord's DISCORD_ALLOW_BOTS. Three modes:

  SLACK_ALLOW_BOTS=none     (default) — ignore all bot messages
  SLACK_ALLOW_BOTS=mentions — accept bot @mentions only
  SLACK_ALLOW_BOTS=all      — accept all bot messages

The self-message guard (bot_id == our own bot_id) is always active to
prevent echo loops regardless of mode.

Also stores self._bot_id from auth.test response for self-message detection.

Closes NousResearch#3198
teknium1 pushed a commit that referenced this pull request Apr 9, 2026
Three modes: "none" (default, backward-compatible), "mentions" (accept
bot messages only when they @mention us), "all" (accept all bot messages
except our own, to prevent echo loops).

Configurable via:
  slack:
    allow_bots: mentions
Or env var: SLACK_ALLOW_BOTS=mentions

Self-message guard always active regardless of mode.

Based on PR #3200 by Mibayy, adapted to current main with config.yaml
bridging support.
teknium1 pushed a commit that referenced this pull request Apr 9, 2026
Three modes: "none" (default, backward-compatible), "mentions" (accept
bot messages only when they @mention us), "all" (accept all bot messages
except our own, to prevent echo loops).

Configurable via:
  slack:
    allow_bots: mentions
Or env var: SLACK_ALLOW_BOTS=mentions

Self-message guard always active regardless of mode.

Based on PR #3200 by Mibayy, adapted to current main with config.yaml
bridging support.
@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 adapted to current main. Your authorship is preserved in git history. Thank you @Mibayy 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
Three modes: "none" (default, backward-compatible), "mentions" (accept
bot messages only when they @mention us), "all" (accept all bot messages
except our own, to prevent echo loops).

Configurable via:
  slack:
    allow_bots: mentions
Or env var: SLACK_ALLOW_BOTS=mentions

Self-message guard always active regardless of mode.

Based on PR NousResearch#3200 by Mibayy, adapted to current main with config.yaml
bridging support.
angelburgosrosado pushed a commit to angelburgosrosado/hermes-agent that referenced this pull request Apr 28, 2026
Three modes: "none" (default, backward-compatible), "mentions" (accept
bot messages only when they @mention us), "all" (accept all bot messages
except our own, to prevent echo loops).

Configurable via:
  slack:
    allow_bots: mentions
Or env var: SLACK_ALLOW_BOTS=mentions

Self-message guard always active regardless of mode.

Based on PR NousResearch#3200 by Mibayy, adapted to current main with config.yaml
bridging support.
ulasbilgen pushed a commit to ulasbilgen/hermes-adhd-agent that referenced this pull request May 1, 2026
Three modes: "none" (default, backward-compatible), "mentions" (accept
bot messages only when they @mention us), "all" (accept all bot messages
except our own, to prevent echo loops).

Configurable via:
  slack:
    allow_bots: mentions
Or env var: SLACK_ALLOW_BOTS=mentions

Self-message guard always active regardless of mode.

Based on PR NousResearch#3200 by Mibayy, adapted to current main with config.yaml
bridging support.
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
Three modes: "none" (default, backward-compatible), "mentions" (accept
bot messages only when they @mention us), "all" (accept all bot messages
except our own, to prevent echo loops).

Configurable via:
  slack:
    allow_bots: mentions
Or env var: SLACK_ALLOW_BOTS=mentions

Self-message guard always active regardless of mode.

Based on PR NousResearch#3200 by Mibayy, adapted to current main with config.yaml
bridging support.
olympus-terminal pushed a commit to olympus-terminal/hermes-agent that referenced this pull request May 16, 2026
Three modes: "none" (default, backward-compatible), "mentions" (accept
bot messages only when they @mention us), "all" (accept all bot messages
except our own, to prevent echo loops).

Configurable via:
  slack:
    allow_bots: mentions
Or env var: SLACK_ALLOW_BOTS=mentions

Self-message guard always active regardless of mode.

Based on PR NousResearch#3200 by Mibayy, adapted to current main with config.yaml
bridging support.
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
Three modes: "none" (default, backward-compatible), "mentions" (accept
bot messages only when they @mention us), "all" (accept all bot messages
except our own, to prevent echo loops).

Configurable via:
  slack:
    allow_bots: mentions
Or env var: SLACK_ALLOW_BOTS=mentions

Self-message guard always active regardless of mode.

Based on PR NousResearch#3200 by Mibayy, adapted to current main with config.yaml
bridging support.
Egavasyug pushed a commit to Egavasyug/hermes-agent that referenced this pull request Jun 10, 2026
Three modes: "none" (default, backward-compatible), "mentions" (accept
bot messages only when they @mention us), "all" (accept all bot messages
except our own, to prevent echo loops).

Configurable via:
  slack:
    allow_bots: mentions
Or env var: SLACK_ALLOW_BOTS=mentions

Self-message guard always active regardless of mode.

Based on PR NousResearch#3200 by Mibayy, adapted to current main with config.yaml
bridging support.
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.

feat: Add SLACK_ALLOW_BOTS env var (parity with Discord's DISCORD_ALLOW_BOTS)

2 participants