Giter Club home page Giter Club logo

check-in-bot's People

Contributors

barry800414 avatar mark86092 avatar peteranny avatar wendellliu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

check-in-bot's Issues

add logging

�發現訊息視窗看不到使用者的對話,很難知道有沒有出錯。要做 logging。

實作 messenger login

目前 messenger bot 點開的網頁,都是用一把 30字元的 key 去讓使用者 access 自己的資料。
雖然只要使用者不要連結亂給別人,要有資安危險的情況應該是滿低的,(大小寫英文+數字 62^30要暴力破應該是沒那麼容易)。
但比較好的做法還是實作 messenger login 的功能。

message handlers 邏輯上的分割

例如:
負責設定打卡時間的部分,就是一支檔案 ./handlers/set-reminder.js
負責打上下班的部分,又是另一支檔案 ./handlers/check-in.js

詳細怎麼做還沒想好,但如果可以做成這樣,會較為方便管理。

使用 `context._session._id` 遇到的問題

這裡發現 context._session._id 是專指 mongodb 上面的 primary key (_id)

換句話說,
2. 當使用者第一次與 bot 說話時,context._session._id 會是 undefined,也就是說,在 session 被存進 DB 前,_id 是沒有任何意義的

  1. 當 sessionStore 更換的時候,這個方法不保證有效
  2. 未來如果要寫測試,ContextSimulator 沒有明確支援 _id

主要是針對 點1,影響到 userId 怎麼來的問題

BTW 這邊有點不知道為什麼要使用 context.session._id 而不使用 context.session._id

[留著不一定要解的] async 導致的 state 問題

描述

當用 messenger 連續送出兩張圖時(發兩次對話),會導致 context.state 中,只有一張圖,且打卡完畢,仍然只有一張圖

重現

  1. 首先準備一個 api 可以回傳 db.collection('sessions') 的所有內容
  2. 傳送 不做了,確保 state 被清空 (可以檢查 1 的 api 回傳或用 console.log 看)
"_state": {
  "isWorking":false,
  "startTime":null,
  "endTime":null,
  "location":null,
  "locationTimestamp":null,
  "imgUrls":[]
}
  1. 傳送 做功德,檢查 state 應該是正常的
"_state": {
  "isWorking":true,
  "startTime":"2018-01-06T05:21:58.709Z",
  "endTime":null,
  "location":null,
  "locationTimestamp":null,
  "imgUrls":[]
}
  1. 連續發送兩張圖片 (假裝是上傳打卡照片)

image

  1. 檢查 state
"_state": {
  "isWorking":true,
  "startTime":"2018-01-06T05:21:58.709Z",
  "endTime":null,
  "location":null,
  "locationTimestamp":null,
  "imgUrls":[
    "https://scontent-ort2-1.xx.fbcdn.net/v/t39.1997-6/p100x100/11057103_789355331153381_925532673_n.png?_nc_ad=z-m&_nc_cid=0&oh=c96dd949be1f29576e28f0420be6b66a&oe=5AF1D9C5"
  ]
}

發現 state 沒有忠實儲存兩張圖片,經過多次測試,不一定會存到最後一張

結論

這不是一個嚴重的問題,畢竟在 2~3 秒送多張圖片實在少見

可能的解法

https://github.com/goodjoblife/check-in-bot/blob/master/index.js#L241 這裏

應該把拿到的圖片存進資料庫,而不是 state 中

修正上/下班人數的計算方式

目前是拿使用者數當分母,顯然不對。
要改成:

  1. 下班人數: 24 小時內 有打卡記錄的使用者數
  2. 總數:上班+下班人數

上班人數: count (state.isWorking = true )

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.