If you mention the bot created with slack and talk with the specified wording Linked to the wording spoken by the lightweight web framework bottle Returns information. The returned information will be posted to slack. Also, you can get the same information by accessing bottle with http, so You don't have to go through slack.
When you talk to magi_casp with mention, It returns the information in JSON. In this example I love[A|B|C|D|E|F|G|H]On the condition If you enter the letters A to H after I love, It returns JSON according to the alphabet.
When you mention tenki
to magi_casp,
It will return the weather for the day and the next day.
I do not understand. While studying bottle and slackbot, remembering docker a little I came up with the idea that it could be used in this way.
--Since docker is used, you need a server to host docker. The host OS is centos7. --There are 2 containers. --Container that runs slackbot --The container that runs the bottle ――I make it in Sakura's cloud. It is a plan of 7 yen per hour with 1 core 1 GB in the Ishikari region. --Assuming that the server on which docker runs is ready. --You have already added the Bot Integration to slack.
Execute the following command to clone the git repository created by the author.
git clonehttps://github.com/tomokitamaki/slackbotWithbottle.git
## Create an image using Dockerfile
1. Create a file that describes the Bot API token.
In the folder called slackbot_bottle in the clone
Create a file called APITOKEN.py in a folder called slackbot.
#### **`vi APITOKEN.py`**
```py
Describe the Bot API token in the following format.
```apiapi = "api token"
Example) API API= "apitoookennnn"
build_slackbot_dockerfile
Because there is a docker fie called
Move to the directory where the file is located and execute it with the following build command.centos7 build_slackbot_Dockerfile .
This will create an image. You can confirm that the image is created by executing the following command.
```sudo docker images```
2. Create an image of the container that moves the bottle
In the folder called bottle in the folder called slackbot_bottle in the clone,
```build_bottle_dockerfile```Because there is a docker fie called
Move to the directory where the file is located and execute it with the following build command.
#### **`centos7 build_bottle_Dockerfile . `**
```sudo docker build -t slackbot
This will create an image. You can confirm that the image is created by executing the following command.
```sudo docker images```
## Launch the container from the image
1. Start the container from the slackbot image.
Start with the following command.
#### **`centos7`**
```sudo docker run -d --name slackbot slackbot
2. Start the container from the image of bottle.
Start with the following command.
`sudo docker run -d -p 3333:80 --name bottle bottle:centos7`
Since the bottle is listening on port80, the communication addressed to prt3333 of the host OS is connected to port80 of the container.
# Mention the bot.
Mention the bot and talk to tenki,
```How is the weather today("Cloudy"),Tomorrow's weather("Partially cloudy")```
If it comes back, it's OK.
# Take a look in your browser
`http: // server IP: 3333 / tenki / tenki`
Access with
```How is the weather today("Cloudy"),Tomorrow's weather("Partially cloudy")```
It is perfect when it comes back.
# end
If you do so far, it will return the weather and JSON that links the word and the alphabet,
You will be able to use the BOT and the bottle that works with it.
Please also see the README below.
https://github.com/tomokitamaki/slackbotWithbottle
# development
If you add to the file in the plugins folder, you can increase the variation of the reply,
You can do something a little more complicated by writing python code in hello_world.py.
TIPS
-[Stumbling] When communication from the slackbot container to the bottle container is not possible.
Described in the file that defines the bot mention in the plugins folder,
It didn't work if the URL was the host OS's global IP: port number (ex: http: // server IP: 3333), so
It worked fine if I made the IP the container's local IP instead of the host's global IP.
--How to install bottle
Please proceed from the 2. Bottle installation section of http://tech.aainc.co.jp/archives/9826 to the end of the page.
--How to install slackbot
From the section on building a Slack Bot environment at http://blog.bitmeister.jp/?p=3892 to [Making a Slack bot (2)](http://blog.bitmeister.jp/?p=3911) in Python Proceed, please.
It's very easy to understand.
Recommended Posts