Easy Slackbot with Docker and Errbot

Overview

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.

Preparation

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.

procedure

Build a Docker container

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

Introduction of Errbot

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 !.

Preparing a bot account

Open the here page and select'Make a Custom Integration'.

1.png

Select Create Bots.

2.png

Enter a name for your bot account and click'Add bot integration'.

3.png

The API Token will be displayed on the transition destination screen, so make a note of it.

4.png

This completes the bot account creation. You should be able to find the account you created in the'DIRECT MESSAGES'field.

5.png

Rewriting the configuration file

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

Operation check

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.

6.png

Summary

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

Easy Slackbot with Docker and Errbot
Introduce errBot and work with Slack
Easy modeling with Blender and Python
Let's try gRPC with Go and Docker
Easy! Use gensim and word2vec with MAMP.
Easy web scraping with Python and Ruby
Easy X-Ray with Lambda Layer and CloudFormation / sam-cli
Build PyPy and Python execution environment with Docker
Tftp server with Docker
Easy Grad-CAM with pytorch-gradcam
Easy IoT to start with Raspberry Pi and MESH
goland and Docker settings
From Kafka to KSQL --Easy environment construction with docker
Easy machine learning with scikit-learn and flask ✕ Web app
Easy partial download of mp4 with python and youtube-dl!
How to share folders with Docker and Windows with tensorflow
Use python with docker
Proxy server with Docker
Read and write files with Slackbot ~ Bot development with Python ~
Hello, World with Docker
Easy build of C ++ code with CMake on Docker
Easy face recognition try with Jetson Nano and webcam
Easy debugging with ipdb
With and without WSGI
Easy TopView with OpenCV
[Linux] Create a self-signed certificate with Docker and apache
Easy introduction to home hack with Raspberry Pi and discord.py
Easy to use Nifty Cloud API with botocore and python
I tried follow management with Twitter API and Python (easy)
Package python runtime and pypi library with chef / omnibus and Docker
Build GPU environment with GCP and kaggle official image (docker)
Easy deep learning web app with NNC and Python + Flask
Programming with Python and Tkinter
Encryption and decryption with Python
Easy tox environment with Jenkins
Working with tkinter and mouse
Pomodoro timer made with Errbot
Python and hardware-Using RS232C with Python-
[Co-occurrence analysis] Easy co-occurrence analysis with Python! [Python]
Docker Easy Installation Procedure (CentOS)
Easy folder synchronization with Python
Easy to make with syntax
Easy image classification with TensorFlow
Implement PyTorch + GPU with Docker
PySpark life starting with Docker
Prepare python3 environment with Docker
Easy web scraping with Scrapy
Easy Python compilation with NUITKA-Utilities
Easy HTTP server with Python
Easy proxy login with django-hijack
Super-resolution with SRGAN and ESRGAN
group_by with sqlalchemy and sum
python with pyenv and venv
Try Selenium Grid with Docker
Try building JupyterHub with Docker
With me, NER and Flair
Rails application building with Docker
Make Slack chatbot with Errbot
Works with Python and R
Azure Monitor determines both cloud monitoring and on-premise monitoring! Easy with GUI!
From ubuntu installation to running kinect with docker and ros (overview)