Checkpoint when you get hooked on LINE parrot return bot on Heroku

It's a mess of rubbing, but ** I was confused by old information on the net and crushed it for half a day with a parrot return bot **, so I'll write it down with remorse.

environment

Create account ~ Deploy to Heroku

First, the following steps were performed.

For specific procedures and code, I referred to qiita articles and blog articles that appear when searching for "LINE bot Python". The following blog articles were organized in an easy-to-understand manner in the reference, so I will omit the detailed procedure here.

Create a LINE Bot with LINE Messaging API + Python + Heroku

However, as described later, ** the latest specifications do not require the "Fixie" setting **, so please be careful. (Not limited to this blog article, there are some articles that are ranked high in the search and still write that Fixie setting is mandatory.)

...... Well, I implemented it like this and talked to the bot, but it does not return the parrot.

Checkpoint 1: Countermeasures against 500 errors that appear with the Verify button on the Webhook

When I pressed the Verify button of the Webhook URL on the LINE Developers management screen to check it, the error message "The webhook returned an HTTP status code other than 200" appeared.

verify.png Check the logs with `heroku logs -t`. The main.py (bot app) was running and seemed to return a 500 error. This seems to determine that the replyToken sent by the Verify button is not a valid replyToken. The reference article is below.

About the error when checking the connection of the LINE Developers Webhook URL

After adding the code referring to this article, the request from the Verify button is now accepted.

Checkpoint 2: Turn on Use Webhook

However, even if I send "A" or "Test" on my smartphone, the log does not work at all. ...... No, isn't it too much a mistake? It's like that, but Use Webhook was turned off. When I turned it on, the request was sent.

usewebhook.png

Checkpoint 3: No need to specify an IP address with the latest specifications

But you can't connect with this IP address! I get the error. I will write in detail in "Supplement" below, but an error occurred because the Fixie setting failed.

When making a LINE bot on Heroku, set Fixie anyway! There are a lot of articles that say, but as you can see in the official FAQ below, ** The latest specifications do not require you to specify an IP address. So you don't have to use Fixie in the first place. ** **

LINE BOT & Beacon Developer FAQ (updated from time to time)

Do I have to register the Server IP Whitelist?

No need to register.

If you want to put restrictions, just register.

If you specify it the other way around, only that IP will be accessible, so if you get an error, make sure that the wrong IP address is not in this list.

IP.png

Supplement about checkpoint 3

Even if you have Fixedie's outbound IP in the list, it's okay if you can connect correctly from there. In my case, even though I set Fixie, I could not send a request from the fixed IP, and when I look at the error log

"message": "Access to this API denied due to the following reason: Your ip address [*.**.***.***] is not allowed to access this API. Please add your IP to the IP whitelist in the developer center."

(The [*. **. ***. ***] part changes every time the app is restarted). Probably because the code of the bot app itself did not include the description for using the proxy.

The following is a reference article for PHP. I think there is probably an equivalent description in Python, but I won't go into it this time. .. ..

[50: LINE BOT API] Parrot BOT with PHP + Heroku

The description that PHP goes through proxy was missing. I set the URL of the proxy created by Fixie with curl_setopt and it worked fine.

Digression

The default message "Thank you for your message! Sorry, this account does not accept individual inquiries. Please wait for the next delivery" message is LINE Official Account Manager Response Settings> Advanced Settings> It should be turned off as appropriate in the response message (I thought it was coming out because of an error at first ...).

Recommended Posts

Checkpoint when you get hooked on LINE parrot return bot on Heroku
Make a parrot return LINE Bot on AWS Cloud9
Parrot return LINE BOT creation
[Python] [LINE Bot] Create a parrot return LINE Bot
If you get stuck when building pycocoapi on Windows
If you get hooked on pip install dlib on OSX
Solution if you crash when using selenium on heroku
[LINE Messaging API] Create parrot return BOT with Python
I get [Error 2055] when trying to connect to MySQL on Heroku