I tried LINE Message API (line-bot-sdk-python) on GAE

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.

Settings to enable the Line Message API

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

snip_20161117132901.png

Use Google Cloud Shell

Google Cloud Shell is easy because you can easily work on the browser.

  1. Go to Google Cloud Console.

  2. Click the Cloud Shell icon in the upper right corner. googleshell.png

  3. It will be displayed at the bottom of the screen of Google Cloud Console, so we will work here. shellconsole.png

Bot code

[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

Start work

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? gamen1.png

It is displayed by pressing the "SHOW" button and "ISSUE" button, respectively, in the items below. gamen2.png gamen3.png

And add the required libraries

$ mkdir lib
$ pip install -t lib flask
$ pip install -t lib line-bot-sdk

That's it ^^

Deploy

Deploy by doing the following

$ appcfg.py update .

Finally, set the "Webhook URL" on the LINE developers site.

gamen-new.png

You can edit from the "EDIT" button at the bottom of the screen gamen5.png

That's it! Let's add "friends" from LINE and check the operation! IMG_3855.jpg

Summary

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

Postscript

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

I tried LINE Message API (line-bot-sdk-python) on GAE
I tried using Twitter api and Line api
I tried to notify the honeypot report on LINE
I tried MLflow on Databricks
I tried tensorflow's new Object Detection API on macOS Sierra
I tried AdaNet on table data
I tried to create Quip API
I tried Cython on Ubuntu on VirtualBox
I tried to touch Tesla's API
I tried the Naruro novel API
I tried Line notification in Python
I tried using the checkio API
I tried using the COTOHA API (there is code on GitHub)
I tried using YOUTUBE Data API V3
I stumbled on the Hatena Keyword API
I tried drawing a line using turtle
I tried to make "Sakurai-san" a LINE BOT with API Gateway + Lambda
I tried using UnityCloudBuild API from Python
I tried to touch the COTOHA API
I tried to make a Web API
I tried using the BigQuery Storage API
[LINE Messaging API] I want to send a message from the program to everyone's LINE
I tried using AWS Rekognition's Detect Labels API
I tried hitting the Qiita API from go
I tried "License OCR" with Google Vision API
I tried running YOLO v3 on Google Colab
I tried using the Google Cloud Vision API
I tried to touch the API of ebay
I tried launching jupyter nteract on heroku server
[Pythonocc] I tried using CAD on jupyter notebook
I tried "Receipt OCR" with Google Vision API
I tried playing with the calculator on tkinter
I tried scraping
Twilio on GAE
I tried AutoKeras
I tried papermill
I tried django-slack
I tried Django
I tried spleeter
I tried cgo
I tried Python on Mac for the first time.
I tried running the app on the IoT platform "Rimotte"
I tried to implement Minesweeper on terminal with python
I tried python on heroku for the first time
I tried APN (remote notification) using Parse.com REST API
I tried to uncover our darkness with Chatwork API
I tried using the API of the salmon data project
I tried using PySpark from Jupyter 4.x on EMR
I tried Kaokore, a Japanese classic dataset, on EfficientNet.
I tried installing the Linux kernel on virtualbox + vagrant
I tried to install scrapy on Anaconda and couldn't
I tried hitting the API with echonest's python client