有奖捉虫:云通信与企业服务文档专题,速来> HOT

腾讯智能对话平台TBP允许Bot创建者提供Endpoint接收TBP的请求,实现定制化的对话逻辑。 本文档介绍TBP控制台中意图配置的服务实现方式为Web Service时,TBP服务和Web服务之间的协议接口。

TBP通过使用HTTP over SSL / TLS的请求响应机制与您的服务进行通信。 当用户与TBP交互时,您的服务会收到包含JSON主体的POST请求。 请求体包含服务执行逻辑所需的参数,并生成JSON格式的响应。

一、请求格式

本节描述发送到您的服务的请求的格式。

HTTP头

1.  POST / HTTP/1.1
2.  Content-Type : application/json;charset=UTF-8
3.  Host : your.application.endpoint
4.  Content-Length :
5.  Accept : application/json
6.  Accept-Charset : utf-8

请求正文语法

发送到您的服务的请求正文是JSON格式。

1.  {
2.  "RequestId":"string",
3.  "AppId":int,
4.  "BotId":"string",
5.  "BotName":"string",
6.  "IntentName":"string",
7.  "SlotInfoList":[
8.  {
9.  "SlotName":"string",
10. "SlotValue":"string"
11. },
12. {
13. "SlotName":"string",
14. "SlotValue":"string"
15. },
16. {
17. "SlotName":"string",
18. "SlotValue":"string"
19. },
20. {
21. "SlotName":"string",
22. "SlotValue":"string"
23. }
24. ],
25. "UserId":"string",
26. "SessionAttributes":"string"
27. }

请求正文参数

参数 描述 类型
RequestId 请求的唯一标识 string
AppId 创建Bot的腾讯云账号 int
BotId Bot的唯一标志符,控制台配置Bot时生成 string
BotName Bot名字,控制台配置的Bot信息 string
IntentName 意图名,当前话术识别到的意图 string
SlotInfoList 槽位数组,提供所有槽位信息 Object
UserId 表示发出请求的用户的唯一标识符的字符串。 此标识符的长度可以有所不同,但不能超过255个字符,调用RTS时传入,会传到web服务,匹配用户身份 string
SessionAttributes 用于服务方透传参数 string

SlotInfoList数组对象

参数 描述 类型
SlotName 槽位名,比如城市city string
SlotValue 槽位值,比如上海 string

请求示例

1.  {
2.  "RequestId":"xxx",
3.  "AppId":123456,
4.  "BotId":"5c8ef837-xxx-xxx-xxx",
5.  "BotName":"Ticket",
6.  "IntentName":"BookTicket",
7.  "SlotInfoList":[
8.  {
9.  "SlotName":"DepartureCity",
10. "SlotValue":"上海"
11. },
12. {
13. "SlotName":"DestinationCity",
14. "SlotValue":"广州"
15. },
16. {
17. "SlotName":"PersonNum",
18. "SlotValue":"4"
19. },
20. {
21. "SlotName":"DepartureTime",
22. "SlotValue":"9点"
23. }
24. ],
25. "UserId":"userId",
26. "SessionAttributes":"xx"
27. }

二、响应格式

本节描述您的服务返回的响应格式。TBP服务必须以JSON格式发送其回复,请注意响应的大小规定:

l ResponseContent响应不能超过8000个字符

l 您的响应的总大小不能超过24kb

如果您的响应不符合规定,则TBP服务返回错误。

HTTP头

1.  HTTP/1.1 200 OK
2.  Content-Type: application/json;charset=UTF-8
3.  Content-Length:

响应正文语法

1.  {
2.  "RequestId":"string",
3.  "SessionAttributes":"string",
4.  "ResponseMessage":{
5.  "ContentType":"PlainText",
6.  "Content":"string"
7.  },
8.  “WebHookStatus":"string"
9.  }

响应参数

参数 描述 类型 是否必需
RequestId 响应的ID,返回req中的RequestId string
SessionAttributes 用于需要持久化数据的传递 string
ResponseMessage 返回消息内容 object
WebHookStatus 业务错误时返回该字段,比如意图不支持,槽位缺失(IntentNotSupport, MissSlotInfo)等。只有业务处理出错时返回该字段,有正常ResponseMessge不需要返回该字段,建议取值:-1001(BotId不支持);-1002(IntentName不支持);-1003(槽位缺失);-1004(其他错误) string

ResponseMessage对象

此对象用于设置输出ResponseMessage属性。

参数 描述 类型 是否必需
ContentType 返回消息类型{PlainText:返回文本; Composite:json},(当前版本仅支持PlainText) string
Content 返回消息内容 string

响应示例

1.  {
2.  "RequestId":"xxx",
3.  "SessionAttributes":"xx",
4.  "ResponseMessage":{
5.  "ContentType":"PlainText",
6.  "Content":"您已成功订购了4张从上海到广州的机票,票号:1557475705737,价格:1650元。"
7.  }
8.  }