0

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"
    }
  ]
}
user2530845
  • 65
  • 1
  • 6
  • Does this answer your question? [Adaptive Cards Submit actions](https://stackoverflow.com/questions/53378090/adaptive-cards-submit-actions) – Kyle Delaney Aug 26 '20 at 20:42
  • Is Nikitha's answer acceptable? – Kyle Delaney Aug 31 '20 at 19:30
  • **Thank You** for accepting answer, this will help others in the community with similar question. Could you please spare one min to let us know how we did by clicking on **[this feedback link](https://aka.ms/DevSupportFeedback)**? – Nikitha-MSFT Nov 07 '20 at 17:17

1 Answers1

0

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"
    }
  ]
}
    
Nikitha-MSFT
  • 577
  • 1
  • 3
  • 6
  • I tried doing this. Here is the json that's being generated. But with this, the Submit stops working. It doesn't raise any events now. I am also useing Adaptive card version 1.2. "actions": [ { "type": "Action.Submit", "data": "{'Action':'OrgName', 'msteams': {'type': 'task/fetch'}, 'data': 'Invoke'}", "title": "Save Configuration" }] – user2530845 Sep 02 '20 at 11:25
  • We are not able to repro the issue at our end. Could you please share your card JSON. – Nikitha-MSFT Sep 03 '20 at 05:09
  • Here is my json `{ "type": "AdaptiveCard", "version": "1.2", "body": [ "actions": [ { "type": "Action.Submit", "data": { "Action": "OrgName", "msteams": { "type": "task/fetch" }, "data": "Invoke" }, "title": "Save Configuration" } ] }` – user2530845 Sep 07 '20 at 09:56
  • The comment section doesn't allow me to post the whole json. But the body is basically an input box and label. When I click on the Save Configuration button, I get a small popup window saying "Unable to reach app. Please try again". This has nothing to do with my running app. It all works good if I remove these msteams related json elements. – user2530845 Sep 07 '20 at 10:02
  • Are you using same Card mentioned in question? Could you please add JSON to actual question – Nikitha-MSFT Sep 08 '20 at 11:29
  • Edited original question – user2530845 Sep 09 '20 at 08:49
  • Are you sending card using connector? if no could you please check this [docs](https://learn.microsoft.com/en-us/dotnet/api/microsoft.bot.builder.teams.teamsactivityhandler.onteamscardactioninvokeasync?view=botbuilder-dotnet-stable). OnTeamsCardActionInvokeAsync is invoked when card action invoke activity is received from the connector – Nikitha-MSFT Sep 10 '20 at 08:15
  • 1
    No. This is a bot conversation. We are sending a card when the user first installs the bot app on MS Teams and then trying to get this data from them for further authentication. So what you say is, this event is not useful for us then. We will have to continue using onMessageActivityAsync. – user2530845 Sep 10 '20 at 12:32