Slack Integration
This guide explains how to set up Slack integration for lsbot's message router.
Architecture
Prerequisites
- A Slack workspace where you have permission to install apps
- An Anthropic API key for Claude
- lsbot binary built and available
Step 1: Create a Slack App
- Go to Slack API Apps
- Click "Create New App"
- Select "From scratch"
- Enter App Name:
lsbot - Select your workspace
- Click "Create App"
Step 2: Enable Socket Mode
Socket Mode allows the bot to receive events without exposing a public URL.
- In your app settings, go to "Socket Mode" in the left sidebar
- Toggle "Enable Socket Mode" to ON
- You'll be prompted to create an App-Level Token:
- Token Name:
socket-token - Scopes:
connections:write
- Token Name:
- Click "Generate"
- Save the App-Level Token (
xapp-...) - you'll need this later
Step 3: Configure Bot Scopes
- Go to "OAuth & Permissions" in the left sidebar
- Scroll to "Scopes" section
- Under "Bot Token Scopes", add:
| Scope | Description |
|---|---|
app_mentions:read | View messages that mention the bot |
chat:write | Send messages as the bot |
im:history | View messages in DMs with the bot |
im:read | View basic DM info |
im:write | Start DMs with the bot |
Step 4: Enable Event Subscriptions
- Go to "Event Subscriptions" in the left sidebar
- Toggle "Enable Events" to ON
- Under "Subscribe to bot events", add:
| Event | Description |
|---|---|
app_mention | Triggered when someone @mentions the bot |
message.im | Triggered when someone DMs the bot |
- Click "Save Changes"
Step 5: Install the App
- Go to "Install App" in the left sidebar
- Click "Install to Workspace"
- Review permissions and click "Allow"
- Copy the Bot User OAuth Token (
xoxb-...)
Step 6: Run lsbot Router
Using Environment Variables
Using Command-Line Flags
Using a .env File
Create a .env file:
Then run:
Step 7: Test the Integration
- Open Slack
- Find your bot in the Apps section or DM it directly
- Send a message like:
@lsbot what's on my calendar today?@lsbot list files in ~/Desktop@lsbot what's my system info?
Available Commands
Once connected, the bot can:
| Category | Examples |
|---|---|
| Calendar | "What's on my calendar today?", "Schedule a meeting tomorrow at 2pm" |
| Files | "List files in ~/Downloads", "Find old files on my Desktop" |
| System | "What's my CPU usage?", "Show disk space" |
| Shell | "Run ls -la", "Check git status" |
| Process | "List running processes", "What's using the most memory?" |
Troubleshooting
Bot not responding
- Check that all three tokens are set correctly
- Verify the bot is running:
lsbot gateway - Check logs for errors
"not_authed" error
Your SLACK_BOT_TOKEN is invalid or expired. Reinstall the app and get a new token.
"invalid_auth" for Socket Mode
Your SLACK_APP_TOKEN is invalid. Generate a new App-Level Token in Socket Mode settings.
Bot responds in wrong channel
The bot only responds to:
- Direct messages (DMs)
- @mentions in channels
Make sure to @mention the bot in channels.
Security Considerations
- Never commit tokens to version control
- Use environment variables or a secrets manager
- Restrict bot installation to trusted workspaces
- Review bot permissions regularly
Running as a Service
To run the router as a background service, create a systemd unit or launchd plist: