使用 Bot 連接器 API 將輸入提示新增至訊息

您可藉由指定訊息的輸入提示,指出您的 Bot 在訊息傳遞給用戶端之後,會接受、需要或忽略使用者輸入。 針對支援此欄位的通道,這可讓用戶端設定相應的使用者輸入控制項狀態。 例如,如果訊息的輸入提示指出 Bot 會忽略使用者輸入,則用戶端可關閉麥克風並停用輸入方塊,以防止使用者提供輸入。

接受輸入

若要指出 Bot 已被動準備好輸入,但未等候使用者的回應,請將 屬性設定 inputHint 為代表您訊息的Activity物件內的acceptingInput。 在許多通道上,這會啟用用戶端的輸入方塊並關閉麥克風,但使用者仍可存取。

下列範例示範傳送訊息並指定 Bot 接受輸入的要求。 在此範例要求中,Direct Line 表示基底 URI,您的 Bot 所發出要求的基底 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"
}

需要輸入

若要指出您的 Bot 正在等候使用者回應,請將代表訊息的 Activity 物件內的 inputHint 屬性設定為 expectingInput。 在支援此方式的通道上,這會啟用用戶端的輸入方塊並開啓麥克風。

下列範例示範傳送訊息並指定 Bot 需要輸入的要求。 在此範例要求中,Direct Line 表示基底 URI,您的 Bot 所發出要求的基底 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"
}

忽略輸入

若要指出 Bot 尚未準備好接收來自使用者的輸入,請將 inputHint 屬性設定為 ignoringInput 代表您訊息的 Activity 物件內。 在支援此方式的通道上,這會停用用戶端的輸入方塊並關閉麥克風。

下列範例示範傳送訊息並指定 Bot 忽略輸入的要求。 在此範例要求中,Direct Line 表示基底 URI,您的 Bot 所發出要求的基底 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"
}

其他資源