or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
Bot Development
Speaker: Lee Wei
tags:
Tutorial
不知道大家想像的機器人是怎樣的
Pepper
- 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 →ASIMO
- 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 →Transformer
- 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 →Transformer- 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 →阿,不是這個
不過今天要談的不是這種東西
而是
Facebook Bot
Line Bot
Chat Bot 聊天機器人
有人說聊天機器人(with AI)將要取代APP
各大軟體公司爭相提供Bot的服務
What can Bot Do?
- 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 →影片中出現了什麼?
原本在App上處理的這些服務
未來都有可能被Chat Bot取代
背後發生了什麼事
e.g. 預約餐廳
把結果回傳給服務提供者Server
Why Chat Bot?
(e.g. Facebook Messenger, Line)
Why not Chat Bot?
How to Design a Bot?
用NLP精準的判斷使用者的意思,串到服務上
Just like the fifth step of...
by Van Oktop
Implement an Echo Bot
(The Simplest ChatBot)
How to Build an Echo Bot?
寫一些服務 (e.g. 訂票、新聞推播)用NLP精準的判斷使用者的意思,串到服務上How to Build an Echo Bot?
Let's Build an Echo Bot
Tools
Create a Line@ Account
[Bot] Apply Line Messaging API
Create Project
Setup Line Secrets
Setup Line Secrets
不過這些值不該被git記錄
所以不該被寫死在
settings.py
中建議寫入環境變數
Setup Line Secrets
Setup Line Webhook URL
設定一個Webhook URL
讓Line可以把Bot收到的訊息傳給我們
Setup Line Webhook URL
讓project找到app
Setup Line Webhook URL
將app的url導到相對應的function
Setup Line Webhook URL
https://"your domain name"/echobot/callback/
Implement Callback Funtion
import相關的函式庫
透過line_bot_api傳訊息給Line,讓Line轉傳給使用者
Callback Function
有兩種方法可以處理Line Server送過來的訊息
這裡先用Todo記著,待會再來補上
Validate Signature
確認這個request是不是從Line Server傳來的
要確認這件事,需要
Handle Recevied Message
取得body跟signature後
Line Bot API會在處理訊息的同時驗證訊息來源
WebhookParser
Parse出訊息的所有欄位
e.g.
Handle Line Related Exception
Echo
如果是文字訊息,就回傳給使用者
WebhookHandler
針對每一種不同的訊息型態註冊一個處理器
只要收到這樣的訊息,就會丟給對應的處理器
Text Message Handler
Default Handler
Handle
Full Code
兩種不同處理方式的完整Code
到了這裡,echo bot實作的部分就完成了
Https Server
(Skip)
ngrok
ngrok
先把django的server run起來
ngrok
用ngrok將request導到本地端的port 8000
ngrok
再來到Line Bot的
Line Developer
頁面設定Webhook URL
ngrok
然後就可以跟Bot聊天了

Heroku
Why not always use ngrok
When to use ngrok or Heroku?
Create App
先上Heroku辦個帳號
到個人的dashboard
New
->Create New App
選一個名字,就創好App了
Deploy
Add Remote
在部署之前要先安裝Heroku CLI
Environment Variables
Python Envrionments
requirements.txt
來判斷是否為Python專案runtime.txt
)python-2.7.12
python-3.5.2
Deploy Settings - Procfile
使用gunicorn部署到Heroku上
requirements.txt
加入gunicorn==19.0.0
Procfile
寫入接著
就部署到Heroku上了
More than just an Echo Bot
How to Design a Bot?
How to Design a Bot?
選擇使用的Bot平台 (e.g. Facebook, Line and etc.)把寫的服務,架在一台https server用Bot平台提供的sdk,把Server跟平台串起來How to Design a Bot?
選擇使用的Bot平台 (e.g. Facebook, Line and etc.)寫一些服務 (e.g. 訂票、新聞推播)把寫的服務,架在一台https server用Bot平台提供的sdk,把Server跟平台串起來淺談如何判斷使用者的意圖
如果使用者問:
要如何知道,他都是要詢問今天的天氣狀況
也就是使用者的「意圖」
Based on Keyword
同樣是天氣的問題
Based on Keyword
e.g.
Based on Keyword
AIML
一款基於XML的markup language
這是最基本的AIML
AIML
Other NLP Service
Other NLP Service
這些服務能透過標記和訓練
解析出這句話的每一個片段,所具有的意義
Wit.ai
Wit.ai跟Luis, API.ai比較不同的地方是
從Wit.ai得到的是,我們設定的回覆
而不是一句話解析後的結果
LUIS
API.ai
Implement Through Powerful Libraries
NLP Libs Sample
Beyond NLP
不過就算做了這些分詞、判斷意圖
也不能保證使用者就會買單
有人稱Chat Bot為下一代的UX Design
Issue
不會每次都不懂使用者的意思
Issue
更進一步是
如何設計一個有個性、有溫度的機器人
Reference
Reference
Thanks For Your Attention