你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

使用 Bot Connector API 向消息添加输入提示

通过为消息指定输入提示,可以指示在将消息传送到客户端后,机器人是接受、预期还是忽略用户输入。 对于支持此字段的通道,这使客户端可以相应地设置用户输入控件的状态。 例如,如果消息的输入提示指示机器人忽略用户输入,则客户端可以关闭麦克风并禁用输入框以防止用户提供输入。

接受输入

若要指示机器人已被动地准备好输入,但未等待来自用户的响应,请将inputHint属性设置为在表示消息的活动对象接受Input。 在许多通道上,这将导致客户端的输入框启用并且麦克风关闭,但仍可供用户访问。

以下示例显示了发送消息并指定机器人正在接受输入的请求。 在此示例请求中,Direct Line 表示基本 URI;机器人发出的请求的基本 URI 可能不同。 有关设置基本 URI 的详细信息,请参阅 API 参考

POST https://smba.trafficmanager.net/teams/v3/conversations/abcd1234/activities/5d5cdc723
Authorization: Bearer ACCESS_TOKEN
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 picture of the house I was telling you about.",
    "inputHint": "acceptingInput",
    "replyToId": "5d5cdc723"
}

期待输入

若要表明机器人在主动等待用户的响应,请在表示消息的 Activity 对象中将 inputHint 属性设置为 expectingInput 。 在支持它的通道上,这会导致客户端的输入框启用并且麦克风打开。

以下示例显示了发送消息并指定机器人期待输入的请求。 在此示例请求中,Direct Line 表示基本 URI;机器人发出的请求的基本 URI 可能不同。 有关设置基本 URI 的详细信息,请参阅 API 参考

POST https://smba.trafficmanager.net/teams/v3/conversations/abcd1234/activities/5d5cdc723
Authorization: Bearer ACCESS_TOKEN
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": "What is your favorite color?",
    "inputHint": "expectingInput",
    "replyToId": "5d5cdc723"
}

忽略输入

若要指示机器人尚未准备好从用户接收输入,请将属性inputHint设置为忽略表示消息的活动对象中的Input。 在支持它的通道上,这会导致客户端的输入框禁用并且麦克风关闭。

以下示例显示了发送消息并指定机器人忽略输入的请求。 在此示例请求中,Direct Line 表示基本 URI;机器人发出的请求的基本 URI 可能不同。 有关设置基本 URI 的详细信息,请参阅 API 参考

POST https://smba.trafficmanager.net/teams/v3/conversations/abcd1234/activities/5d5cdc723
Authorization: Bearer ACCESS_TOKEN
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": "Please hold while I perform the calculation.",
    "inputHint": "ignoringInput",
    "replyToId": "5d5cdc723"
}

其他资源