Skip to content

Howeng98/TOC_app

Repository files navigation

TOC Project 2020

Maintainability

A Line bot based on a finite state machine

Setup

Prerequisite

  • Python 3.6
  • Pipenv
  • Facebook Page and App
  • HTTPS Server
  • Firebase

Install Dependency

pip3 install pipenv

pipenv --three

pipenv install

pipenv shell

pip install firebase-admin

Secret Data

You should generate a .env file to set Environment Variables. LINE_CHANNEL_SECRET and LINE_CHANNEL_ACCESS_TOKEN MUST be set to proper values. Otherwise, you might not be able to run your code.

Run Locally

You can either setup https server or using ngrok as a proxy.

a. Ngrok installation

ngrok would be used in the following instruction

ngrok http 8000

After that, ngrok would generate a https URL.

Run the sever

python3 app.py

b. Servo

Or You can use servo to expose local servers to the internet.

Finite State Machine

fsm

Usage

The initial state is set to user.

Every time user state is triggered to advance to another state, it will go_back to user state after the bot replies corresponding message.

  • user

    • Input: anykey
    • Destination: Start
    • Description: The user state will go to the Start state whenever you input
  • Start

    • Input: 早餐,午餐,晚餐
    • Destination: breakfast,lunch,dinner
    • Description: Choose one selection for advanced suggestion
  • breakfast,lunch,dinner

    • Input: 試試新口味,最愛
    • Destination: new_flavor,favorite
    • Description: user can pick whether you want to choose a new thing for your food or pick from your favorite list
  • new_flavor,favorite

    • Input: 隨機,價位
    • Destination: random,cost
    • Description: if you are lazy to choose some food, you can just go ahead random option to let our line-bot give you an answer.Or you can go with cost conditions
  • cost,new_flavor,favorite

    • Input: 產生美食菜單
    • Destination: foodlist
    • Description: ask the line-bot to create a food list with the given conditions
  • end

    • Input: 確定
    • Destination: Start
    • Description: If you decided your food to have, click 確定 to go back lobby
  • back

    • Input: 返回大廳
    • Destination: Start
    • Description: go back to lobby immediately

Deploy

Setting to deploy webhooks on Heroku.

Heroku CLI installation

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

Connect to Heroku

  1. Register Heroku: https://signup.heroku.com

  2. Create Heroku project from website

  3. CLI Login

    heroku login

Upload project to Heroku

  1. Add local project to Heroku project

    heroku git:remote -a {HEROKU_APP_NAME}

  2. Upload project

    git add .
    git commit -m "Add code"
    git push -f heroku master
    
  3. 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
    
  4. Your Project is now running on Heroku!

    url: {HEROKU_APP_NAME}.herokuapp.com/callback

    debug command: heroku logs --tail --app {HEROKU_APP_NAME}

  5. If fail with pygraphviz install errors

    run 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

APP Picture

APP一開始的樣子

initial

使用者可以選擇早午晚餐

breakfast

接着可以選擇最愛,或者新口味

new_flavor

再來可以選擇要直接隨機產生一個結果,或者往價位的條件做篩選,及或者可以前往食物菜單查看資料庫中符合條件所擁有的食物

random

foodlist

cost

若前往最愛,則可以看到資料庫的選項,使用者可以直接對資料庫中資料做增刪甚至更新的動作

database

最後是確認好要吃的食物,還附上圖片meme

decision

以下是資料庫增加與更新的樣子

firebase1

firebase2

addData

updateData

Reference

Pipenv ❤️ @chihsuan

TOC-Project-2019 ❤️ @winonecheng

Flask Architecture ❤️ @Sirius207

Line line-bot-sdk-python

FireBase_Tutorial

About

LineBot designed with finite state machine, deploy on heroku

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •