Build and Deploy Python Errbot & ChatOps Slack Integration

Santhosh S
3 min readMar 20, 2022

Requirements:

  1. Python3
  2. Access to Slack work space with a user has admin privilege

Create a classic app in Slack:

To integrate our chatbot to slack workspace we need to create a classic app, assuming you have a slack workspace which is already signed in, click on this link to create classic app.

Give a name for your bot and select the workspace in which you want to create it, then click create

2. Click on bots

3. Create user for our bot, by clicking “Add Legacy Bot User”. Give a display name and username for your bot.

4. Next click on OAuth&Permissions, then install the bot in our workspace and click “Allow” in next page. It will generate a User OAuth Token and Bot User OAuth Token, make of note of it

Python Installation and setting up virtual environment:

Make sure you have python3 installed, and then follow the steps mentioned below.

# Update and Upgrade
sudo apt update
sudo apt -y upgrade
# Install pip and other additional tools
sudo apt install -y python3-pip
sudo apt install build-essential libssl-dev libffi-dev python3-dev
sudo apt install -y python3-venv
# Create Virtual environment
sudo mkdir /opt/chatbot
cd chatbot
python3 -m venv my_bot
source my_bot/bin/activate
(my_bot) ubuntu@ubuntu:/opt/chatbot$

after activating the virtual environment, install the errbot using pip and initiate the bot .

sudo pip install errbot
sudo mkdir -p /opt/chatbot/backend
cd /opt/chatbot
sudo errbot --init

It will create the basic bot folder structure and config.py file inside /opt/chatbot directory. To make integration of our bot to slack we need to configure the config.py according to it.

Edit the config.py file and add the below content, BACKEND will be defined already as ‘Text’ replace it to ‘SlackV3' and paste the Bot User OAuth Token in token field.

BACKEND=”SlackV3"
BOT_EXTRA_BACKEND_DIR=”/opt/chatbot/backend”
BOT_IDENTITY = {
‘token’: ‘xoxb-****’,
}

Next step is to install the required extra plugin for SlackV3 backend

cd /opt/chatbot/backend
git clone https://github.com/errbotio/err-backend-slackv3
pip install -r /opt/chatbot/backend/err-backend-slackv3/requirements.txt

If all the above steps completed, then we’re only few steps behind to make our bot work.

cd /opt/chatbot
#activate our bot and make it run in background
sudo errbot --daemon

Now got to you slack workspace, in apps section you can see your bot name. Open it and try commands like ‘!tryme’ , ‘!help’. We can also define our customized commands and response.

--

--