Complete step-by-step guide to set up Slack integration for Sleepless Agent.
Before starting:
- Admin access to your Slack workspace
- Sleepless Agent installed locally
- Understanding of basic concepts
- Go to https://api.slack.com/apps
- Click "Create New App"
- Choose "From scratch"
App Name: Sleepless Agent
Pick a workspace: [Your Workspace]
Click "Create App"
In the Basic Information page:
- Add an app icon (optional but recommended)
- Add a description:
24/7 AI agent that processes tasks autonomously using Claude Code - Set the background color:
#7C3AED(purple)
Socket Mode allows real-time communication without exposing a public endpoint.
- Go to Settings → Socket Mode
- Toggle Enable Socket Mode to ON
- You'll be prompted to create an app-level token
Token Name: sleepless-token
Scope: connections:write
Click Generate
xapp- and you'll need it for your .env file.
Go to Features → Slash Commands
Create each command by clicking "Create New Command":
Command: /think
Request URL: [Leave empty - Socket Mode handles this]
Short Description: Submit a task or thought
Usage Hint: [description] [-p project_name]
Command: /check
Request URL: [Leave empty]
Short Description: Check system status and queue
Usage Hint: [no arguments]
Command: /report
Request URL: [Leave empty]
Short Description: View task reports
Usage Hint: [task_id | date | project_name | --list]
Command: /cancel
Request URL: [Leave empty]
Short Description: Cancel a task or project
Usage Hint: <task_id | project_name>
Command: /trash
Request URL: [Leave empty]
Short Description: Manage cancelled tasks
Usage Hint: <list | restore <id> | empty>
Command: /usage
Request URL: [Leave empty]
Short Description: Show Claude Code Pro plan usage
Usage Hint: [Leave empty]
Command: /chat
Request URL: [Leave empty]
Short Description: Start interactive chat mode with Claude
Usage Hint: <project_name> | end | status | help
Go to Features → OAuth & Permissions
Add these scopes:
| Scope | Purpose |
|---|---|
chat:write |
Send messages to channels |
chat:write.public |
Send messages to public channels without joining |
commands |
Receive slash commands |
app_mentions:read |
Respond to @mentions |
channels:read |
List channels |
channels:history |
Read message history (required for chat mode) |
groups:read |
Access private channels |
groups:history |
Read private channel history (required for chat mode) |
im:read |
Read direct messages |
im:write |
Send direct messages |
im:history |
Read DM history (required for chat mode) |
users:read |
Get user information |
reactions:write |
Add emoji reactions (for chat mode indicators) |
These are optional but useful:
| Scope | Purpose |
|---|---|
files:write |
Upload files (for reports) |
files:read |
Read uploaded files |
Go to Features → Event Subscriptions
Toggle Enable Events to ON
Add these bot events:
| Event | Purpose |
|---|---|
app_mention |
Respond when bot is mentioned |
message.channels |
Monitor channel messages (required for chat mode) |
message.groups |
Monitor private channel messages (required for chat mode) |
message.im |
Respond to direct messages |
⚠️ Important for Chat Mode: Themessage.channelsandmessage.groupsevents are required for chat mode to receive messages in threads. Without these, chat mode will not work.
Since we're using Socket Mode, leave the Request URL empty.
- Go to Settings → Install App
- Click "Install to Workspace"
- Review permissions
- Click "Allow"
After installation, you'll see a Bot User OAuth Token.
xoxb- and you'll need it for your .env file.
# Create .env file
cp .env.example .envEdit .env:
# Slack Configuration (Required)
SLACK_BOT_TOKEN=xoxb-your-bot-token-here
SLACK_APP_TOKEN=xapp-your-app-token-here
# Optional: Default channel for notifications
SLACK_DEFAULT_CHANNEL=general# Test Slack connection
sle test-slack
# Should output:
# ✓ Slack bot token valid
# ✓ Slack app token valid
# ✓ Socket Mode connected
# ✓ Bot user: @sleepless-agentFor each channel where you want to use the bot:
- Go to the channel in Slack
- Type:
/invite @sleepless-agent - The bot will join the channel
For private channels:
- Channel Details → Integrations
- Add App → Sleepless Agent
- Click Add
In config.yaml:
slack:
default_channel: general
error_channel: sleepless-errors
report_channel: sleepless-reports
notification_channels:
- general
- dev-teamsle daemonYou should see:
INFO | Slack bot started and listening for events
INFO | Sleepless Agent starting...
Try these commands:
/check
# Should show system status
/think Test task from Slack
# Should acknowledge and queue task
/report --list
# Should list available reports
Try the interactive chat mode:
/chat my-project
# Should create a thread with welcome message
# In the thread, send a message:
"What files are in this project?"
# Claude should respond in the thread
# End the session:
exit
# Or use /chat end
/chat <project-name>
This creates:
- A new Slack thread for the conversation
- A project folder at
workspace/projects/<project-name>/ - A session that maintains conversation history
| Command | Description |
|---|---|
/chat <project> |
Start chat mode for a project |
/chat end |
End current chat session |
/chat status |
Show current session info |
/chat help |
Show help |
While in a chat thread, you can:
- Send any message to interact with Claude
- Type
exit,end, orquitto end the session - Claude can read, write, and edit files in the project workspace
| Indicator | Meaning |
|---|---|
| 💬 (reaction) | Chat session is active |
| 🔄 Processing... | Claude is working on your request |
| ✅ (reaction) | Chat session has ended |
Sessions automatically end after 30 minutes of inactivity.
Add custom emoji for task status:
slack:
reactions:
pending: hourglass
in_progress: gear
completed: white_check_mark
failed: xConfigure threading behavior:
slack:
threading:
enabled: true
reply_in_thread: true
broadcast_important: truePrevent Slack rate limit issues:
slack:
rate_limiting:
max_messages_per_minute: 20
retry_after: 60
backoff_multiplier: 2-
Check Socket Mode is enabled
# In Slack App settings Settings → Socket Mode → Should be ON -
Verify tokens
# Check .env file cat .env | grep SLACK
-
Check bot status
# In terminal running daemon # Should show "listening for events"
-
Reinstall slash commands
- Delete and recreate each command
- Reinstall app to workspace
-
Check permissions
- Ensure all required scopes are added
- Reinstall if scopes were changed
-
Verify Socket Mode connection
sle test-slack --verbose
-
Bot not in channel
/invite @sleepless-agent -
Missing scopes
- Add required scopes in OAuth & Permissions
- Reinstall app after scope changes
-
Private channel access
- Manually add app in channel settings
- Never commit tokens to Git
- Use environment variables only
- Rotate tokens periodically
- Restrict token access
slack:
allowed_channels:
- general
- dev-team
blocked_channels:
- sensitive-data
require_mention: true # Only respond to @mentionsslack:
authorized_users:
- U0123456789 # User IDs
- U9876543210
admin_users:
- U0123456789slack:
audit:
log_commands: true
log_users: true
retention_days: 90Track Slack-specific metrics:
def collect_slack_metrics():
return {
'commands_received': count_commands(),
'response_time': avg_response_time(),
'active_channels': count_active_channels(),
'error_rate': calculate_error_rate()
}monitoring:
slack_health:
check_interval: 60 # seconds
timeout: 10
alert_on_failure: trueConfigure error handling:
slack:
errors:
notify_channel: sleepless-errors
include_stacktrace: false
rate_limit: 5 # Max 5 error messages per hourNow that Slack is configured: