LINEbot development, I want to check the operation in the local environment

This article ** Somehow push to heroku every time I check it! !! ** For those who think.

Operating environment

The meaning of using heroku

Before solving the problem, think about why you were using heroku in the first place. LINEbot and heroku were connected via an access token, secret key and ** webhook URL **. "Figure" Once a heroku app is published (deployed), it can have a URL (~ herokuapp.com). This is the one I use as the ** webhook URL **. I wish I could ** prepare this webhook URL by myself **, but I can't ** easily **. So I had no choice but to deploy and use heroku to get the URL of the app (but not only).

Then what to do

** Publish your localhost ** to the outside world ** without using heroku. By doing this, you can prepare a webhook URL. (I'm wondering if it's safe to publish localhost, but I'll leave it.) The tool I use is ** ngrok **.

How to do

Download the zip file with the red button on the ngrok official website Screenshot from 2020-02-19 03-45-22.png

Next, use the following command to decompress and check the version.

ngrok installation


cd ~/Downloads
unzip ngrok-stable-linux-amd64.zip
sudo cp ngrok /usr/bin/
ngrok version

You can now use ngrok. When actually using

Published externally on ngrok


ngrok http [port number]

The [port number] of the local server is exposed to the outside.

ngrok execution result


ngrok by @inconshreveable    (Ctrl+C to quit)
Session Status                online
Session Expires               7 hours, 59 minutes
Version                       2.3.35
Region                        United States (us)
Web Interface                 http://127.0.0.1:☓☓☓☓
Forwarding                    http://☓☓☓☓☓☓☓☓.ngrok.io -> http://localhost:5000 
Forwarding                    https://☓☓☓☓☓☓☓☓.ngrok.io -> http://localhost:5000
Connections
ttl     opn     rt1     rt5     p50     p90
0       0       0.00    0.00    0.00    0.00  

The URL when https: //☓☓☓☓☓☓☓☓.ngrok.io next to Forwarding exposes localhost to the outside (port number is 5000). Use this as a ** webhook URL! ** **

.env is a file that sets environment variables, so don't push it to GitHub. To avoid pushing, find out how to use the .gitignore file.

.env


LINE_CHANNEL_ACCESS_TOKEN = ☓☓☓☓☓☓☓☓☓☓☓☓☓☓☓☓☓☓☓☓☓☓☓☓
LINE_CHANNEL_SECRET = ☓☓☓☓☓☓☓☓☓☓☓☓☓☓☓☓☓☓☓☓☓☓☓☓

・ ** Run main.py ** Prepare two terminals and run ngrok again on one. (Ngrok associates a different URL each time it is executed, so the value should have changed earlier). With that running, LINE developers webhook URL

https://☓☓☓☓☓☓☓☓.ngrok.io/callback

Set to (https!). Finally, run main.py in another terminal as follows.

main.Run py


pipenv shell //In a virtual environment
pipenv run python3.8 main.py

Hopefully the sample will work.

** In case of error ** Error: the command python3.8 could not be found within PATH or Pipfile's [scripts]. If you get an error like the one above, Change python3.8 to one that suits your environment.

main.Run py


pipenv run python main.py

For example, python or python3.

Summary

I was able to check the operation locally without pushing to heroku every time. Edit main.py ⇒ Execute ⇒ Just edit, so development is smooth.

However, ** ngrok changes the URL every time it is executed **, so you have to change the webhook URL of LINE developers every time you stop ngrok. Also, I feel that exposing localhost to the outside ** is bad for security ** (I don't know the details).

that's all!

Reference article

It seems that ngrok is safe or dangerous, free or paid, and so on. Verify actions around webhook on localhost ngrok is too convenient Use ngrok as safely as possible (Basic authentication)

Recommended Posts

LINEbot development, I want to check the operation in the local environment
I want to display the progress in Python!
I want to write in Python! (1) Code format check
I want to use Python in the environment of pyenv + pipenv on Windows 10
I want to easily build a model-based development environment
I want to write in Python! (3) Utilize the mock
I want to use the R dataset in python
I want to save the trouble of inputting when debugging Paiza's skill check example in a local environment such as Jupyter [Python]
I want to get the operation information of yahoo route
I want to make the Dictionary type in the List unique
I want to align the significant figures in the Numpy array
I didn't want to write the AWS key in the program
I want to run Rails with rails s even in vagrant environment
I want to make the second line the column name in pandas
I want to pass the G test in one month Day 1
I want to check the position of my face with OpenCV!
I want to know the population of each country in the world.
I want to pin Spyder to the taskbar
I want to output to the console coolly
I want to print in a comprehension
I want to handle the rhyme part1
I want to handle the rhyme part3
I want to build a Python environment
I want to display the progress bar
I want to embed Matplotlib in PySimpleGUI
I want to handle the rhyme part2
I want to handle the rhyme part5
I want to handle the rhyme part4
I want to change the color by clicking the scatter point in matplotlib
I tried to execute SQL from the local environment using Looker SDK
How to check local GAE from iPhone browser in the same LAN
I want to separate the processing between test time and production environment
[C language] I want to generate random numbers in the specified range
(Python Selenium) I want to check the settings of the download destination of WebDriver
I want to batch convert the result of "string" .split () in Python
I want to explain the abstract class (ABCmeta) of Python in detail.
I want to sort a list in the order of other lists
I want to use the Django Debug Toolbar in my Ajax application
Environment maintenance made with Docker (I want to post-process GrADS in Python
I want to leave an arbitrary command in the command history of Shell
I made a program to check the size of a file in Python
Let's use the NAOqi OS VM. I want to resolve dependencies with pip even in Pepper development
I want to load the pytest fixture as a library somewhere else (pytest may not exist in the environment)
I want to use Ubuntu's desktop environment on Android for the time being (Termux version-Japanese input in desktop environment)
Introduction to Python Let's prepare the development environment
I want to pin Datetime.now in Django tests
I want to create a window in Python
Anyway, I want to check JSON data easily
I want to handle the rhyme part7 (BOW)
I want to store DB information in list
I want to merge nested dicts in Python
From 0 to Django development environment construction to basic operation
I want to customize the appearance of zabbix
I want to use the activation function Mish
I want to visualize where and how many people are in the factory
[Python] I want to know the variables in the function when an error occurs!
I want to create a nice Python development environment for my new Mac
[Django memo] I want to set the login user information in the form in advance
I want to set a life cycle in the task definition of ECS
I want to see a list of WebDAV files in the Requests module
I want to store the result of% time, %% time, etc. in an object (variable)