A Slack chatbot that can respond to messages and answer general FAQs.
-
Create a Slack App at https://api.slack.com/apps
- Enable Socket Mode
- Add bot token scopes:
chat:write
,app_mentions:read
,channels:history
,im:history
- Install the app to your workspace
-
Set up your environment:
# Clone the repository git clone <repository-url> cd chatbot # Create and activate virtual environment (optional but recommended) python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate # Install dependencies pip install -r requirements.txt # Copy example environment file and update with your Slack credentials cp .env.example .env
-
Update the
.env
file with your Slack credentials:SLACK_BOT_TOKEN
: Your bot's OAuth token (starts withxoxb-
)SLACK_SIGNING_SECRET
: Your app's signing secretSLACK_APP_TOKEN
: Your app-level token (starts withxapp-
)
-
Start the Flask server:
python app.py
-
Use a tool like ngrok to expose your local server:
ngrok http 5000
-
Update your Slack App's Event Subscriptions URL with the ngrok URL +
/slack/events
(e.g.,https://your-ngrok-url.ngrok.io/slack/events
)
- Responds to messages in channels where the bot is invited
- Basic message processing functionality
- Extensible architecture for adding more features
To add new bot responses or features:
- Modify the
process_message()
function inapp.py
- Add your custom logic for handling different message types
- Test the new functionality in your Slack workspace
Feel free to submit issues and enhancement requests!