Features
- Socket Mode: Outbound WebSocket connection (no public URL needed)
- Command support:
/help,/new,/status,/model,/clear,/compact,/version - File attachments: Send files directly in Slack channels
- Message splitting: Handles messages up to 40,000 characters
- User allowlists: Restrict bot access to specific user IDs
- Channel and DM support: Works in both channels and direct messages
Prerequisites
Install the Slack channel dependencies:slack-sdk with Socket Mode support for bot functionality.
Creating a Slack Bot
- Enter a token name (e.g., “grip-socket-token”)
- Add the
connections:writescope - Click “Generate”
xapp-)You can only view the app-level token once. Save it immediately! If you lose it, you’ll need to generate a new one.
chat:write- Send messagesfiles:write- Upload fileschannels:history- Read channel messagesgroups:history- Read private channel messagesim:history- Read direct messagesmpim:history- Read group direct messages
message.channels- Messages in public channelsmessage.groups- Messages in private channelsmessage.im- Direct messagesmessage.mpim- Group direct messages
Configuration
The Slack channel requires two tokens:- Bot Token (
xoxb-...): OAuth token for API calls - App Token (
xapp-...): App-level token for Socket Mode
config.yaml:
Environment Variables
For better security, use environment variables:User Allowlist
Restrict bot access to specific users:To find your Slack user ID:
- Click your profile picture in Slack
- Select “Profile”
- Click “More” (three dots)
- Select “Copy member ID”
allow_from is empty or omitted, anyone in the workspace can use the bot.
Bot Commands
The Slack bot supports these commands (defined inchannels/slack.py:27-35). Commands can use either ! or / prefix:
/help or !help
Lists all available commands with descriptions.
/new or !new
Starts a fresh conversation by clearing the session:
/status or !status
Shows current session information:
/model [name] or !model [name]
Shows the current model or switches to a different one:
/clear or !clear
Clears the entire conversation history:
/compact or !compact
Summarizes and compresses the session history:
/version or !version
Shows the Grip AI version:
Message Handling
The Slack channel processes messages through Socket Mode events (reference:channels/slack.py:82-129):
Text Messages
All non-command text messages are forwarded to the agent for processing.Commands
Messages starting with! or / are checked against the command list. If the command is recognized, it’s processed as a command.
Bot Messages Ignored
Messages withsubtype (bot messages, message changes, etc.) are automatically ignored to prevent loops.
Message Metadata
Each message includes metadata:Socket Mode Architecture
Socket Mode uses an outbound WebSocket connection from your Grip AI instance to Slack’s servers. This means:- No public URL required: Your server doesn’t need to be accessible from the internet
- No webhook setup: No need to configure request URLs
- No ngrok/tunneling: Works behind firewalls and NAT
- Simple deployment: Easier to run locally or in private networks
channels/slack.py:51-133
Socket Mode is perfect for development, testing, and private deployments. For high-scale production use, consider Event API with webhooks instead.
Sending Files from Agent
The agent can send files to Slack channels using thefiles_upload_v2 API (with automatic fallback to files_upload for older SDK versions).
Implementation reference: channels/slack.py:153-188
Example agent response with file:
text field is sent as the initial_comment (appears above the file).
Message Length Limits
Slack enforces a 40,000 character limit per message (much higher than Telegram and Discord). Long responses are automatically split on newline boundaries when possible. Implementation:channels/base.py:78-101
Channel IDs
Slack uses channel IDs (not names) for message routing:- Public channels: IDs start with
C(e.g.,C01ABC123) - Private channels: IDs start with
G(e.g.,G02DEF456) - Direct messages: IDs start with
D(e.g.,D03GHI789) - Group DMs: IDs start with
G(e.g.,G04JKL012)
To find a channel ID in Slack:
- Right-click the channel name
- Select “View channel details”
- Scroll down to find the Channel ID
Connection Process
The Slack channel uses Socket Mode for connectivity (reference:channels/slack.py:51-133):
Error Handling
The channel implements graceful error handling: Channel not found: Logs error if channel ID is invalid File not found: Sends error message instead of file API version fallback: Triesfiles_upload_v2, falls back to files_upload for older SDK versions
Send failures: Logs error and continues operation
Implementation Reference
The Slack channel is implemented inchannels/slack.py:
- Bot initialization:
slack.py:51-80 - Event handler:
slack.py:82-129 - Connection process:
slack.py:131-133 - Send methods:
slack.py:144-188 - Command list:
slack.py:27-35
Troubleshooting
Bot doesn’t respond
- Check that both tokens are correct in your configuration
- Verify the bot is enabled:
channels.slack.enabled: true - Ensure Socket Mode is enabled in the Slack app settings
- Check that Event Subscriptions are configured with the correct events
- Verify you’re not blocked by the
allow_fromlist - Check logs for connection errors
”slack-sdk not found” error
Install the Slack channel dependencies:“Slack app-level token is required” error
You need to provide both the bot token and the app-level token:Bot connects but doesn’t receive messages
Check Event Subscriptions in the Slack app settings:- Navigate to “Event Subscriptions”
- Verify “Enable Events” is ON
- Ensure these events are subscribed:
message.channelsmessage.groupsmessage.immessage.mpim
- Click “Save Changes” and reinstall the app if needed
Missing bot scopes error
Add the required scopes in “OAuth & Permissions” → “Bot Token Scopes”:chat:writefiles:writechannels:historygroups:historyim:historympim:history
Bot responds to everyone (security concern)
Add a user allowlist:Socket Mode vs Events API
Socket Mode is one of two ways to receive events from Slack:| Feature | Socket Mode | Events API |
|---|---|---|
| Public URL | Not required | Required |
| Setup complexity | Lower | Higher |
| Scalability | Good for small/medium | Better for large scale |
| Latency | Slightly higher | Lower |
| Best for | Development, private networks | Production, high traffic |
Next Steps
Message Bus
Learn how channels integrate with the message bus
Telegram Setup
Set up a Telegram bot with rich command support