Slack ChatBot with shortcuts forms support and Azure Boards integration.
- bot: source code main directory
- handlers: source for manage libs events like a new message received
- libs: source for third party libs like slack-bolt Slack client
- templates: Bot templates like Slack modal views, see Block Kit Builder, and AzureDevops payloads
- tests: source for code unit tests
- config.py: file that manages bot base configurations
- main.py: file that starts all necessary codes to run the bot
- requirements.txt: file with python required libs to run the bot
- Dockerfile: file to build a docker container to run the bot
.
|-- bot
| |-- handlers
| | `-- slack
| | |-- handle_messages.py
| | |-- handle_reactions.py
| | `-- handle_shortcut_support.py
| |-- libs
| | |-- az_devops_client.py
| | `-- slack_app.py
| |-- templates
| | |-- azure_devops
| | | |-- cloud-team.j2
| | | |-- devops-team.j2
| | | `-- test.j2
| | `-- slack
| | |-- cloud_shortcut_support.json
| | `-- devops_shortcut_support.json
| |-- config.py
| `-- main.py
|-- tests
| `-- unit
| |-- handlers
| | `-- slack
| | |-- test_handle_message.py
| | `-- test_handle_shortcut_support.py
| `-- libs
| |-- test_az_devops_client.py
| `-- test_slack_app.py
|-- app-manifest.yml
|-- azure-pipelines.yml
|-- Dockerfile
|-- README.md
`-- requirements.txt
- Creating a python virtual environment:
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
# Load environment varibles
export AZ_DEVOPS_ORGANIZATION_URL=https://dev.azure.com/my_org \
AZ_DEVOPS_PERSONAL_ACCESS_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
SLACK_BOT_TOKEN=xoxb-xxxxxxxxxxxx-xxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxx \
SLACK_SIGNING_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# Start the bot locally
gunicorn --bind 0.0.0.0:5000 --reload bot.main:app
On another terminal run:
# Exposing a public url for our locally running bot
pip install ngrok
ngrok http 5000
It's recommended to create a new Slack Workspace to get full control for manage the bot installation and configuration.
- Copy the url generated by ngrok and configure it in the app created.
- Add /slack/events to the url, example: http://710723d67ad9.ngrok.io/slack/events
- Create a new Global Shortcut with Name = suporte and Callback ID = suporte
- Turn on Enable Events option and paste in the url input the same ngrok url as above
- In Bot Token Scopes add the following scopes:
- app_mentions:read
- channels:history
- channels:read
- chat:write
- commands
- incoming-webhook
- reactions:write
- users:read
- reactions:read
- usergroups:read
- Go to Install App and install the bot app in your Slack Workspace.
- Open Slack, go to the Workspace where the Bot was installed, create a channel and invite the bot to the channel.