Search code examples
c#botframeworkbotsmicrosoft-teamsadaptive-cards

TeamsActivityHandler OnTeamsCardActionInvokeAsync is not firing on Card Submit Action


I have a simple Adaptive card with a couple of Input fields and an Action button with Submit action.

var card = new AdaptiveCard("1.0")
{
    Body = new List<AdaptiveElement>()
    {
        new AdaptiveTextBlock()
        {
            Text = "Title",
            Separator = true
        },
        new AdaptiveTextBlock()
        {
            Text = "Product Line"
        },
        new AdaptiveChoiceSetInput()
        {
            Id = "cmbProductLine",
            Choices = new List<AdaptiveChoice>()
            {
                new AdaptiveChoice() {
                    Title = "Choice 1",
                    Value = "1"},
                new AdaptiveChoice() {
                    Title = "Choice 2",
                    Value = "2"}
            },
            Style = AdaptiveChoiceInputStyle.Compact
        },
        new AdaptiveTextBlock()
        {
            Text = "Organization"
        },
        new AdaptiveTextInput()
        {
            Id = "txtOrgName",
            Placeholder = "Name"
        },
    },
    Actions = new List<AdaptiveAction>()
    {
        new AdaptiveSubmitAction()
        {
            Title = "Save",
            DataJson = @"{'Action':'Save'}"
        }
    }
};

Now on click of Save Action button, I am expecting OnTeamsCardActionInvokeAsync event to fire because my Bot is Inheriting from TeamsActivityHandler. But the button is only firing OnMessageActivityAsync event instead. Is this a bug in Bot framework or am I missing something?

Here is the JSON created from this code.

{
  "type": "AdaptiveCard",
  "version": "1.2",
  "body": [
    {
      "type": "TextBlock",
      "text": "Please provide organization details to proceed:",
      "separator": true
    },
    {
      "type": "TextBlock",
      "text": "Organization"
    },
    {
      "type": "Input.Text",
      "id": "txtOrgName",
      "placeholder": "Organization Name",
      "style": "email"
    }
  ],
  "actions": [
    {
      "type": "Action.Submit",
      "data": {
        "Action": "OrgName",
        "msteams": {
          "type": "task/fetch"
        },
        "data": "Invoke"
      },
      "title": "Save Configuration"
    },
    {
      "type": "Action.Submit",
      "data": {
        "Action": "Cancel"
      },
      "title": "Cancel"
    }
  ]
}

Solution

  • To include a Invoke action with an Adaptive Card include data object in the msteams object. Could you please check this docs for more info?

    Example: adaptive card JSON :

    {
      "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
      "type": "AdaptiveCard",
      "version": "1.2",
      "body": [
        {
          "type": "TextBlock",
          "size": "large",
          "weight": "bolder",
          "text": "Adaptive card"
        }
      ],
      "actions": [
        {
          "type": "Action.Submit",
          "data": {
            "msteams": {
              "type": "task/fetch"
            },
            "data": "Invoke"
          },
          "title": "Invoke"
        }
      ]
    }