Bottender
chatbot framwork
- Bottender intro
- webhooks
- http && https
- LRU
故事是這樣子開始的.......
所以決定來寫寫看 chatbot
...要做啥呢
- 統計(數量)
- 客製(加XXX、飲料冰量甜度)
- 取消、修改訂餐
- 開團者的付款資訊
希望有的功能
做一個幫忙統計訂餐的聊天機器人
- 如何判定是點餐還是講幹話
- 如何判定是要客製化(加蛋 冰量甜度)還是點餐項目
- ....
盡量減少規範達成判定
.......然後第一個挫折就是發現 FB
不讓 chatBot 加入多人對話
feature
- 方便管理保存 state 和 event
- 少很多拉哩拉匝的設定
- React-like && Intuitive APIs
- State、Event (對話的組成)
- Session、SessionStore(紀錄對話關係)
- Context(對話情境)
- Connect(串連各平台)
- CLI
核心構成
State、Event
(對話的組成)
State - 麻將 -1 QAQ
Event - 問 Kevin Hu 要不要大膽 ++
State + Event => 不要,我要去跟__泡湯呢ლ(・ ิω・ิლ)
Kevin Hu
(ChatBot)
State + Event => Action(Response)
ChuChuJay
(User)
State + Event => Action(Response)
(State, Props) => UI
484 跟 react 很像呢
// state={ 大膽的人: 3, __約泡湯: true }
module.exports = async context => {
const { text } = context.event.message;
if (/要不要(大膽|打麻將|下棋|吃飯|)/.test(text) {
if (__約泡湯) {
context.sendText('不要,我要去跟__泡湯呢ლ(・ ิω・ิლ)')
} else {
context.sendText('來咩!不敢膩!')
}
}
};
Session、SessionStore
(紀錄對話關係)
紀錄一個對話開始到結束的關係
(ex: user )
Session
SessionStore
- memory (LRU-cache)
- file
- redis
- mongo
儲存 session 的地方
Context(對話情境)
Context 代表一個 Event 發生時,我們當下要處理它的整個情境
// initialState={ ordering: false}
module.exports = async function App(context) {
//判斷是否開團
if (context.state.ordering) {
return isOrdering; // 開團中
}
return notOrdering; // 尚未開團
};
context
Event
state
(from user)
紀錄 session
session Store
Response
(to user)
change state
chatbot
DEMO
歡迎幫忙優化或開發新功能 ><
延伸閱讀 - 1 WebHooks
client
server
提供 api
client
platform
提供 api
1. 必須要有一個 domain(不能只有 IP)
2. 要是 https
差異: 明/密文傳輸訊息
如何轉職
1. 了解對稱式加密
2. 再了解非對稱式加密
3. 只剩下證明我就是發出訊息的那個人
跟公正的第三方申請數位憑證,
好證明這個公鑰就是我的
延伸閱讀 - 2
HTTP HTTPS
=>
延伸閱讀 - 3
LRU
管理 cache 的一個方式
Least Recently Used cache
當有新朋友進來時又剛好沒位子時,
邊緣人會被踢出去
Read and write operations has to be in O(1) time complexity.
Read O(1)
insert O(1)
delete O(1)
用空間換取時間
Bottender Intro
By Jay Chou
Bottender Intro
- 311