Search code examples
botframeworkbotsmicrosoft-teamsadaptive-cards

Open a Teams TaskModule from an Adaptive card


I am trying to open a TaskModule from an adaptive Card. When I Use a HeroCard and embed an button like this

Buttons = new List<CardAction>()
{
new TaskModuleAction("Start task", new { data = "open_task" }),
}

it results in a json like this:

  {
  "type": "invoke",
  "title": "Start task",
  "image": null,
  "text": null,
  "displayText": null,
  "value": "{\n  \"data\": \"open_task\",\n  \"type\": \"task/fetch\"\n}",
  "channelData": null
}

When clicking the Button my OnTeamsMessagingExtensionFetchTaskAsync function is called.

How would I accomplish the same when using adaptive Cards? None of the options Action.Submit, Action.OpenURL, Action.showCard seem to be the right choice.


Solution

  • You can use adaptive card submit action type to open a task module.

    Below is the c# code snippet

    new AdaptiveCard()
                {
    
                    Actions =
                    {
                        new AdaptiveSubmitAction()
                        {
                            Title = "Title",
                            Data = new TaskModuleDetail<string>() { Data = "data here" }
                        },
    
                    }
                };
    

    TaskModuleDetail Class

    public class TaskModuleDetail<T>
        {
            [JsonProperty("msteams")]
            public object Type { get; set; } = JsonConvert.DeserializeObject("{\"type\": \"task/fetch\" }");
            [JsonProperty("data")]
            public T Data { get; set; }
        }