I tried to make my own high school girl BOT with Rinna style with LINE BOT (Python & Heroku)

It seems that the Server IP Whitelist of LINE BOT has become Optional, so I removed the part of Heroku's Fixie Addon setting and Server IP Whitelist setting from the procedure in the article. It should work even if you set Fixie + Server IP Whitelist separately.

[[Good news] LINE BOT's Server IP Whitelist has become Optional-Memorandum of Niwaka Server Shop](http://architect.hatenadiary.jp/entry/2016/05/18/%E3%80%90 % E6% 9C% 97% E5% A0% B1% E3% 80% 91LINE_BOT_% E3% 81% AE_Server_IP_Whitelist_% E3% 81% 8COptional% E3% 81% AB% E3% 81% AA% E3% 81% A3% E3 % 81% A6% E3% 81% 9F_1)


The BOT area is very exciting. The LINE BOT API opened on a first-come, first-served basis on April 7th last week, so I tried to verify it.

[LINE] Prior to the opening of the messaging API, the "BOT API Trial Account", which allows the first 10,000 people to freely develop BOT accounts, is now available free of charge.| LINE Corporation |news

In addition, I referred to the following articles for this verification. Thank you very much.

Overview

Your own high school girl-style Bot Linna will become your LINE friend and endlessly chat with you on LINE. The dialogue mechanism uses DoCoMo's chat dialogue API. The chat dialogue API specifies the Kansai dialect high school girl character (Sakurako?), So I feel like it looks like that. The image is also a high school girl free material I got from Pakutaso, so the atmosphere is perfect.

The following is an operation image. IMG_4208.PNG

Apparently it seems to be both feelings.

How to use

With Heroku, anyone can deploy with just one click, just by preparing a Heroku button. Heroku is amazing!

However, the following accounts are required to actually operate. Create an account before deploying.

After preparing these, please press the Heroku button from the link below.

shiraco/linnabot

When you click the deploy button, you will be asked for the name of the application, API KEY for each LINE / DoCoMo, etc., so log in to the dashboard for each LINE / DoCoMo and enter the confirmed contents.

After confirming that the deployment was successful, reopen the LINE dashboard from the following and set as follows.

https://developers.line.me/channels/

Maybe it will be https://YOUR_APP_NAME.herokuapp.com:443/callback.

linnabot2.png

(It seems that Server IP Whitelist is now Optional, so the following is unnecessary)

~~ * Set heroku's fixie outboud ip address x 2 to LINE's Server IP Whitelist ~~

~~ Fix the connection source IP when calling the LINE API with fixie and set to allow it on the LINE side. ~~

~~linnabot1.png~~

That's all for setting up, just add a friend from the QR code and talk with the LINE app.

What I wanted to verify

System configuration

The environment this time has the following configuration.

The rough processing flow is the following image.

linna-archi.png

In terms of processing, in response to something being spoken on LINE, callback is called and the utterance content is thrown to DoCoMo's chat API.

bot.py(Excerpt&Modification)


    def on_post(self, req, resp):

        body = req.stream.read()
        receive_params = json.loads(body.decode('utf-8'))

        for msg in receive_params['result']:

            docomo_res = self.docomo_client.send(utt=msg['content']['text'],  #User's utterance content
                                                 apiname='Dialogue')
            send_content = {
                'to': [msg['content']['from']],
                'toChannel': 1383378250,  # Fixed value
                'eventType': '138311608800106203',  # Fixed value
                'content': {
                    'contentType': 1,
                    'toType': 1,
                    'text': docomo_res['utt'],  #The utterance content of the chat API
                },
            }
            send_content = json.dumps(send_content)

            header = {
                'Content-Type': 'application/json; charset=UTF-8',
                'X-Line-ChannelID': os.environ['LINE_CHANNEL_ID'],
                'X-Line-ChannelSecret': os.environ['LINE_CHANNEL_SECRET'],
                'X-Line-Trusted-User-With-ACL': os.environ['LINE_CHANNEL_MID'],
            }

            #It seems that Server IP Whitelist is now Optional, so you don't need to specify proxies anymore!
            # PROXIES = {'http': os.environ.get('FIXIE_URL', ''), 'https': os.environ.get('FIXIE_URL', '')}
            # res = requests.post(ENDPOINT_URI, data=send_content, headers=header, proxies=PROXIES)
            res = requests.post(ENDPOINT_URI, data=send_content, headers=header)

            resp.body = json.dumps('OK')

See the code below for more details if needed. shiraco/linnabot

Where I was addicted

(It seems that Server IP Whitelist is now Optional, so the following is unnecessary)

~~ When you go to hit the LINE BOT API, you need to set Heroku's addon fixie to the proxy. As mentioned above, set http_proxy & https_proxy using FIXIE_URL which is automatically set in the environment variable of Heroku when addon is added. (http_proxy may not be needed for this purpose.) ~~

Summary

I just connected the chat API to LINE's BOT API this time, but the chat interface is very user-friendly and looks attractive because it has the potential to be used by a large number of people.

In Trial, I feel that the main use is as a personal assistant, such as being able to create only one bot or not being able to invite to the LINE group, but LINE, a major messaging platform, provides a BOT platform. I feel great potential for having started. It is easy to imagine that restrictions will be relaxed in the future and various BOT apps will be born. Keep an eye on future trends.

You can see that nearly 30 posts have been posted to Qiita's linebot tag in 3 to 4 days.

reference

Recommended Posts

I tried to make my own high school girl BOT with Rinna style with LINE BOT (Python & Heroku)
I tried to make "Sakurai-san" a LINE BOT with API Gateway + Lambda
I tried to make my own source code compatible with Chainer v2 alpha
I made a LINE BOT with Python and Heroku
I tried to make various "dummy data" with Python faker
I tried to make GUI tic-tac-toe with Python and Tkinter
I tried to make the weather forecast on the official line by referring to the weather forecast bot of "Dialogue system made with python".
[Python] Make your own LINE bot
I want to know the weather with LINE bot feat.Heroku + Python
[3rd] I tried to make a certain authenticator-like tool with python
I tried to make a periodical process with Selenium and Python
I tried to make a 2channel post notification application with Python
[Introduction] I want to make a Mastodon Bot with Python! 【Beginners】
I tried to make a todo application using bottle with python
[4th] I tried to make a certain authenticator-like tool with python
[1st] I tried to make a certain authenticator-like tool with python
I tried to make an image similarity function with Python + OpenCV
Python: I tried to make a flat / flat_map just right with a generator
Python beginners decided to make a LINE bot with Flask (Flask rough commentary)
[AWS] [GCP] I tried to make cloud services easy to use with Python
I tried to make a traffic light-like with Raspberry Pi 4 (Python edition)
[Zaif] I tried to make it easy to trade virtual currencies with Python
Make a Twitter trend bot with heroku + Python
I want to make a game with Python
I tried to get CloudWatch data with Python
I tried to output LLVM IR with Python
I tried to automate sushi making with python
I tried to operate Linux with Discord Bot
I tried to make a simple mail sending application with tkinter of Python
[Patent analysis] I tried to make a patent map with Python without spending money
I tried to refactor the code of Python beginner (junior high school student)
I tried to automatically send the literature of the new coronavirus to LINE with Python
I tried to make a real-time sound source separation mock with Python machine learning
I tried to implement Minesweeper on terminal with python
I tried to get started with blender python script_Part 01
I tried to touch the CSV file with Python
I tried to draw a route map with Python
I tried to put out the frequent word ranking of LINE talk with Python
I tried to solve the soma cube with python
Continuation ・ I tried to make Slackbot after studying Python3
I tried to get started with blender python script_Part 02
I tried to implement an artificial perceptron with python
You can drink Zoom! !! I tried to make a just one style cooperative theme guessing game with Flask + Heroku
I tried to automatically generate a password with Python3
A Python beginner made a chat bot, so I tried to summarize how to make it.
I tried to solve the problem with Python Vol.1
I tried to analyze J League data with Python
I tried to make an OCR application with PySimpleGUI
[Super easy] Let's make a LINE BOT with Python.
I tried to solve AOJ's number theory with Python
[Python] I tried to make an application that calculates salary according to working hours with tkinter
I tried to make a generator that generates a C # container class from CSV with Python
I tried various methods to send Japanese mail with Python
I tried to notify the train delay information with LINE Notify
I published my own Python baseball library to Packaging & PyPI
[Python] I tried to visualize tweets about Corona with WordCloud
[Python] I asked LINE BOT to answer the weather forecast.
Mayungo's Python Learning Episode 3: I tried to print numbers with print
I want to send a message from Python to LINE Bot
I tried to make a stopwatch using tkinter in python
I tried to divide the file into folders with Python