狠狠撸

狠狠撸Share 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。
Ad

Recommended

Software Engineer Talk
Software Engineer Talk
Larry Cai
?
Docker 淺入淺出
Docker 淺入淺出
Miles Chou
?
前端工程師一定要知道的 Docker 虛擬化容器技巧
前端工程師一定要知道的 Docker 虛擬化容器技巧
Chu-Siang Lai
?
顿辞肠办别谤应用
顿辞肠办别谤应用
Jui An Huang (黃瑞安)
?
Docker 基礎介紹與實戰
Docker 基礎介紹與實戰
Bo-Yi Wu
?
20150604 docker 新手入門
20150604 docker 新手入門
azole Lai
?
Docker Build
Docker Build
Miles Chou
?
Introduction to Golang final
Introduction to Golang final
Paul Chao
?
开源笔补蝉蝉平台蹿濒测苍苍功能介绍
开源笔补蝉蝉平台蹿濒测苍苍功能介绍
Zhichao Liang
?
Docker Compose
Docker Compose
Miles Chou
?
Rancher: 建立你的牧場艦隊
Rancher: 建立你的牧場艦隊
Miles Chou
?
認識那條鯨魚 Docker 初探
認識那條鯨魚 Docker 初探
仲昀 王
?
從軟體開發角度?談 Docker 的應用
從軟體開發角度?談 Docker 的應用
謝 宗穎
?
AWS EC2 for beginner
AWS EC2 for beginner
azole Lai
?
用 Docker 改善團隊合作模式
用 Docker 改善團隊合作模式
Bo-Yi Wu
?
Docker tutorial
Docker tutorial
azole Lai
?
COSCUP 2016 Workshop: 用 Docker 架設班級 git-it 練習環境
COSCUP 2016 Workshop: 用 Docker 架設班級 git-it 練習環境
均民 戴
?
docker intro
docker intro
koji lin
?
Continuous Delivery with Ansible x GitLab CI
Continuous Delivery with Ansible x GitLab CI
Chu-Siang Lai
?
開發人員不可不知的 Windows Container 容器技術預覽
開發人員不可不知的 Windows Container 容器技術預覽
Will Huang
?
Introduction to Docker
Introduction to Docker
Chris Chen
?
Container Security
Container Security
LinuxCon ContainerCon CloudOpen China
?
Continuous Delivery Workshop with Ansible x GitLab CI
Continuous Delivery Workshop with Ansible x GitLab CI
Chu-Siang Lai
?
Docker
Docker
旭 張
?
Dev-Ops与Docker的最佳实践 QCon2016 北京站演讲
Dev-Ops与Docker的最佳实践 QCon2016 北京站演讲
ChinaNetCloud
?
Docker open stack
Docker open stack
Guangya Liu
?
cec-hello-docker
cec-hello-docker
Bruce Huang
?
快速上手 Windows Containers 容器技術 (Docker Taipei)
快速上手 Windows Containers 容器技術 (Docker Taipei)
Will Huang
?
青云虚拟机部署私有Docker Registry
青云虚拟机部署私有Docker Registry
Zhichao Liang
?
青云颁辞谤别翱厂虚拟机部署办耻产别谤苍别迟别蝉
青云颁辞谤别翱厂虚拟机部署办耻产别谤苍别迟别蝉
Zhichao Liang
?

More Related Content

What's hot (20)

