Skip to content

feat(slack): add allowBots "mentions" mode (parity with Discord) - #43588

Closed
raw34 wants to merge 7 commits into
openclaw:mainfrom
raw34:feat/slack-allowbots-mentions
Closed

raw34 wants to merge 7 commits into
openclaw:mainfrom
raw34:feat/slack-allowbots-mentions

Conversation

@raw34

@raw34 raw34 commented Mar 12, 2026

Copy link
Copy Markdown

Summary

  • Add "mentions" as a valid value for Slack's allowBots config, matching Discord's existing allowBots: "mentions" implementation
  • When set to "mentions", only bot messages that explicitly @mention the receiving bot (or have implicit mention via thread participation) are processed
  • Prevents infinite reply loops in multi-agent setups where different bots share a channel

Closes #43587

Changes

6 files modified:

File Change
src/config/types.slack.ts allowBots type: boolean → boolean | "mentions" (both SlackChannelConfig and SlackAccountConfig)
src/slack/monitor/channel-config.ts Local type definitions synced
src/config/zod-schema.providers-core.ts Zod schema updated for SlackChannelSchema and SlackAccountSchema
src/slack/monitor/message-handler/prepare.ts Core logic: three-state allowBotsMode resolution + mentions-mode gate after mention gating
src/config/schema.help.ts Help text updated
src/slack/monitor/message-handler/prepare.test.ts 4 new test cases

Behavior:

allowBots value Bot msg without @mention Bot msg with @mention
false (default) Drop Drop
true Process Process
"mentions" Drop Process

Discord reference: src/discord/monitor/message-handler.preflight.ts:142-144, 661-668

Test plan

  • Drops bot messages without mention when allowBots=mentions
  • Allows bot messages with explicit mention when allowBots=mentions
  • Allows bot DM messages when allowBots=mentions
  • Allows bot messages with implicit mention (thread participation) when allowBots=mentions
  • Existing allowBots: true and allowBots: false tests still pass
  • Lint passes (0 errors)

🤖 Generated with Claude Code

@openclaw-barnacle openclaw-barnacle Bot added channel: slack Channel integration: slack size: S labels Mar 12, 2026
@greptile-apps

greptile-apps Bot commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds "mentions" as a third valid value for Slack's allowBots config (alongside true and false), achieving feature parity with Discord's existing implementation. When set to "mentions", bot messages are only processed if the receiving bot is explicitly @mentioned, the message is a DM, or the bot has prior thread participation — preventing infinite reply loops in multi-agent setups.

Key changes:

  • allowBots type updated from boolean to boolean | "mentions" across SlackChannelConfig, SlackAccountConfig, SlackChannelConfigResolved, and SlackChannelConfigEntry
  • Zod schemas updated using the same z.union([z.boolean(), z.literal("mentions")]) pattern already used by Discord
  • allowBots: boolean in SlackConversationContext replaced with a tri-state allowBotsMode: "off" | "all" | "mentions", cleanly separating the two independent gates (bot allowed at all vs. mention required for bots)
  • The bot-mentions gate is correctly placed after mention-gating but before any API side-effects, mirroring src/discord/monitor/message-handler.preflight.ts:661-668
  • 4 new test cases covering the main scenarios

Issues found:

  • The implicit-mention test (recordSlackThreadParticipation) writes to module-level state without cleanup; clearSlackThreadParticipationCache() exists for exactly this purpose and is already used in sent-thread-cache.test.ts

Confidence Score: 4/5

  • Safe to merge — the logic is correct and closely mirrors the existing Discord implementation; one test isolation issue should be addressed.
  • The implementation is well-structured and the tri-state mode resolution, gate placement, type changes, and Zod schema updates are all consistent and correct. The only notable issue is the missing cleanup of module-level cache state in the implicit-mention test, which could cause subtle test pollution in future additions but does not affect runtime behavior.
  • src/slack/monitor/message-handler/prepare.test.ts — the implicit-mention test should call clearSlackThreadParticipationCache() after the assertion to prevent state leakage.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/slack/monitor/message-handler/prepare.test.ts
Line: 446-447

Comment:
**Missing cache cleanup risks test pollution**

`recordSlackThreadParticipation` writes to a module-level singleton (`threadParticipation` map in `sent-thread-cache.ts`). This entry (`"default:C123:1.000"`) persists for the rest of the test run. The `clearSlackThreadParticipationCache()` helper exists precisely for this — `sent-thread-cache.test.ts` always calls it in `beforeEach`/`afterEach`. Any future test that happens to use `accountId: "default"`, `channel: "C123"`, and `thread_ts: "1.000"` will unexpectedly find `implicitMention: true`.

Consider importing and calling `clearSlackThreadParticipationCache` after the assertion:

```suggestion
    const { recordSlackThreadParticipation, clearSlackThreadParticipationCache } = await import("../../sent-thread-cache.js");
    recordSlackThreadParticipation("default", "C123", "1.000");
```

…and adding a teardown in an `afterEach` (or at the end of this test) to clear the cache:
```ts
afterEach(async () => {
  const { clearSlackThreadParticipationCache } = await import("../../sent-thread-cache.js");
  clearSlackThreadParticipationCache();
});
```

How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: 5e6a86c

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Apr 27, 2026
@clawsweeper

clawsweeper Bot commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

Summary
This PR widens Slack allowBots to accept "mentions" in shared config/schema/help and adds mention-gated bot-message handling/tests in the old src/slack message preparation path.

