SlideShare a Scribd company logo
简介
• 微软Bot Framework是一套用于开发和部署bot服
务的框架,通过该框架可以开发对话型机器人
服务,并接入到多种应用中。
• Bot Framework框架包括五个组成部分:
- Bot Builder SDK (开发bot服务,目前提供.Net & Node)
- Bot Connector (连接bot服务和最终用户)
- Developer Portal (供开发者注册、发布和管理bot服务)
- Bot Directory (已发布的所有bot服务目录)
- Emulator (供开发者本地调试bot服务的模拟器)
简介
Bot
Bot Connector
User
Channels
Hello world (Node version)
var restify = require('restify');
var builder = require('botbuilder');
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
var connector = new builder.ChatConnector({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
var bot = new builder.UniversalBot(connector);
server.post('/api/messages', connector.listen());
bot.dialog('/', function (session) {
session.send("Hello World");
});
Connector
建立同Bot Connector的连接,实现鉴
权以及用户和Bot之间的消息传递,目
前SDK提供三种:ConsoleConnector、
ChatConnector和CallConnector。
Bot
Bot服务的大脑,负责管理用户和Bot
之间的所有会话,需要使用connector
初始化,目前SDK提供两种:
UniversalBot和UniversalCallBot。
Dialog
实现Bot的具体会话逻辑,类似于网站
的路由,可以定义多个分别实现不同
的会话逻辑
鉴权
第一步: 向MSA登录服务发起请求
POST /d6d49420-f39b-4df7-a1dc-
d59a935871db/oauth2/v2.0/token HTTP/1.1
grant_type=client_credentials
client_id=<YOUR MICROSOFT APP ID>
client_secret=<YOUR MICROSOFT APP PASSWORD>
scope=https://api.botframework.com/.default
第二步: 获取token
HTTP/1.1 200 OK
{"token_type":"Bearer","expires_in":3600,"ext_expires_
in":3600,"access_token":"eyJhbGciOiJIUzI1NiIsInR5cC
I6IkpXVCJ9.eyJzdWIiOiJZb3UgZm91bmQgdGhlIG1hc
mJsZSBpbiB0aGUgb2F0bWVhbCEiLCJuYW1lIjoiQm
90IEZyYW1ld29yayJ9.JPyDDC5yKmHfOS7Gz2jjEhO
PvZ6iStYFu9XlkZDc7wc"}
第三步: 向Bot Connector发送消息
POST /v3/conversations/12345/activities HTTP/1.1
Authorization: Bearer
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ
Zb3UgZm91bmQgdGhlIG1hcmJsZSBpbiB0aGUgb2F0
bWVhbCEiLCJuYW1lIjoiQm90IEZyYW1ld29yayJ9.JP
yDDC5yKmHfOS7Gz2jjEhOPvZ6iStYFu9XlkZDc7wc
... (JSON-serialized activity message follows)
鉴权
第一步: 下载OpenId元数据文档
GET /v1/.well-known/openidconfiguration
HTTP/1.1
{
"issuer":"https://api.botframework.com",
"authorization_endpoint":"https://invalid.botframew
ork.com/",
"jwks_uri":"https://api.aps.skype.com/v1/keys",
"id_token_signing_alg_values_supported":["RSA25
6"],
"token_endpoint_auth_methods_supported":["privat
e_key_jwt"]
}
第二步: 下载有效的签名秘钥列表
GET /v1/keys HTTP/1.1
第三步: 验证JWT token
开启对话
Bot向Bot Connector发起创建会话请求
POST https://api.botframework.com/v3/conversations HTTP/1.1
Authorization: Bearer eyJhbGciOiJIUzI1Ni...
Content-Type: application/json
{
"bot": {
"id": "12345678",
"name": "bot's name"
},
"isGroup": false,
"members": [
{
"id": "1234abcd",
"name": "recipient's name"
}
],
"topicName": "News Alert"
}
会话创建成功之后Bot Connector返回会话id
{
"id": "abcd1234"
}
通常会话由用户发起,Bot回复用户的
消息即可,但某种场景下可能需要Bot
主动发起会话。
会话可以有多种形式,既可以是一对
一的私有回话,也可以是多对多的群
组会话。
收发消息
• 会话就是在用户与Bot之间发
送的消息序列,在Bot
Framework中每条消息都是一
个Activity对象。
消息类型 描述
contactRelationUpdate 用户将bot添加到联系人列表或者
移除出联系人列表
conversationUpdate 用户加入或离开会话,会话名称修
改
deleteUserData 用户要求bot删除自己的相关信息
message 普通的消息
ping 发给bot用来验证服务可接入
typing 表示对方正在输入
属性 属性说明
conversation 消息所属会话的信息,包括会话id和会话名称
from 发送消息方的信息
locale 消息的语言环境
recipient 接收消息方的信息
replyToId 消息回复的activity id
type 消息类型
POST https://api.botframework.com/v3/conversations/abcd1234/activities/5d5cdc723 HTTP/1.1
Authorization: Bearer eyJhbGciOiJIUzI1Ni...
Content-Type: application/json
{
"type": "message",
"from": {
"id": "12345678",
"name": "Pepper's News Feed"
},
"conversation": {
"id": "abcd1234",
"name": "Convo1"
},
"recipient": {
"id": "1234abcd",
"name": "SteveW"
},
"text": "My bot's reply",
"replyToId": "5d5cdc723"
}
收发消息
回复消息发送的URL路径为
https://api.botframework.com/v3/conversations/{conversation
Id}/activities/{activityId}
发起消息发送的URL路径为
https://api.botframework.com/v3/conversations/{conversation
Id}/activities
消息中携带附件
POST https://api.botframework.com/v3/conversations/abcd1234/activities/5d5cdc723 HTTP/1.1
Authorization: Bearer eyJhbGciOiJIUzI1Ni...
Content-Type: application/json
{
"type": "message",
"from": {
"id": "12345678",
"name": "sender's name"
},
"conversation": {
"id": "abcd1234",
"name": "conversation's name"
},
"recipient": {
"id": "1234abcd",
"name": "recipient's name"
},
"text": "Here's a pic of the duck I was telling you about.",
"attachments": [
{
"contentType": "image/png",
"contentUrl": http://aka.ms/Fo983c
}
],
"replyToId": "5d5cdc723"
}
除了文本文字,消息也可以携带其他类型的附件,如图片、
音频、视频和Rich Card。
消息中携带应用数据
{
"type": "message",
"from": {
"id": "mybot@gmail.com",
"name": "My bot"
},
"conversation": {
"id": "abcd1234",
"name": "conversation's name"
},
"recipient": {
"id": "john@gmail.com",
"name": "John Doe"
},
"channelData": {
"htmlBody" : "<html><body style="font-family: Calibri; font-size: 11pt;">email message goes
here</body></html>",
"subject":"email subject goes here",
"importance":"high"
},
"replyToId": "5d5cdc723"
}
某些对接应用无法直接使用text和附件,此时需要携带应用
可使用的数据
保存用户状态数据
• Bot Framework提供了三种存储来保存用户的状态数据
- User Data Store (与会话无关的用户数据)
- Conversation Store (与用户无关的会话数据)
- Private Conversation Store (会话中的用户数据)
• 每种存储可用的最大空间均为32KB,使用ETag实现对数据修改的并发控制
User Data Store
https://api.botframework.com/v3/botstate/{channelId}/users/{userId}
Conversation Store
https://api.botframework.com/v3/botstate/{channelId}/conversations/{conversationId}
Private Conversation Store
https://api.botframework.com/v3/botstate/{channelId}/conversations/{conversationId}/users/{userId}
保存用户状态数据
POST https://api.botframework.com/v3/botstate/abcd1234/users/12345678 HTTP/1.1
Authorization: Bearer eyJhbGciOiJIUzI1Ni...
Content-Type: application/json
{
"data": [
{
"trail": "Lake Serene",
"miles": 8.2,
"difficulty": "Difficult",
},
{
"trail": "Rainbow Falls",
"miles": 6.3,
"difficulty": "Moderate",
}
],
"eTag": "a1b2c3d4"
}
GET https://api.botframework.com/v3/botstate/abcd1234/users/12345678
HTTP/1.1
Authorization: Bearer eyJhbGciOiJIUzI1Ni...
Content-Type: application/json
{
"data": [
{
"trail": "Lake Serene",
"miles": 8.2,
"difficulty": "Difficult",
}
],
"eTag": "xyz12345"
}
Dialog组织方式
• Waterfall:Bot驱动会话的常用组织方式,bot始终处于一种为用户
提供信息或者问用户问题等待回答的状态。
- 为dialog处理器提供一组函数,框架对于每个会话维护一个dialog栈,bot根据栈中的内容来
判断用户的回复内容路由到哪个dialog。
• Closure:只为dialog处理器提供一个函数,类似于单步的waterfall。
• Dialog Object:为dialog处理提供一个IntentDialog,用于判断用户
意图,然后根据不同的意图执行不同的处理逻辑。
• SimpleDialog:作为waterfall的补充,用来处理waterfall无法覆盖
的场景。
IntentDialog
• 意图对话提供两种意图匹配方法:正则表达式和意图识别器,前
者在Bot本地实现意图匹配,后者基于云端实现意图识别和实体
抽取。
• 微软提供的云端意图识别的服务为LUIS(https://www.luis.ai/)。
• 目前Bot Framework提供的智能服务涉及:Vision、Speech、
Language、Knowledge和Search。

More Related Content

PPT
Software Engineer Talk
PPTX
Docker 淺入淺出
PDF
前端工程師一定要知道的 Docker 虛擬化容器技巧
PDF
PPTX
Docker 基礎介紹與實戰
PDF
20150604 docker 新手入門
PDF
Docker Build
PDF
Introduction to Golang final
Software Engineer Talk
Docker 淺入淺出
前端工程師一定要知道的 Docker 虛擬化容器技巧
Docker 基礎介紹與實戰
20150604 docker 新手入門
Docker Build
Introduction to Golang final

What's hot (20)

PDF
开源Pass平台flynn功能简介
PPTX
Docker Compose
PPTX
Rancher: 建立你的牧場艦隊
PDF
認識那條鯨魚 Docker 初探
PDF
從軟體開發角度
談 Docker 的應用
PDF
AWS EC2 for beginner
PPTX
用 Docker 改善團隊合作模式
PPTX
Docker tutorial
PDF
COSCUP 2016 Workshop: 用 Docker 架設班級 git-it 練習環境
PDF
docker intro
PDF
Continuous Delivery with Ansible x GitLab CI
PPTX
開發人員不可不知的 Windows Container 容器技術預覽
PPTX
Introduction to Docker
PDF
Continuous Delivery Workshop with Ansible x GitLab CI
PDF
Docker
PPTX
Dev-Ops与Docker的最佳实践 QCon2016 北京站演讲
PPTX
Docker open stack
PPTX
cec-hello-docker
PPTX
快速上手 Windows Containers 容器技術 (Docker Taipei)
开源Pass平台flynn功能简介
Docker Compose
Rancher: 建立你的牧場艦隊
認識那條鯨魚 Docker 初探
從軟體開發角度
談 Docker 的應用
AWS EC2 for beginner
用 Docker 改善團隊合作模式
Docker tutorial
COSCUP 2016 Workshop: 用 Docker 架設班級 git-it 練習環境
docker intro
Continuous Delivery with Ansible x GitLab CI
開發人員不可不知的 Windows Container 容器技術預覽
Introduction to Docker
Continuous Delivery Workshop with Ansible x GitLab CI
Docker
Dev-Ops与Docker的最佳实践 QCon2016 北京站演讲
Docker open stack
cec-hello-docker
快速上手 Windows Containers 容器技術 (Docker Taipei)
Ad

Viewers also liked (16)

PDF
青云虚拟机部署私有Docker Registry
PDF
青云CoreOS虚拟机部署kubernetes
PDF
Concept of service robots
PDF
thesis_palogiannidi
PPTX
Building A Conversational Bot Using Bot Framework and Microsoft
PDF
Tj bot 0317實作坊 組裝篇
PPTX
An Intelligent Assistant for High-Level Task Understanding
PPTX
End-to-End Memory Networks with Knowledge Carryover for Multi-Turn Spoken Lan...
PDF
Why Chatbot? 為何開發聊天機器人?
PPTX
Statistical Learning from Dialogues for Intelligent Assistants
PDF
Cascon 2016 Keynote: Disrupting Developer Productivity One Bot at a Time
PDF
Harm van Seijen, Research Scientist, Maluuba at MLconf SF 2016
PDF
如何透過聊天機器人(Chatbot)來翻轉企業與客戶溝通方式&【凡事都有個 Bot:虛擬篇】聊天機器人的前世今生 | 20160918 科技時事報導
PPTX
Intro to Bot Framework v3
PDF
End-to-End Joint Learning of Natural Language Understanding and Dialogue Manager
PDF
3 Things Every Sales Team Needs to Be Thinking About in 2017
青云虚拟机部署私有Docker Registry
青云CoreOS虚拟机部署kubernetes
Concept of service robots
thesis_palogiannidi
Building A Conversational Bot Using Bot Framework and Microsoft
Tj bot 0317實作坊 組裝篇
An Intelligent Assistant for High-Level Task Understanding
End-to-End Memory Networks with Knowledge Carryover for Multi-Turn Spoken Lan...
Why Chatbot? 為何開發聊天機器人?
Statistical Learning from Dialogues for Intelligent Assistants
Cascon 2016 Keynote: Disrupting Developer Productivity One Bot at a Time
Harm van Seijen, Research Scientist, Maluuba at MLconf SF 2016
如何透過聊天機器人(Chatbot)來翻轉企業與客戶溝通方式&【凡事都有個 Bot:虛擬篇】聊天機器人的前世今生 | 20160918 科技時事報導
Intro to Bot Framework v3
End-to-End Joint Learning of Natural Language Understanding and Dialogue Manager
3 Things Every Sales Team Needs to Be Thinking About in 2017
Ad

More from Zhichao Liang (11)

PDF
Introduction of own cloud
PDF
Power drill列存储底层设计
PDF
C store底层存储设计
PDF
Storage Class Memory: Technology Overview & System Impacts
PPTX
A simple introduction to redis
PDF
Memcached简介
PPTX
Some key value stores using log-structure
PPT
A novel method to extend flash memory lifetime in flash based dbms
PPT
Sub join a query optimization algorithm for flash-based database
PPTX
Hush…tell you something novel about flash memory
PPTX
Survey of distributed storage system
Introduction of own cloud
Power drill列存储底层设计
C store底层存储设计
Storage Class Memory: Technology Overview & System Impacts
A simple introduction to redis
Memcached简介
Some key value stores using log-structure
A novel method to extend flash memory lifetime in flash based dbms
Sub join a query optimization algorithm for flash-based database
Hush…tell you something novel about flash memory
Survey of distributed storage system

微软Bot framework简介