开源笔补蝉蝉平台蹿濒测苍苍功能介绍
开源笔补蝉蝉平台蹿濒测苍苍功能介绍
Zhichao Liang
?
Docker Compose
Docker Compose
Miles Chou
?
Rancher: 建立你的牧場艦隊
Rancher: 建立你的牧場艦隊
Miles Chou
?
認識那條鯨魚 Docker 初探
認識那條鯨魚 Docker 初探
仲昀 王
?
從軟體開發角度?談 Docker 的應用
從軟體開發角度?談 Docker 的應用
謝 宗穎
?
AWS EC2 for beginner
AWS EC2 for beginner
azole Lai
?
用 Docker 改善團隊合作模式
用 Docker 改善團隊合作模式
Bo-Yi Wu
?
Docker tutorial
Docker tutorial
azole Lai
?
COSCUP 2016 Workshop: 用 Docker 架設班級 git-it 練習環境
COSCUP 2016 Workshop: 用 Docker 架設班級 git-it 練習環境
均民 戴
?
docker intro
docker intro
koji lin
?
Continuous Delivery with Ansible x GitLab CI
Continuous Delivery with Ansible x GitLab CI
Chu-Siang Lai
?
開發人員不可不知的 Windows Container 容器技術預覽
開發人員不可不知的 Windows Container 容器技術預覽
Will Huang
?
Introduction to Docker
Introduction to Docker
Chris Chen
?
Container Security
Container Security
LinuxCon ContainerCon CloudOpen China
?
Continuous Delivery Workshop with Ansible x GitLab CI
Continuous Delivery Workshop with Ansible x GitLab CI
Chu-Siang Lai
?
Docker
Docker
旭 張
?
Dev-Ops与Docker的最佳实践 QCon2016 北京站演讲
Dev-Ops与Docker的最佳实践 QCon2016 北京站演讲
ChinaNetCloud
?
Docker open stack
Docker open stack
Guangya Liu
?
cec-hello-docker
cec-hello-docker
Bruce Huang
?
快速上手 Windows Containers 容器技術 (Docker Taipei)
快速上手 Windows Containers 容器技術 (Docker Taipei)
Will Huang
?
开源笔补蝉蝉平台蹿濒测苍苍功能介绍
开源笔补蝉蝉平台蹿濒测苍苍功能介绍
Zhichao Liang
?
Rancher: 建立你的牧場艦隊
Rancher: 建立你的牧場艦隊
Miles Chou
?
認識那條鯨魚 Docker 初探
認識那條鯨魚 Docker 初探
仲昀 王
?
從軟體開發角度?談 Docker 的應用
從軟體開發角度?談 Docker 的應用
謝 宗穎
?
AWS EC2 for beginner
AWS EC2 for beginner
azole Lai
?
用 Docker 改善團隊合作模式
用 Docker 改善團隊合作模式
Bo-Yi Wu
?
Docker tutorial
Docker tutorial
azole Lai
?
COSCUP 2016 Workshop: 用 Docker 架設班級 git-it 練習環境
COSCUP 2016 Workshop: 用 Docker 架設班級 git-it 練習環境
均民 戴
?
Continuous Delivery with Ansible x GitLab CI
Continuous Delivery with Ansible x GitLab CI
Chu-Siang Lai
?
開發人員不可不知的 Windows Container 容器技術預覽
開發人員不可不知的 Windows Container 容器技術預覽
Will Huang
?
Introduction to Docker
Introduction to Docker
Chris Chen
?
Continuous Delivery Workshop with Ansible x GitLab CI
Continuous Delivery Workshop with Ansible x GitLab CI
Chu-Siang Lai
?
Dev-Ops与Docker的最佳实践 QCon2016 北京站演讲
Dev-Ops与Docker的最佳实践 QCon2016 北京站演讲
ChinaNetCloud
?
快速上手 Windows Containers 容器技術 (Docker Taipei)
快速上手 Windows Containers 容器技術 (Docker Taipei)
Will Huang
?

Viewers also liked (16)

