A Line bot based on a finite state machine
More details in the Slides and FAQ
- Python 3.8
- Pipenv
- Line App
- HTTPS Server
- Redis
pip3 install pipenv
pipenv --three
pipenv install
pipenv shell
- pygraphviz (For visualizing Finite State Machine)
You should generate a .env
file to set Environment Variables refer to our .env.sample
.
LINE_CHANNEL_SECRET
and LINE_CHANNEL_ACCESS_TOKEN
MUST be set to proper values.
Otherwise, you might not be able to run your code.
You should also set your REDIS_TLS_URL
for the use of REDIS. (A sample method is mentioned behind)
You can either setup https server or using ngrok
as a proxy.
or you can use Homebrew (MAC)
brew cask install ngrok
ngrok
would be used in the following instruction
ngrok http 8000
After that, ngrok
would generate a https URL.
python3 app.py
The initial state is set to welcome
.
Every time welecome
state is triggered to advance
to another state, it can back to welcome
state as long as the input is help
or e
.
Each input is not case sensitive, it also allow blank after the input string.
I also use Redis in Heroku to record the state for each user.
Once you add as friend, you will see the welcome message:
Setting to deploy webhooks on Heroku.
or you can use Homebrew (MAC)
brew tap heroku/brew && brew install heroku
or you can use Snap (Ubuntu 16+)
curl https://cli-assets.heroku.com/install.sh | sh
-
Register Heroku: https://signup.heroku.com
-
Create Heroku project from website
-
CLI Login
heroku login
-
Add local project to Heroku project (or you can build it)
heroku git:remote -a {HEROKU_APP_NAME}
-
Set buildpack in Heroku (for
pygraphviz
usage)heroku buildpacks:set heroku/python heroku buildpacks:add --index 1 heroku-community/apt heroku buildpacks:add https://github.com/weibeld/heroku-buildpack-graphviz heroku buildpacks
-
Heroku Redis Add-ons (optional)
If you havn't deploy your redis, you can use Heroku addons.
You should verified your Heroku account before you execute these command.
heroku addons:create heroku-redis:hobby-dev -a your-app-name
if you want to run locally, use
heroku config:get REDIS_TLS_URL -s >> .env
to get the URL which will use in this process. -
Set Environment - Line Messaging API Secret Keys
heroku config:set LINE_CHANNEL_SECRET=your_line_channel_secret heroku config:set LINE_CHANNEL_ACCESS_TOKEN=your_line_channel_access_token
-
Upload project
git add . git commit -m "Add code" git push heroku master
-
Your Project is now running on Heroku!
url:
{HEROKU_APP_NAME}.herokuapp.com/callback
debug command:
heroku logs --tail --app {HEROKU_APP_NAME}
Flask Architecture @Sirius207