A Japanese learning Line bot based on a finite state machine
After sending start
to the Line bot, Main menu
will be returned
For the first four options in Main menu
, you can choose which level you want, and bot will return five words of the level.(below shows the result of choosing N5單字
)
You can choose to go back to Main menu
or continue to see words at the end of the message
You can add the word to favorite by clicking 加入收藏
. If the word is not in the favorite, bot will send 已將單字加入收藏
and add it to favorite, else return 單字已在收藏
You can see your favorite words by clicking 我的收藏
, bot will return at most five words in your favorite.
If you want to remove the word, just click 移除收藏
below the word. If success, bot will return 已將單字移除收藏
.
You can test by clicking 測驗
, bot will reply two options, first one represents that you need to answer the spell of the word, second one represents that you need to answer the chinese meaning of the word.
After choosing the type of test, you need to choose the level.
After choosing level, you can start to test, below shows the spell test.
After answering, bot will return the answer, and then you can choose to add word to favorite, continue , or go back to Main menu
.
After choosing level, you can start to test, below shows the chinese meaning test.
After answering, bot will return the answer, and then you can choose to add word to favorite, continue , or go back to Main menu
.
The initial state is set to user
.
Every state
can be triggered to advance
to another state
or go_back
to the state
which triggered it before.
You need to create four files(N2.csv
,N3.csv
,N4.csv
,N5.csv
) below the data
directory.
In every row of file, you have to follow the rules below(there is also an example under data directory.)
- Japan original word
Japanese spell tune meaning - loanword
spell ------ tune meaning
Deploy(This part is copied from https://github.com/NCKU-CCS/TOC-Project-2020 and add database configuration)
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+)
sudo snap install --classic heroku
-
Register Heroku: https://signup.heroku.com
-
Create Heroku project from website
-
CLI Login
heroku login
-
Add local project to Heroku project
heroku git:remote -a {HEROKU_APP_NAME}
-
Use database service provided by heroku
heroku addons:create heroku-postgresql:hobby-dev
After add database service, you can connect database to pgAdmin 4 by follwing the steps of this website
-
Upload project
git add . git commit -m "Add code" git push -f heroku master
-
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
-
Your Project is now running on Heroku!
url:
{HEROKU_APP_NAME}.herokuapp.com/webhook
debug command:
heroku logs --tail --app {HEROKU_APP_NAME}
-
If fail with
pygraphviz
install errorsrun commands below can solve the problems
heroku buildpacks:set heroku/python heroku buildpacks:add --index 1 heroku-community/apt
refference: https://hackmd.io/@ccw/B1Xw7E8kN?type=view#Q2-如何在-Heroku-使用-pygraphviz
below shows the finite state machine of nihongolearning
TOC-Project-2019 ❤️ @winonecheng
Flask Architecture ❤️ @Sirius207