Buttons enhance the conversational experience by letting the user answer a question or select the desired button, rather than having to type a response with a keyboard. Unlike buttons that appear within rich cards (which remain visible and accessible to the user even after being selected), buttons that appear within the suggested actions pane will disappear after the user makes a selection. This prevents the user from selecting stale buttons within a conversation and simplifies bot development since you won't need to account for that scenario.
Note
The Bot Framework JavaScript, C#, and Python SDKs will continue to be supported, however, the Java SDK is being retired with final long-term support ending in November 2023.
Existing bots built with the Java SDK will continue to function.
Suggested actions enable your bot to present buttons. You can create a list of suggested actions (also known as quick replies) that will be shown to the user for a single turn of the conversation.
// 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.privatestaticasync 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);
}
asyncdef_send_suggested_actions(self, turn_context: TurnContext):"""
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.
"""
reply = MessageFactory.text("What is your favorite color?")
reply.suggested_actions = SuggestedActions(
actions=[
CardAction(
title="Red",
type=ActionTypes.im_back,
value="Red",
image="https://via.placeholder.com/20/FF0000?text=R",
image_alt_text="R",
),
CardAction(
title="Yellow",
type=ActionTypes.im_back,
value="Yellow",
image="https://via.placeholder.com/20/FFFF00?text=Y",
image_alt_text="Y",
),
CardAction(
title="Blue",
type=ActionTypes.im_back,
value="Blue",
image="https://via.placeholder.com/20/0000FF?text=B",
image_alt_text="B",
),
]
)
returnawait turn_context.send_activity(reply)
Additional resources
You can access the complete source code for the Suggested actions sample in C#, JavaScript, Java and Python.
Some Power Automate button flows allow for user input and runs a predefined series of actions. This type of flow button provides the input that is necessary to run the predefined actions in the flow. It shows users how they can create a flow button that runs different logic based on the provided inputs.
Find out how to engage users in meaningful conversations with bots by learning about welcome messages. See code samples that detect and greet new users.
Learn how bots handle user interruptions. See how to implement help and cancel interruptions, how to create and test bots, and how to handle unexpected errors.