A Slack bot that connects Slack to your LocalBrain daemon. When users ask questions in monitored channels, the bot retrieves answers from your LocalBrain knowledge base and responds as you, using first-person responses.
Slack Message → Slack Events API → FastAPI Webhook (/slack/events)
↓
LocalBrain Daemon (/protocol/slack/answer)
↓
Answer Retrieved
↓
Slack SDK posts response
-
FastAPI Server (
main.py)- Receives Slack events via webhook (
/slack/events) - Validates Slack signatures for security
- Routes messages to background processing
- Receives Slack events via webhook (
-
Slack Synthesizer (
slack_synthesizer.py)- Poses as the user (first-person responses)
- Adapts tone based on Slack context (workspace, channel, asker)
- Protects user reputation with built-in guardrails
- Returns clean answers without source citations
-
Slack SDK Client
- Posts responses back to Slack
- Handles threading automatically
- Manages API rate limits
User posts message in Slack
↓
Slack Events API sends webhook
↓
POST /slack/events (FastAPI)
↓
Verify Slack signature
↓
Extract message & channel
↓
Check if channel is monitored
↓
Queue background task
↓
Call daemon: POST /protocol/slack/answer
↓
Daemon searches knowledge base & synthesizes answer
↓
Return answer to bot
↓
Post response via Slack SDK
↓
Message appears in Slack thread
- Python 3.10+
- Slack workspace admin access
- LocalBrain daemon running at
http://127.0.0.1:8765(or configured URL)
cd slack-bot
pip install -r requirements.txt- Go to https://api.slack.com/apps
- Click "Create New App" → "From scratch"
- Name:
LocalBrain Assistant - Select your workspace
- Click "Create App"
- Go to "OAuth & Permissions"
- Under "Bot Token Scopes", add:
chat:write- Send messageschannels:history- Read channel messageschannels:read- View channel infoim:history- Read DM messagesim:write- Send DM messagesapp_mentions:read- Read mentions
- Go to "Event Subscriptions"
- Toggle "Enable Events" to ON
- Request URL:
https://your-domain.com/slack/events- You'll need to deploy your server first or use ngrok for testing
- Under "Subscribe to bot events", add:
message.channels- Listen to messages in public channelsmessage.im- Listen to direct messagesapp_mention- Listen to @mentions
- Go to "Install App"
- Click "Install to Workspace"
- Authorize the app
- Copy the "Bot User OAuth Token" (starts with
xoxb-)
- Go to "Basic Information"
- Under "App Credentials", find "Signing Secret"
- Click "Show" and copy it
- Open Slack workspace in browser
- Navigate to the channel you want to monitor
- Copy the channel ID from URL
- URL format:
https://app.slack.com/client/TXXXXXX/C01234ABCDE - Channel ID is the last part:
C01234ABCDE
- URL format:
- In Slack, go to your target channel
- Type
/invite @LocalBrain Assistant
Create a .env file:
# Slack Configuration
SLACK_BOT_TOKEN=xoxb-your-bot-token-here
SLACK_SIGNING_SECRET=your-signing-secret-here
SLACK_CHANNEL_ID=C01234ABCDE
# LocalBrain Daemon Configuration
DAEMON_URL=http://127.0.0.1:8765
# Trigger Keywords (optional - comma-separated)
TRIGGER_KEYWORDS=internship,interview,job,offer,resume
# Server Configuration
HOST=0.0.0.0
PORT=8000Note: If you leave SLACK_CHANNEL_ID empty, the bot will respond to messages in all channels where it's been added.
-
Start your LocalBrain daemon:
cd electron/backend python src/daemon.py -
Start the Slack bot:
cd slack-bot python main.py -
Expose with ngrok:
ngrok http 8000
-
Copy the HTTPS URL (e.g.,
https://xyz789.ngrok.io) -
Update Slack Event Subscription URL:
- Go to your Slack app settings
- Navigate to "Event Subscriptions"
- Set Request URL to:
https://xyz789.ngrok.io/slack/events - Wait for the green "Verified" checkmark
In channels, bot responds only when message contains:
- Bot name variations ("localbrain", "local brain", "lb")
- Question indicators ("?", "help", "what", "how", "where", "why", etc.)
- Custom keywords you configure (e.g., "internship", "job", "interview")
- @mentions of the bot
Note: DMs always respond to ALL messages automatically, regardless of keywords.
The bot analyzes the Slack context to determine appropriate tone:
- Workspace name contains "Inc", "Corp", company names → Professional tone
- Channel name contains "work", "team", "project" → Professional tone
- Otherwise → Friendly, conversational tone
- Default → Friendly-professional hybrid
- Maintains last 25 messages in conversation history
- Works across all channels/threads
- Enables follow-up questions
- Thread support for organized conversations
- Signature verification for security
- Background processing to prevent timeouts
- Error handling with user notifications
Use this endpoint for custom Slack app integrations.
Request:
POST http://localhost:8765/protocol/slack/answer
Content-Type: application/json
{
"question": "What was my Meta offer?",
"slack_context": {
"server_name": "ACME Corp Workspace",
"channel_name": "engineering",
"asker_name": "John Doe",
"thread_id": "optional_thread_id"
},
"clear_history": false
}Response:
{
"success": true,
"question": "What was my Meta offer?",
"answer": "I received a Senior Engineer offer from Meta with a $200k base salary...",
"conversation_length": 12
}Webhook endpoint for direct integration with Slack's Events API.
Leave SLACK_CHANNEL_ID empty in .env:
SLACK_CHANNEL_ID=Then invite the bot to any channels you want it to monitor.
Remove message.channels from Event Subscriptions and only keep app_mention.
Add custom keywords in .env:
TRIGGER_KEYWORDS=internship,interview,job,offer,resume,startup,fundingIf your daemon runs on a different machine:
DAEMON_URL=https://your-daemon-server.com:8765- Add agentic capabilities
- Add admin commands (e.g.,
/localbrain status) - Implement caching for frequent queries
- Add analytics and usage tracking
- Support file attachments
- Add reaction-based feedback