A simple Slack bot built with Flask that listens for Slack events and responds to app mentions. The bot verifies Slack request signatures for security and uses ngrok to expose the local server to the internet during development.
- Verifies Slack request signature using your Slack Signing Secret
- Responds to
app_mentionevents with a friendly greeting - Handles Slack URL verification challenge automatically
- Uses
ngrokfor exposing the local Flask server with a public URL
- Python 3.7 or higher
- Slack App with:
- Bot Token (
SLACK_BOT_TOKEN) - Signing Secret (
SLACK_SIGNING_SECRET)
- Bot Token (
ngrokinstalled or use the Python packagepyngrokpippackage manager
git clone https://github.com/yourusername/slack-bot.git
cd slack-botpython -m venv venvsource venv/bin/activate
venv\Scripts\activate
- Flask
- python-dotenv
- slack-sdk
- pyngrok
You can use this command to download the dependencies in the terminal of you IDE.
pip install Flask python-dotenv slack-sdk pyngrok
Create a .env file in the project root with the following variables:
SLACK_BOT_TOKEN=xoxb-your-bot-token
SLACK_SIGNING_SECRET=your-signing-secret
PORT=3000
Replace the values with your actual Slack app credentials.
Start the Flask app:
python app.py
The script will automatically create a public URL using ngrok and print it in the console, for example:
🌐 Public URL: http://abcd1234.ngrok.io
Use this URL in your Slack app's Event Subscriptions as the Request URL with the suffix /slack/events, e.g.,
http://abcd1234.ngrok.io/slack/events
- Go to your Slack app's Event Subscriptions page.
- Enable Event Subscriptions.
- Set the Request URL to the ngrok URL followed by /slack/events.
- Subscribe to bot events:
- app_mention
- Install or reinstall the app to your workspace.
This app verifies requests from Slack using the signing secret to ensure security. The signature verification helps prevent unauthorized requests.
- If your push to GitHub is blocked due to secret scanning, make sure .env is removed from Git history.
- If ngrok URL changes, update your Slack app Event Subscription URL.
- Ensure your Slack app has the correct OAuth scopes (chat:write, app_mentions:read).
This project is licensed under the MIT License. See the LICENSE file for details.
ForbiddenKiwis