Reproducibility: yes. Source inspection is enough for this feature gap: current Slack config accepts only boolean allowBots, and the active runtime treats the value as a boolean rather than a mention-only mode.

Next step before merge
Queue a focused replacement because the source work is useful but the PR is mis-targeted to retired Slack files and needs a clear port into the active plugin.

Security
Needs attention: Schema acceptance must not get ahead of active Slack runtime authorization for bot-authored messages.

Review findings

  • [P2] Port the bot gate to the active Slack plugin — src/slack/monitor/message-handler/prepare.ts:87-90
  • [P2] Keep schema acceptance aligned with runtime semantics — src/config/zod-schema.providers-core.ts:802
  • [P3] Add the required changelog entry — src/config/types.slack.ts:40
Review details

Best possible solution:

Retarget or replace the PR with an active extensions/slack implementation that keeps config schema, plugin metadata, docs, tests, and changelog aligned while preserving the existing Slack bot-room authorization guard.

Do we have a high-confidence way to reproduce the issue?

Yes. Source inspection is enough for this feature gap: current Slack config accepts only boolean allowBots, and the active runtime treats the value as a boolean rather than a mention-only mode.

Is this the best way to solve the issue?

No. The requested direction is consistent with Discord and Matrix, but the submitted patch is not the best fix because it updates retired src/slack files instead of the active Slack plugin.

Full review comments:

  • [P2] Port the bot gate to the active Slack plugin — src/slack/monitor/message-handler/prepare.ts:87-90
    Current main no longer tracks src/slack/**; Slack inbound handling lives under extensions/slack, where allowBots is still boolean-only. As written, this PR does not enable the shipped Slack runtime after rebase.
    Confidence: 0.95
  • [P2] Keep schema acceptance aligned with runtime semantics — src/config/zod-schema.providers-core.ts:802
    This widens Slack config validation to accept "mentions", but the active Slack runtime still treats allowBots as a truthy boolean. If the schema lands without the plugin tri-state gate, "mentions" can behave like allowBots: true rather than mention-only.
    Confidence: 0.92
  • [P3] Add the required changelog entry — src/config/types.slack.ts:40
    This is a user-facing Slack config feature, so repo policy requires a CHANGELOG.md entry before merge.
    Confidence: 0.9

Overall correctness: patch is incorrect
Overall confidence: 0.94

Security concerns:

  • [medium] Keep bot-message authorization aligned with schema — src/config/zod-schema.providers-core.ts:802
    Accepting allowBots: "mentions" in shared Slack config while the active Slack plugin still checks allowBots as a boolean can process bot-authored messages as fully allowed instead of mention-gated.
    Confidence: 0.88

Acceptance criteria:

  • pnpm test extensions/slack/src/monitor/message-handler/prepare.test.ts extensions/slack/src/config-schema.test.ts
  • pnpm exec oxfmt --check --threads=1 extensions/slack/src/monitor/message-handler/prepare.ts extensions/slack/src/monitor/message-handler/prepare.test.ts extensions/slack/src/monitor/channel-config.ts extensions/slack/src/config-ui-hints.ts extensions/slack/src/config-schema.test.ts src/config/types.slack.ts src/config/zod-schema.providers-core.ts docs/channels/slack.md docs/gateway/config-channels.md CHANGELOG.md
  • pnpm config:channels:check
  • pnpm config:docs:gen/check
  • pnpm check:changed

What I checked:

Likely related people:

  • Peter Steinberger: Visible shallow blame for the active Slack runtime, Slack config types, schemas, and Slack docs points at the current release-prep history for these files; useful as a maintainer routing hint, not as original-introducer proof. (role: recent maintainer; confidence: medium; commits: 5397667272; files: extensions/slack/src/monitor/message-handler/prepare.ts, src/config/types.slack.ts, src/config/zod-schema.providers-core.ts)
  • @andrewhong-translucent: The changelog credits recent Slack allowBots=true room-message hardening, which is directly adjacent to this bot-message authorization path. (role: adjacent owner; confidence: medium; files: CHANGELOG.md, extensions/slack/src/monitor/message-handler/prepare.ts, docs/channels/slack.md)
  • @thewilloftheshadow: The changelog credits the existing Discord allowBots: "mentions" behavior that this Slack feature is explicitly trying to match. (role: precedent owner; confidence: low; files: CHANGELOG.md, src/config/types.discord.ts, src/config/zod-schema.providers-core.ts)

Remaining risk / open question:

  • A partial schema/type merge without active Slack runtime support would make allowBots: "mentions" truthy in the current plugin and can process bot-authored messages more broadly than the new mode promises.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 5f373ae4d3db.

@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Apr 28, 2026
@steipete

Copy link
Copy Markdown
Contributor

Landed the Slack allowBots: "mentions" behavior via maintainer commit 8654144.

I did not merge this PR directly because the branch was conflict-marked against current main; the shipped commit ports the behavior to the current Slack plugin paths, updates the config surface, adds current regression coverage, and credits the contribution in CHANGELOG.md.

Verification:

  • pnpm test extensions/slack/src/draft-stream.test.ts extensions/slack/src/monitor/message-handler/prepare.test.ts extensions/slack/src/config-schema.test.ts
  • pnpm tsgo:extensions
  • pnpm tsgo:core
  • pnpm config:schema:check
  • pnpm config:docs:check

Thanks @raw34.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: slack Channel integration: slack size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Slack allowBots: "mentions" mode (parity with Discord)

2 participants