Add suggested actions to messages with the Bot Connector API
APPLIES TO: SDK v3
Suggested actions enable your bot to present buttons that the user can tap to provide input. Suggested actions appear close to the composer and enhance user experience by enabling the user to answer a question or make a selection with a simple tap of a 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 tapped), buttons that appear within the suggested actions pane will disappear after the user makes a selection. This prevents the user from tapping stale buttons within a conversation and simplifies bot development (since you will not need to account for that scenario).
Send suggested actions
To add suggested actions to a message, set the suggestedActions
property of the Activity object to specify the list of CardAction objects that represent the buttons to be presented to the user.
The following request sends a message that presents three suggested actions to the user. In this example request, https://smba.trafficmanager.net/apis
represents the base URI; the base URI for requests that your bot issues may be different. For details about setting the base URI, see API Reference.
POST https://smba.trafficmanager.net/apis/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": "I have colors in mind, but need your help to choose the best one.",
"inputHint": "expectingInput",
"suggestedActions": {
"actions": [
{
"type": "imBack",
"title": "Blue",
"value": "Blue"
},
{
"type": "imBack",
"title": "Red",
"value": "Red"
},
{
"type": "imBack",
"title": "Green",
"value": "Green"
}
]
},
"replyToId": "5d5cdc723"
}
When the user taps one of the suggested actions, the bot will receive a message from the user that contains the value
of the corresponding action.