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.
In addition, I referred to the following articles for this verification. Thank you very much.
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.
Apparently it seems to be both feelings.
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.
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
.
(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. ~~
~~~~
That's all for setting up, just add a friend from the QR code and talk with the LINE app.
The environment this time has the following configuration.
The rough processing flow is the following image.
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
(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.) ~~
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.
Recommended Posts