Try   HackMD
tags: Line Bot FSM Python pymongo GraphMachine

Line Bot - 日常瑣事linebot (Implement FSM)

example code, Hlunlun

前言

  1. 外出看天氣可以直接查詢
  2. 也可以是todo list,隨時查看還有哪些事沒完成

環境:

python 3.9.13

技術

  • pymogo : 連接資料庫
  • api : 搜尋氣象資料
  • mongodb : 存todolist

How to start

  1. pip3 install pipenv
  2. 創一個 .env 檔包含
    • LINE_CHANNEL_SECRET
    • LINE_CHANNEL_ACCESS_TOKEN
    • WEATHER_API : 到這裡申請api
    • CONNECTION_STRING : 到這裡創建mongodb帳號
  3. pygraphviz : for windows
  4. open ngrok.exe : 記得先安裝
  5. type ngrok http 5000
  6. run app.py : python app.py

操作說明

  • 基本操作
    • restart : reset 回到初始狀態
    • fsm : 顯示狀態圖
  • 架構
    • weather : 查詢天氣
    • todo : 可以對todolist做CRUD的編輯
  • 使用示範
    • hello
      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →
    • 天氣
      • 問地區
        Image Not Showing Possible Reasons
        • The image file may be corrupted
        • The server hosting the image is unavailable
        • The image path is incorrect
        • The image format is not supported
        Learn More →
      • 可以繼續問,若是不想問了,就打restart
        Image Not Showing Possible Reasons
        • The image file may be corrupted
        • The server hosting the image is unavailable
        • The image path is incorrect
        • The image format is not supported
        Learn More →

        Image Not Showing Possible Reasons
        • The image file may be corrupted
        • The server hosting the image is unavailable
        • The image path is incorrect
        • The image format is not supported
        Learn More →
    • todolist
      • 問CRUD的哪個,一個項目進行完可以打todo就可以繼續下一個項目
        Image Not Showing Possible Reasons
        • The image file may be corrupted
        • The server hosting the image is unavailable
        • The image path is incorrect
        • The image format is not supported
        Learn More →
      • Create
        Image Not Showing Possible Reasons
        • The image file may be corrupted
        • The server hosting the image is unavailable
        • The image path is incorrect
        • The image format is not supported
        Learn More →
      • Read
        Image Not Showing Possible Reasons
        • The image file may be corrupted
        • The server hosting the image is unavailable
        • The image path is incorrect
        • The image format is not supported
        Learn More →
      • Update
        • 輸入要更新的項目的編號
          Image Not Showing Possible Reasons
          • The image file may be corrupted
          • The server hosting the image is unavailable
          • The image path is incorrect
          • The image format is not supported
          Learn More →
        • 選擇要更新狀態
          Image Not Showing Possible Reasons
          • The image file may be corrupted
          • The server hosting the image is unavailable
          • The image path is incorrect
          • The image format is not supported
          Learn More →
        • 最後顯示目前todolist
          Image Not Showing Possible Reasons
          • The image file may be corrupted
          • The server hosting the image is unavailable
          • The image path is incorrect
          • The image format is not supported
          Learn More →
      • Delete
        • 輸入要刪除的項目的編號
          Image Not Showing Possible Reasons
          • The image file may be corrupted
          • The server hosting the image is unavailable
          • The image path is incorrect
          • The image format is not supported
          Learn More →
        • 最後顯示目前todolist
          Image Not Showing Possible Reasons
          • The image file may be corrupted
          • The server hosting the image is unavailable
          • The image path is incorrect
          • The image format is not supported
          Learn More →
    • 輸入fsm
      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →

參考資料

.gitignore

line develop

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
Warning

1. Runtime

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

2. heroku stack

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →