This is a Slack bot that integrates with Netlify. The bot allows users to perform various actions on Netlify deployments directly from Slack, such as listing recent deploys, locking and unlocking a site, rolling back to a previous deploy, and setting the live deploy.
Before running the bot, make sure you have the following set up:
- Python 3.x installed on your machine
- Slack API token: Obtain a Slack API token by creating a new Slack app and going to the
OAuth & Permissions
section, make sure it has thechat:write
Bot Token Scope - Slack signing secret: Can be found under "App Credentials" on the "Basic Information" tab in the Slack app web settings
- Netlify Site ID: Check the site settings on netlify to find the ID for the site you want to control with this bot
- Netlify API token: Generate a Netlify API token from the Netlify account settings
- Clone the repository to your local machine
- Navigate to the project directory
- Create a virtual environment (optional but recommended)
- Install the required Python packages by running the following command:
pip install -r requirements.txt
- Create a
.env
file in the project directory and add the following environment variables:
NETLIFY_API_TOKEN=<Netlify API token>
NETLIFY_SITE_ID=<Netlify site ID>
SLACK_TOKEN=<Slack API token>
SIGNING_SECRET=<Slack signing secret>
- Replace
<Netlify API token>
with your Netlify API token - Replace
<Netlify site ID>
with the ID of your Netlify site - Replace
<Slack API token>
with your Slack API token - Replace
<Slack signing secret>
with your Slack signing secret
The bot supports the following commands:
/list-deploys [numOfDeploys]
: Lists the most recent Netlify deploys.numOfDeploys
is an optional parameter to specify the number of deploys to retrieve (default is 3)./lock
: Locks the Netlify site to prevent further deploys./unlock
: Unlocks the Netlify site to allow deploys./rollback
: Rolls back the Netlify site to the previous deploy./set-live [deployID]
: Sets the live deploy for the Netlify site.deployID
is an optional parameter to specify a specific deploy ID. If not provided, the bot will choose the most recent deploy with a "ready" status.
- Start the bot by running
python3 slack_bot.py
- Use a localhost to web forwarding tool such as
Pinggy.io
,ngrok
,Localtunnel
, orlocalhost.run
- Configure all the
Slash Commands
in the Slack app settings to point to the web endpoint with each command endpoint followed by the command itself. So/lock
command endpoint would behttps://some-endpoint.com/lock
- Install the bot to your Slack workspace
- Add the bot to a channel and start messaging!
Contributions to the project are welcome. If you find any issues or want to add new features, feel free to open a pull request.
If you need help setting this up you can follow this playlist.