青云虚拟机部署私有Docker Registry
青云虚拟机部署私有Docker Registry
Zhichao Liang
?
青云颁辞谤别翱厂虚拟机部署办耻产别谤苍别迟别蝉
青云颁辞谤别翱厂虚拟机部署办耻产别谤苍别迟别蝉
Zhichao Liang
?
Concept of service robots
Concept of service robots
Grupo Golem (DCC-IIMAS-UNAM)
?
thesis_palogiannidi
thesis_palogiannidi
Elisavet Palogiannidi
?
Building A Conversational Bot Using Bot Framework and Microsoft
Building A Conversational Bot Using Bot Framework and Microsoft
Pranav Ainavolu
?
Tj bot 0317實作坊 組裝篇
Tj bot 0317實作坊 組裝篇
湯米吳 Tommy Wu
?
An Intelligent Assistant for High-Level Task Understanding
An Intelligent Assistant for High-Level Task Understanding
Yun-Nung (Vivian) Chen
?
End-to-End Memory Networks with Knowledge Carryover for Multi-Turn Spoken Lan...
End-to-End Memory Networks with Knowledge Carryover for Multi-Turn Spoken Lan...
Yun-Nung (Vivian) Chen
?
Why Chatbot? 為何開發聊天機器人?
Why Chatbot? 為何開發聊天機器人?
Burton Chau
?
Statistical Learning from Dialogues for Intelligent Assistants
Statistical Learning from Dialogues for Intelligent Assistants
Yun-Nung (Vivian) Chen
?
Cascon 2016 Keynote: Disrupting Developer Productivity One Bot at a Time
Cascon 2016 Keynote: Disrupting Developer Productivity One Bot at a Time
Margaret-Anne Storey
?
Harm van Seijen, Research Scientist, Maluuba at MLconf SF 2016
Harm van Seijen, Research Scientist, Maluuba at MLconf SF 2016
MLconf
?
如何透過聊天機器人(Chatbot)來翻轉企業與客戶溝通方式&【凡事都有個 Bot:虛擬篇】聊天機器人的前世今生 | 20160918 科技時事報導
如何透過聊天機器人(Chatbot)來翻轉企業與客戶溝通方式&【凡事都有個 Bot:虛擬篇】聊天機器人的前世今生 | 20160918 科技時事報導
貫中 侯
?
Intro to Bot Framework v3
Intro to Bot Framework v3
Shahed Chowdhuri
?
End-to-End Joint Learning of Natural Language Understanding and Dialogue Manager
End-to-End Joint Learning of Natural Language Understanding and Dialogue Manager
Yun-Nung (Vivian) Chen
?
3 Things Every Sales Team Needs to Be Thinking About in 2017
3 Things Every Sales Team Needs to Be Thinking About in 2017
Drift
?
青云虚拟机部署私有Docker Registry
青云虚拟机部署私有Docker Registry
Zhichao Liang
?
青云颁辞谤别翱厂虚拟机部署办耻产别谤苍别迟别蝉
青云颁辞谤别翱厂虚拟机部署办耻产别谤苍别迟别蝉
Zhichao Liang
?
Building A Conversational Bot Using Bot Framework and Microsoft
Building A Conversational Bot Using Bot Framework and Microsoft
Pranav Ainavolu
?
An Intelligent Assistant for High-Level Task Understanding
An Intelligent Assistant for High-Level Task Understanding
Yun-Nung (Vivian) Chen
?
End-to-End Memory Networks with Knowledge Carryover for Multi-Turn Spoken Lan...
End-to-End Memory Networks with Knowledge Carryover for Multi-Turn Spoken Lan...
Yun-Nung (Vivian) Chen
?
Why Chatbot? 為何開發聊天機器人?
Why Chatbot? 為何開發聊天機器人?
Burton Chau
?
Statistical Learning from Dialogues for Intelligent Assistants
Statistical Learning from Dialogues for Intelligent Assistants
Yun-Nung (Vivian) Chen
?
Cascon 2016 Keynote: Disrupting Developer Productivity One Bot at a Time
Cascon 2016 Keynote: Disrupting Developer Productivity One Bot at a Time
Margaret-Anne Storey
?
Harm van Seijen, Research Scientist, Maluuba at MLconf SF 2016
Harm van Seijen, Research Scientist, Maluuba at MLconf SF 2016
MLconf
?
如何透過聊天機器人(Chatbot)來翻轉企業與客戶溝通方式&【凡事都有個 Bot:虛擬篇】聊天機器人的前世今生 | 20160918 科技時事報導
如何透過聊天機器人(Chatbot)來翻轉企業與客戶溝通方式&【凡事都有個 Bot:虛擬篇】聊天機器人的前世今生 | 20160918 科技時事報導
貫中 侯
?
End-to-End Joint Learning of Natural Language Understanding and Dialogue Manager
End-to-End Joint Learning of Natural Language Understanding and Dialogue Manager
Yun-Nung (Vivian) Chen
?
3 Things Every Sales Team Needs to Be Thinking About in 2017
3 Things Every Sales Team Needs to Be Thinking About in 2017
Drift
?
Ad

More from Zhichao Liang (11)

Introduction of own cloud
Introduction of own cloud
Zhichao Liang
?
Power drill列存储底层设计
Power drill列存储底层设计
Zhichao Liang
?
C store底层存储设计
C store底层存储设计
Zhichao Liang
?
Storage Class Memory: Technology Overview & System Impacts
Storage Class Memory: Technology Overview & System Impacts
Zhichao Liang
?
A simple introduction to redis
A simple introduction to redis
Zhichao Liang
?
惭别尘肠补肠丑别诲介绍
惭别尘肠补肠丑别诲介绍
Zhichao Liang
?
Some key value stores using log-structure
Some key value stores using log-structure
Zhichao Liang
?
A novel method to extend flash memory lifetime in flash based dbms
A novel method to extend flash memory lifetime in flash based dbms
Zhichao Liang
?
Sub join a query optimization algorithm for flash-based database
Sub join a query optimization algorithm for flash-based database
Zhichao Liang
?
Hush…tell you something novel about flash memory
Hush…tell you something novel about flash memory
Zhichao Liang
?
Survey of distributed storage system
Survey of distributed storage system
Zhichao Liang
?
Introduction of own cloud
Introduction of own cloud
Zhichao Liang
?
Power drill列存储底层设计
Power drill列存储底层设计
Zhichao Liang
?
C store底层存储设计
C store底层存储设计
Zhichao Liang
?
Storage Class Memory: Technology Overview & System Impacts
Storage Class Memory: Technology Overview & System Impacts
Zhichao Liang
?
A simple introduction to redis
A simple introduction to redis
Zhichao Liang
?
惭别尘肠补肠丑别诲介绍
惭别尘肠补肠丑别诲介绍
Zhichao Liang
?
Some key value stores using log-structure
Some key value stores using log-structure
Zhichao Liang
?
A novel method to extend flash memory lifetime in flash based dbms
A novel method to extend flash memory lifetime in flash based dbms
Zhichao Liang
?
Sub join a query optimization algorithm for flash-based database
Sub join a query optimization algorithm for flash-based database
Zhichao Liang
?
Hush…tell you something novel about flash memory
Hush…tell you something novel about flash memory
Zhichao Liang
?
Survey of distributed storage system
Survey of distributed storage system
Zhichao Liang
?
Ad

微软Bot framework介绍