Following the announcement of LINE BOT AWARDS, I also tried the Line Message API. I started with a light feeling of trying to make a LINE bot using machine learning. GAE seemed to be compatible with LINE Bot, so I used it.
[Click here] Make settings by referring to (https://bita.jp/dml/line-messaging-api-exp).
The bot settings below may require some attention. I'm wondering how you set it up.
Google Cloud Shell is easy because you can easily work on the browser.
Go to Google Cloud Console.
Click the Cloud Shell icon in the upper right corner.
It will be displayed at the bottom of the screen of Google Cloud Console, so we will work here.
[line-bot-sdk-python] I implemented it while looking at GitHub of (https://github.com/line/line-bot-sdk-python).
However, GAE needs to use the URLFetch API to send requests to the outside world. .. I was wondering how to solve it here It was very helpful to have someone who gave me a code close to the image. Referenced code
The completed code is below. https://github.com/mochan-tk/line-bot-python-sample
From here, let's work with Google Cloud Shell.
First, clone the code from GitHub
$ git clone https://github.com/mochan-tk/line-bot-python-sample.git
Move the folder
$ cd line-bot-python-sample
Modify the app.yaml project to suit your environment
$ vi app.yaml
Set the Secret key and Access Token in the file below
$ vi config.py
The Secret key and Access Token are on the LINE developers site, right?
It is displayed by pressing the "SHOW" button and "ISSUE" button, respectively, in the items below.
And add the required libraries
$ mkdir lib
$ pip install -t lib flask
$ pip install -t lib line-bot-sdk
That's it ^^
Deploy by doing the following
$ appcfg.py update .
Finally, set the "Webhook URL" on the LINE developers site.
You can edit from the "EDIT" button at the bottom of the screen
That's it! Let's add "friends" from LINE and check the operation!
With GAE, you can get fully managed services, so you can concentrate on development. I am grateful that I can use functions such as Task Queue.
Regarding the Bot code, I think that there is logic that can be used in common except for the core processing. In order to create a better LINE Bot, I would like to share the code as much as possible and do my best to help other developers.
This time it's until the bot really works, but I'm thinking of implementing detailed processing including machine learning from here! Continue. .. ..
2016/11/20 (Sun) 14:00
When you press the "VERIFY" button on the LINE developers site, the server log You should see the LineBotApiError [Invalid reply token] message. When I checked with LINE, the processing of "VERIFY" is mainly for communication confirmation, so up to the consistency of Token It is a process that is not conscious (?), So it is sent to the server by response processing from the LINE application If there was no error message in this case, there seemed to be no problem. We have received several inquiries regarding this matter, so we have decided to revise it. It seems that it will disappear soon.
Recommended Posts