入力にボタンを使用する

適用対象: SDK v4

ボタンは、キーボードで応答を入力する必要なく、ユーザーが質問に回答したり、目的のボタンを選択したりすることで、会話エクスペリエンスを向上させます。 リッチ カード内に表示されるボタン (選択した後もユーザーが表示され、アクセス可能な状態のまま) とは異なり、ユーザーが選択を行うと、推奨される操作ウィンドウ内に表示されるボタンは表示されなくなります。 これにより、ユーザーは会話内で古いボタンを選択できなくなり、そのシナリオを考慮する必要がないため、ボットの開発が簡素化されます。

ボタンを使用した推奨されるアクション

"推奨されるアクション" では、お使いのボットにボタンを表示させることができます。 1 回の会話でユーザーに表示される、推奨されるアクション ( クイック応答とも呼ばれます) の一覧を作成できます。

ここで示すソース コードは、推奨されるアクションのサンプルに基づいています。

// 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推奨アクション サンプルの完全なソース コードにアクセスできます。

次のステップ