Suggested Actions throwing error in teams using Bot Framework Composer

379 Views Asked by At

According to the link https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/conversations/conversation-messages?referrer=whats.new.rssfeed&tabs=typescript#send-suggested-actions MS teams does support suggested action now. As I am using MS Bot Composer for development, using the suggested actions doesn't seem working in Team. It is showing "Operation returned an invalid status code 'BadRequest'" message only. Can anyone please tell me that what is the way to implement suggested action in MS Teams chatbot, developed in Bot Framework Composer?

I am trying this in composer and in composer there are option for suggested actions. If I choose Ask for a question or Send a response , I can ask question/send response using Text, Attachments, Suggested Action. It seems, suggested action is not working for me in MS Teams.Suggested Action Option from here

1

There are 1 best solutions below

2
Sayali-MSFT On

Suggested actions enable your bot to present buttons that the user can select to provide input. Suggested actions enhance user experience by enabling the user to answer a question or make a choice with selection of a button, rather than typing a response with a keyboard. 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.

Here some code snippet -

 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" },
                new CardAction() { Title = "Yellow", Type = ActionTypes.ImBack, Value = "Yellow" },
                new CardAction() { Title = "Blue", Type = ActionTypes.ImBack, Value = "Blue" },
            },
            To = new List<string> { turnContext.Activity.From.Id },
        };

        await turnContext.SendActivityAsync(reply, cancellationToken);
    }

Reference sample link-https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/1ba8b1cec11a8052124cf02f88fff0bc9846f8cd/samples/bot-suggested-actions/csharp