入力にボタンを使用する

この記事の対象: SDK v4

ボタンを使用すると、ユーザーがキーボードで応答を入力せずに、質問に答えたり目的のボタンを選択したりできるため、会話のエクスペリエンスが向上します。 リッチ カード内に表示されるボタン (選択後も表示されたままとなり、ユーザーがアクセスできる) とは異なり、推奨される操作ウィンドウ内に表示されるボタンは、ユーザーが選択を行った後は表示されなくなります。 こうすると、ユーザーが会話内の選択済みボタンをタップすることを防ぎ、お客様はそのシナリオの責任を負う必要がなくなるので、ボット開発が簡略化されます。

Note

Bot Framework JavaScript SDK、C#、Python SDK は引き続きサポートされますが、Java SDK については、最終的な長期サポートは 2023 年 11 月に終了する予定です。 このリポジトリ内の重要なセキュリティとバグの修正のみが行われます。

Java SDK を使用して構築された既存のボットは引き続き機能します。

新しいボットの構築については、Power Virtual Agents の使用を検討し、適切なチャットボット ソリューションの選択についてお読みください。

詳細については、「The future of bot building」をご覧ください。

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

"推奨されるアクション" では、お使いのボットにボタンを表示させることができます。 会話の 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推奨アクション サンプルの完全なソース コードにアクセスできます。

次のステップ