輸入的 [使用] 按鈕

適用於: SDK v4

按鈕可讓使用者回答問題或選取所需的按鈕,而不必使用鍵盤輸入回應,來增強交談體驗。 不同於在豐富卡片內出現的按鈕(即使在選取之後仍可供使用者看見且可供存取),在使用者進行選取之後,出現在建議動作窗格中的按鈕將會消失。 這可防止使用者在交談中選取過時的按鈕,並簡化 Bot 開發,因為您不需要考慮該案例。

注意

Bot Framework JavaScript、C# 和 Python SDK 將會繼續受到支援,不過,Java SDK 即將淘汰,最終長期支援將於 2023 年 11 月結束。

使用 Java SDK 建置的現有 Bot 將繼續運作。

針對新的 Bot 建置,請考慮使用 Power Virtual Agents ,並閱讀 選擇正確的聊天機器人解決方案

如需詳細資訊,請參閱 Bot 建置的未來。

使用按鈕建議動作

建議的動作 可讓 Bot 呈現按鈕。 您可以建立建議的動作清單(也稱為 快速回復),向用戶顯示單一回合的交談。

以下是建議動作範例中的範例。

// Creates and sends an activity with suggested actions to the user. When the user
// clicks one of the buttons the text value from the "CardAction" will be
// displayed in the channel just as if the user entered the text. There are multiple
// "ActionTypes" that may be used for different situations.
private static async Task SendSuggestedActionsAsync(ITurnContext turnContext, CancellationToken cancellationToken)
{
    var reply = MessageFactory.Text("What is your favorite color?");

    reply.SuggestedActions = new SuggestedActions()
    {
        Actions = new List<CardAction>()
        {
            new CardAction() { Title = "Red", Type = ActionTypes.ImBack, Value = "Red", Image = "https://via.placeholder.com/20/FF0000?text=R", ImageAltText = "R" },
            new CardAction() { Title = "Yellow", Type = ActionTypes.ImBack, Value = "Yellow", Image = "https://via.placeholder.com/20/FFFF00?text=Y", ImageAltText = "Y" },
            new CardAction() { Title = "Blue", Type = ActionTypes.ImBack, Value = "Blue", Image = "https://via.placeholder.com/20/0000FF?text=B", ImageAltText = "B" },
        },
    };
    await turnContext.SendActivityAsync(reply, cancellationToken);
}

其他資源

您可以在 C#、JavaScriptJavaPython 中存取建議動作範例的完整原始程式碼

下一步