Setup
1. Create a Slack App
- Go to api.slack.com/apps and click Create New App
- Choose From scratch, name your app, and select a workspace
2. Enable Socket Mode
- Go to Settings → Socket Mode and enable it
- Generate an App-Level Token with the
connections:writescope (starts withxapp-)
3. Add Bot Token Scopes
Go to OAuth & Permissions → Scopes → Bot Token Scopes and add:| Scope | Purpose |
|---|---|
chat:write | Send messages |
app_mentions:read | Respond to @mentions |
channels:history | Read channel messages |
im:history | Read DMs |
files:read | Download shared files |
files:write | Upload files |
users:read | Resolve user info |
reactions:write | Add typing/done reactions |
4. Subscribe to Events
Go to Event Subscriptions → Subscribe to bot events and add:message.im— Direct messagesapp_mention— @mentions in channelsmessage.channels— Channel messages (if you want thread replies)
5. Install and Run
Install the app to your workspace, then copy the Bot User OAuth Token (starts withxoxb-).
Installation
slack-bolt and aiohttp as dependencies.
SlackInterface Parameters
Authentication
Slack Bot User OAuth Token (
xoxb-...).Slack App-Level Token (
xapp-...). Required when mode="socket".Signing secret for request verification. Required when
mode="http".Receiver Mode
How the bot receives events.
"socket" for development (WebSocket, no public URL needed), "http" for production (Events API, requires public URL).HTTP Events API Settings
URL path for the Events API endpoint (HTTP mode only).
URL path for interactive components (HTTP mode only).
Channel Behavior
Respond when @mentioned in channels.
Respond to direct messages.
Respond when a user replies in a thread the bot started.
Always reply in a thread when in channels (keeps channels tidy).
Reply in threads in DMs. When
false, replies appear as top-level DM messages.Typing Indicators
Emoji reaction added while the agent processes. Set to
"" to disable.Emoji reaction added when the agent finishes. Set to
"" to disable.Text Formatting
Automatically convert standard Markdown to Slack mrkdwn format (
**bold** → *bold*, [text](url) → <url|text>, etc.).Maximum message length. Messages exceeding this are split at paragraph/sentence boundaries.
Access Control
Only accept messages from these Slack user IDs. All users allowed if not set.
Only accept messages from these channel IDs. All channels allowed if not set.
Rate Limiting & Timeouts
Maximum retries for Slack API calls on rate limit (429) responses.
HTTP connection timeout in seconds.
HTTP request timeout in seconds.
Slash Commands
Slash commands to register. Maps command name to description. Commands are routed through the agent pipeline by default.
Whether slash commands are sent to the agent. When
false, commands only dispatch to registered callbacks.Socket Mode (Development)
Socket Mode uses a WebSocket connection — no public URL, no HTTPS, no firewall configuration. Ideal for development.HTTP Events API (Production)
For production, use HTTP mode with Slack’s Events API. Events are pushed to your server over HTTPS.- A publicly accessible HTTPS URL
- The signing secret from your app’s Basic Information page
- Event subscriptions configured to point at your URL
Threading
The Slack interface automatically manages thread context:- Channel messages: Replies always go to a thread (when
thread_replies_in_channel=True) - Thread replies: When a user replies in a bot thread, the conversation continues in that thread with full history
- DMs: By default, replies appear as top-level messages (set
thread_replies_in_dm=Truefor threaded DMs)
Media Support
The interface handles Slack file uploads automatically:| Slack Type | Converted To | Notes |
|---|---|---|
| Images (png, jpg, gif) | Image | Downloaded and passed to the agent |
| Audio files | Audio | Includes file metadata |
| Documents | File | Includes filename and mime type |
images, audio, and files parameters.
Block Kit Interactions
Slash Commands
Register slash commands that route through the agent:You must also register slash commands in your Slack app settings at Features → Slash Commands. The
slash_commands parameter tells the interface to listen for them.Custom Command Handlers
Handle commands with custom logic instead of (or alongside) the agent:Buttons and Actions
Register handlers for interactive components:Modals
Open and handle modal dialogs:Shortcuts
Handle global and message shortcuts:Reactions
React to emoji reactions:App Home Tab
Publish a custom App Home tab:Block Kit Builders
Theformatter module provides pure-dict builders for Slack’s Block Kit — no SDK dependency needed:
Additional API Methods
The interface provides methods beyond basic messaging:| Method | Description |
|---|---|
update_message(channel, ts, ...) | Edit an existing message |
send_ephemeral(channel, user, text) | Send a message only visible to one user |
send_blocks(channel, blocks, ...) | Send rich Block Kit messages |
open_modal(trigger_id, view) | Open a modal dialog |
update_modal(view_id, view) | Update an open modal |
push_modal(trigger_id, view) | Push a new view onto the modal stack |
publish_home(user_id, view) | Publish an App Home tab |
schedule_message(channel, text, post_at) | Schedule a message for later |
delete_scheduled_message(channel, id) | Cancel a scheduled message |
delete_message(channel, ts) | Delete a message |
get_permalink(channel, ts) | Get a permanent link to a message |
set_topic(channel, topic) | Set a channel’s topic |
pin_message(channel, ts) | Pin a message |
unpin_message(channel, ts) | Unpin a message |
Access Control
Restrict who can interact with the bot:Agent with Tools and Memory
Error Handling
The Slack interface maps API errors to the standard exception hierarchy:| Scenario | Exception | Recovery |
|---|---|---|
| Invalid bot token | InterfaceAuthenticationError | Check token validity |
| Rate limited (429) | InterfaceRateLimitError | Auto-retried up to max_retries |
| Invalid channel/user | InterfaceMessageError | Check IDs and permissions |
| Network failure | InterfaceConnectionError | Auto-reconnect (Socket Mode) |
error_message is sent to the user, and all on_error hooks are invoked.