Run chatbot with Docker in local environment I tried to interact with Slack.
I was worried about Hubot made by GitHub and Lita made by Ruby. It was troublesome to read CoffeeScript and prepare for Redis. I chose Errbot, which is written in Python and seems to be the simplest. I don't think there is a big difference in the feeling of a quick survey.
There is no problem in any environment where Docker containers work. I'm building it on my local PC using Docker for Mac.
If you want to create a Slackbot, you need to prepare your team in advance.
Build a container that runs Python version 3.3 and above. To save labor, I used Alpine Linux with Python.
FROM python:3.5.2-alpine
#apk update
RUN apk update
#Installation of packages required to install Errbot
RUN apk add gcc g++ libffi-dev openssl-dev
#Install the packages required for development as you like
RUN apk add vim bash
Enter the following in the directory containing Dockerfile
to start the container.
Start container
#Generate an image from a Dockerfile with the name bot
$ docker build -t bot .
#Launch the bot image and/bin/run sh
$ docker run -it bot /bin/sh
Use pip
to install the required packages.
ʻSlack client is required for communication between the main body of ʻerrbot
and Slack.
Package installation
$ pip install errbot slackclient
When you're done, check to see if you've successfully installed. It depends on a good number of packages ...
Check the package
$ pip freeze
ansi==0.1.3
beautifulsoup4==4.5.1
bottle==0.12.9
cffi==1.8.3
colorlog==2.7.0
cryptography==1.5.2
daemonize==2.4.7
dnspython==1.14.0
dnspython3==1.14.0
errbot==4.3.3
idna==2.1
Jinja2==2.8
Markdown==2.6.7
MarkupSafe==0.23
pyasn1==0.1.9
pycparser==2.14
Pygments==2.1.3
pygments-markdown-lexer==0.1.0.dev39
pyOpenSSL==16.1.0
requests==2.11.1
rocket-errbot==1.2.5
six==1.10.0
slackclient==1.0.2
threadpool==1.3.2
waitress==1.0.0
WebOb==1.6.1
websocket-client==0.37.0
WebTest==2.0.23
Yapsy==1.11.223
After successful installation, try running First run. Initialize the project directory with the following command.
Project initialization
$ mkdir ~/errbot-root
$ cd ~/errbot-root
$ errbot --init
Several files have been created to configure and run the bot.
Let's start ʻerrboton the console immediately. When you see
>>>, try typing
! Tryme`.
You should get a response from the bot.
Run on console
$ errbot
>>> !tryme
It works !
Apparently, Errbot prefixes the instructions to the bot with !
.
Open the here page and select'Make a Custom Integration'.
Select Create Bots.
Enter a name for your bot account and click'Add bot integration'.
The API Token will be displayed on the transition destination screen, so make a note of it.
This completes the bot account creation. You should be able to find the account you created in the'DIRECT MESSAGES'field.
Rewrite the config.py
created by ʻerrbot --init`.
There are three main changes. There is no problem with other items as they are.
config.py
#Fixed BACKEND from Text to Slack
BACKEND = 'Slack'
#Enter the API Token mentioned above
BOT_IDENTITY = {
'token': 'xxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
}
#Enter the account name of the user you want to be admin in the form of a tuple (s)
BOT_ADMINS = ('@nanakenashi')
The token is written in solid form for explanation. When managing the source with GitHub etc., embed it in the environment variable I think it is desirable to read it with ʻos.getenv ('HOGE')`.
After saving, start Errbot again. This time I will add a daemon option.
Launch Errbot
$ errbot --daemon
Talk to ! Tryme
,! Help
, ! About
, etc. on Slack.
It should work as it does on the console.
We recommend that you change the icon of your bot account to something that you can love.
Although it was quite a trial content You can now talk to Slack bots.
Because the true value of chatbot is flexible movement to instructions Next, I would like to touch on that part (plug-in).
Recommended Posts