This guide covers setting up Kōan with Slack as the messaging provider. Slack uses Socket Mode for real-time bidirectional communication.
- A Slack workspace where you have permission to install apps (or can request admin approval)
- Go to api.slack.com/apps
- Click Create New App → From scratch
- Name it (e.g., "Kōan") and select your workspace
- Click Create App
- In your app settings, go to Settings → Socket Mode
- Toggle Enable Socket Mode to ON
- When prompted, create an App-Level Token:
- Name:
koan-socket(or anything descriptive) - Scope:
connections:write
- Name:
- Click Generate and copy the token (starts with
xapp-)
-
Go to OAuth & Permissions → Scopes → Bot Token Scopes
-
Add these scopes:
Scope Purpose chat:writeSend messages channels:historyRead messages in public channels groups:historyRead messages in private channels im:historyRead direct messages app_mentions:readRespond to @mentions -
Go to Event Subscriptions → Enable Events
-
Under Subscribe to bot events, add:
message.channelsmessage.groupsmessage.imapp_mention
- Go to OAuth & Permissions
- Click Install to Workspace (or Request to Install if admin approval is required)
- Authorize the requested permissions
- Copy the Bot User OAuth Token (starts with
xoxb-)
- In Slack, right-click on the channel where Kōan should operate
- Click View channel details
- At the bottom of the panel, copy the Channel ID (e.g.,
C01234ABCD)
In the Slack channel, type:
/invite @koan
(Replace @koan with your bot's display name)
pip install 'slack-sdk>=3.27'
# Or add to your virtualenv:
.venv/bin/pip install 'slack-sdk>=3.27'Security note: Your bot and app tokens grant access to your Slack workspace. Never commit them to a public repo. If you accidentally leak them, rotate them immediately in the Slack app settings.
Edit your .env file:
# Messaging provider
KOAN_MESSAGING_PROVIDER=slack
# Slack credentials (all required)
KOAN_SLACK_BOT_TOKEN=xoxb-your-bot-token
KOAN_SLACK_APP_TOKEN=xapp-your-app-token
KOAN_SLACK_CHANNEL_ID=C01234ABCDOr in instance/config.yaml:
messaging:
provider: "slack"make startYou should see in the logs:
[init] Messaging provider: SLACK, Channel: C01234ABCD
[slack] Socket Mode connected.
- Verify your
KOAN_SLACK_BOT_TOKENstarts withxoxb- - Make sure the app is installed to the workspace (Step 4)
- Check that scopes are correct (Step 3)
- Verify your
KOAN_SLACK_APP_TOKENstarts withxapp- - Make sure Socket Mode is enabled (Step 2)
- The
connections:writescope must be on the App-Level Token
- Make sure the bot is invited to the channel (
/invite @koan) - Verify the
KOAN_SLACK_CHANNEL_IDmatches the channel - Check that event subscriptions are enabled (Step 3)
- Messages from other bots and message subtypes (edits, joins) are filtered out
- Slack limits
chat.postMessageto ~1 message/second. Kōan handles this automatically with built-in rate limiting. - Long messages are chunked to 4000 characters per message.
- Socket Mode: Kōan uses Slack's Socket Mode (WebSocket) for receiving events — no public URL or ngrok needed
- Event buffering: Incoming messages are buffered in a thread-safe queue and processed on each poll cycle
- Single channel: Kōan only listens and responds in the configured channel (ignores DMs and other channels)
- @mention stripping: When you @mention the bot, the mention prefix is automatically removed before processing