Slack Integration
OpenPact connects to Slack using Socket Mode, which means no public URL or webhook infrastructure is needed. Your AI assistant can communicate through Slack channels and direct messages.
Setting Up a Slack App
Create a Slack App
- Go to api.slack.com/apps
- Click Create New App > From scratch
- Name your app (e.g., "OpenPact AI") and select your workspace
- Click Create App
Enable Socket Mode
- In the left sidebar, go to Socket Mode
- Toggle Enable Socket Mode on
- Create an app-level token with the
connections:writescope - Name it (e.g., "openpact-socket") and click Generate
- Copy the token (starts with
xapp-) - this is yourSLACK_APP_TOKEN
Configure Bot Permissions
- Go to OAuth & Permissions in the left sidebar
- Under Bot Token Scopes, add:
chat:write- Send messageschannels:read- View channel infochannels:history- Read channel messagesim:read- View DM infoim:history- Read DM messagesapp_mentions:read- Detect @mentions
Subscribe to Events
- Go to Event Subscriptions in the left sidebar
- Toggle Enable Events on
- Under Subscribe to bot events, add:
message.channels- Messages in public channelsmessage.im- Direct messages
Create Slash Commands
- Go to Slash Commands in the left sidebar
- Create these commands:
| Command | Description | Usage Hint |
|---|---|---|
/openpact-new | Start a new conversation session | |
/openpact-sessions | List all conversation sessions | |
/openpact-switch | Switch to an existing session | [session_id] |
Slack requires globally unique slash command names within a workspace. The /openpact- prefix avoids conflicts. OpenPact strips this prefix internally, so /openpact-new maps to the new command.
Install to Workspace
- Go to Install App in the left sidebar
- Click Install to Workspace
- Review and authorize the permissions
- Copy the Bot User OAuth Token (starts with
xoxb-) - this is yourSLACK_BOT_TOKEN
Configuration
Set the tokens in your environment:
# .env file
SLACK_BOT_TOKEN=xoxb-your-bot-token
SLACK_APP_TOKEN=xapp-your-app-token
Configure Slack in openpact.yaml:
slack:
enabled: true
allowed_users:
- "U12345678" # Slack user ID
allowed_chans:
- "C12345678" # Allowed channel ID
Finding User and Channel IDs
- User ID: Click on a user's name > View profile > More (three dots) > Copy member ID
- Channel ID: Right-click a channel name > View channel details > the ID is at the bottom
Allowlisting
User Allowlisting
When allowed_users is configured, only those users' messages are processed:
slack:
enabled: true
allowed_users:
- "U12345678" # User 1
- "U23456789" # User 2
If allowed_users is empty, all users can interact with the bot.
Channel Allowlisting
Restrict which channels the bot responds in:
slack:
enabled: true
allowed_users:
- "U12345678"
allowed_chans:
- "C12345678" # #ai-assistant
- "C23456789" # #engineering
If allowed_chans is empty, the bot responds in all channels it has been added to.
Slash Commands
| Slack Command | Maps To | Description |
|---|---|---|
/openpact-new | new | Start a new conversation session for this channel |
/openpact-sessions | sessions | List all sessions (marks active for this channel) |
/openpact-switch <id> | switch | Switch this channel to a different session |
Command responses are ephemeral (only visible to the user who ran the command).
Examples
Start a new session:
/openpact-new
→ New session started: ses_abc123... - New session
List sessions:
/openpact-sessions
→ Sessions:
- ses_abc123... — Debugging the API (active in this channel)
- ses_def456... — Code review discussion
Switch to another session:
/openpact-switch ses_def456
→ Switched to session: ses_def456... - Code review discussion
Message Handling
How Messages Are Processed
- User sends a message in an allowed channel or DM
- OpenPact checks user and channel allowlists
- Messages from the bot itself and message subtypes (edits, joins, etc.) are ignored
- The message is forwarded to the AI engine with source context
- The AI response is posted back to the same channel
Source Context
Messages to the AI include provider context:
[via slack, channel:C12345678, user:U12345678]
Can you check the latest deployment?
Per-Channel Sessions
Each Slack channel and DM conversation gets its own session. The #engineering channel has a separate conversation from #design, and both are independent from any DM conversations.
Proactive Messaging
The AI can send messages to any Slack channel or user using the chat_send MCP tool:
{
"name": "chat_send",
"arguments": {
"provider": "slack",
"target": "C12345678",
"message": "Build completed successfully! All 171 tests passed."
}
}
For DMs, use the user ID as the target:
{
"name": "chat_send",
"arguments": {
"provider": "slack",
"target": "U12345678",
"message": "Your report is ready."
}
}
Troubleshooting
Bot Not Responding
- Check both tokens: Both
SLACK_BOT_TOKENandSLACK_APP_TOKENmust be set - Socket Mode: Verify Socket Mode is enabled in the Slack app settings
- Event subscriptions: Ensure
message.channelsandmessage.imevents are subscribed - Channel membership: The bot must be invited to channels with
/invite @BotName - Review logs: Check OpenPact logs for Slack auth or socket errors
Permission Errors
If the bot can read but not send messages:
- Verify
chat:writescope is in the bot token scopes - Reinstall the app if you added scopes after initial installation
- Check channel-specific permission overrides in Slack
Slash Commands Not Working
- Verify commands are created in the Slack app settings
- Check that the command names match exactly (
/openpact-new,/openpact-sessions,/openpact-switch) - Reinstall the app after adding new slash commands
Bot Goes Offline
Socket Mode connections can drop. OpenPact logs reconnection attempts. If the bot stays offline:
- Check your network connectivity
- Verify the
SLACK_APP_TOKENhasn't been revoked - Restart OpenPact
Related Documentation
- Chat Providers Overview - Multi-provider architecture
- MCP Tools Reference -
chat_sendtool documentation - Configuration Overview - General configuration
- Environment Variables - Setting Slack tokens