A dead-simple Slack bot built with Bolt for Python. No Docker, no complexity, just python main.py.
/pingslash command β Responds with "Pong!"- "hello" message listener β Detects "hello" (case-insensitive) and responds with "Hey there!"
/add-allslash command β Adds all workspace members to the channel with confirmation
# 1. Clone and setup
cd PWRUP_slack_bot
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
# 2. Configure environment
cp .env.example .env
# Edit .env with your Slack tokens (see Setup Guide below)
# 3. Run the bot
python main.py- Go to https://api.slack.com/apps
- Click "Create New App" β "From scratch"
- Name it (e.g., "PWRUP Bot") and select your workspace
- Click "Create App"
-
In your app settings, go to "OAuth & Permissions"
-
Scroll to "Scopes" β "Bot Token Scopes"
-
Add these scopes:
chat:write- Send messagescommands- Use slash commandschannels:history- Read messages in public channelsgroups:history- Read messages in private channelsim:history- Read direct messagesmpim:history- Read group messagesusers:read- List workspace memberschannels:read- Read channel infochannels:manage- Invite users to channelsgroups:write- Invite users to private channels
-
Scroll up and click "Install to Workspace"
-
Authorize the app
-
Copy the "Bot User OAuth Token" (starts with
xoxb-)- Save this as
SLACK_BOT_TOKENin your.envfile
- Save this as
- Go to "Basic Information" in your app settings
- Scroll to "App Credentials"
- Copy the "Signing Secret"
- Save this as
SLACK_SIGNING_SECRETin your.envfile
- Save this as
- Go to "Slash Commands" in your app settings
- Click "Create New Command" for
/ping:- Command:
/ping - Request URL:
https://your-domain.com/slack/events - Short Description: "Ping the bot"
- Command:
- Click "Create New Command" for
/add-all:- Command:
/add-all - Request URL:
https://your-domain.com/slack/events - Short Description: "Add all workspace members to this channel"
- Command:
- Go to "Event Subscriptions" in your app settings
- Toggle "Enable Events" to ON
- Request URL:
https://your-domain.com/slack/eventsβ οΈ You need to deploy your bot first before Slack can verify this URL
- Scroll to "Subscribe to bot events"
- Add these events:
message.channels- Messages in public channelsmessage.groups- Messages in private channelsmessage.im- Direct messagesmessage.mpim- Group messages
- Click "Save Changes"
# Update system
sudo apt update && sudo apt upgrade -y
# Install Python 3 and pip
sudo apt install python3 python3-pip python3-venv curl -y# On your Ubuntu server
cd /opt
sudo git clone https://github.com/PinewoodRobotics/SlackBot.git
cd SlackBot
# Or upload files manually with scp:
# scp -r /path/to/PWRUP_slack_bot user@your-server:/opt/SlackBotcd /opt/SlackBot
sudo python3 -m venv venv
sudo chown -R $USER:$USER venv
source venv/bin/activate
pip install -r requirements.txt# Create .env file
cp .env.example .env
nano .env
# Add your tokens:
# SLACK_BOT_TOKEN=xoxb-your-actual-token
# SLACK_SIGNING_SECRET=your-actual-secret
# PORT=3000# Run manually to test
python main.py
# You should see: β‘οΈ Slack bot is starting on port 3000...
# Press Ctrl+C to stop# Create service file
sudo nano /etc/systemd/system/slackbot.servicePaste this content:
[Unit]
Description=PWRUP Slack Bot
After=network.target
[Service]
Type=simple
User=ubuntu
WorkingDirectory=/opt/SlackBot
Environment="PATH=/opt/SlackBot/venv/bin"
EnvironmentFile=/opt/SlackBot/.env
ExecStart=/opt/SlackBot/venv/bin/python main.py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.targetNote: Change User=ubuntu to your actual username if different.
# Enable and start the service
sudo systemctl daemon-reload
sudo systemctl enable slackbot
sudo systemctl start slackbot
# Check status
sudo systemctl status slackbot
# View logs
sudo journalctl -u slackbot -f# Install Cloudflare Tunnel
curl -L --output cloudflared.deb https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
sudo dpkg -i cloudflared.deb
rm cloudflared.deb
# Authenticate with Cloudflare
cloudflared tunnel login
# Create a tunnel (replace 'slackbot' with your preferred name)
cloudflared tunnel create slackbot
# Get your tunnel ID from the outputCreate config file at ~/.cloudflared/config.yml:
tunnel: slackbot
credentials-file: ~/.cloudflared/<YOUR-TUNNEL-ID>.json
ingress:
- hostname: your-domain.com
service: http://localhost:3000
- service: http_status:404Create systemd service for tunnel:
sudo nano /etc/systemd/system/cloudflared.service[Unit]
Description=Cloudflare Tunnel
After=network.target
[Service]
Type=simple
User=ubuntu
ExecStart=/usr/local/bin/cloudflared tunnel --config ~/.cloudflared/config.yml run slackbot
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.targetsudo systemctl daemon-reload
sudo systemctl enable cloudflared
sudo systemctl start cloudflared
sudo systemctl status cloudflaredNow go back to your Slack app settings:
- Event Subscriptions β Request URL:
https://your-domain.com/slack/events - Slash Commands β
/pingβ Request URL:https://your-domain.com/slack/events - Click "Save Changes"
Slack will verify the URL (should show a green checkmark β)
In any Slack channel where the bot is added:
/ping
Expected response: Pong!
In any channel where the bot is added:
hello
Hello
HELLO
hey hello there
Expected response: Hey there <@your_username>!
In any channel where the bot is added:
/add-all
Expected: Ephemeral message (only visible to you) showing all members to be added with Confirm/Cancel buttons. Click Confirm to add them all.
# View bot logs
sudo journalctl -u slackbot -f
# Restart bot
sudo systemctl restart slackbot
# Stop bot
sudo systemctl stop slackbot
# Check bot status
sudo systemctl status slackbot
# Update code and restart
cd /opt/SlackBot
git pull
sudo systemctl restart slackbot- Check if service is running:
sudo systemctl status slackbot - Check logs:
sudo journalctl -u slackbot -f - Verify Slack slash command URL is correct
- Make sure bot is installed in your workspace
- Make sure bot is invited to the channel:
/invite @YourBotName - Check Event Subscriptions are enabled
- Verify bot has correct scopes (see Step 2)
- Check logs for errors
- This happens when Slack can't verify your URL
- Make sure bot is running:
sudo systemctl status slackbot - Make sure tunnel is running:
sudo systemctl status cloudflared - Verify tunnel is connected:
sudo journalctl -u cloudflared -f - Check bot is responding:
curl https://your-domain.com/slack/events
# Find what's using port 3000
sudo lsof -i :3000
# Kill the process or change PORT in .env# Check tunnel status
sudo systemctl status cloudflared
# View tunnel logs
sudo journalctl -u cloudflared -f
# Restart tunnel
sudo systemctl restart cloudflared
# List active tunnels
cloudflared tunnel listPWRUP_slack_bot/
βββ main.py # Main bot code
βββ requirements.txt # Python dependencies
βββ .env.example # Environment template
βββ .env # Your actual config (git-ignored)
βββ .gitignore # Git ignore rules
βββ README.md # This file
- Never commit
.envto git (it's in.gitignore) - Keep your tokens secret
- Use HTTPS in production (handled by certbot)
- Slack automatically verifies requests using the signing secret
You now have a production-ready Slack bot running on your Ubuntu server. No Docker, no complexity, just Python.
Questions? Check the logs: sudo journalctl -u slackbot -f