0

I started with Hello World Bot(ICommandHandler), I modified it

Now I try to process the response from the adaptive card

Already checked it out https://learn.microsoft.com/en-us/microsoftteams/platform/bots/bot-basics?tabs=csharp

I still can't understand - Where I am supposed to catch the submit action?

Adaptive Card

  • Please have look into this sample-https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/bot-type-ahead-search-adaptive-cards/csharp – Sayali-MSFT Sep 27 '22 at 06:54

1 Answers1

0

Since you mentioned you used Teams Toolkit C#, I assume you are using Teams Toolkit for Visual Studio.

Current Teams Toolkit and its SDK do not have built-in support for Adaptive Cards action handling. So you need to directly use Bot Framework SDK to write your own ActivityHandler to handle the card actions.

public class TeamsBot : ActivityHandler
{
    protected override async Task<InvokeResponse> OnInvokeActivityAsync(ITurnContext<IInvokeActivity> turnContext, CancellationToken cancellationToken)
    {
        // Handle card action
        if (turnContext.Activity.Name == "adaptiveCard/action")
        {
            // Handle your action response
            var cardJson = await File.ReadAllTextAsync("Resources/ActionResponseCard.json", cancellationToken).ConfigureAwait(false);
            var response = JObject.Parse(cardJson);
            var adaptiveCardResponse = new AdaptiveCardInvokeResponse()
            {
                StatusCode = 200,
                Type = "application/vnd.microsoft.card.adaptive",
                Value = response
            };

            return CreateInvokeResponse(adaptiveCardResponse);
        }

        return CreateInvokeResponse(null);
    }
}

You also need to use Action.Execute instead of Action.Submit which is the newer Universal Actions for Adaptive Cards. It is a unified action model across platforms.

Also see this GitHub issue to learn more.

You can checkout this more complete example in teams samples repo.

Alex Wang
  • 325
  • 2
  • 13