3

I have to create a adaptive card which have city of name and each city have different holiday list. I have to show city name in dropdown list and on selection of each city i have to show child card which contains Holiday list.

I have develop below code:

private async Task<DialogTurnResult> ShowCard(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
    List<string> city = new List<string>() { "Delhi", "Bangalore", "Mumbai" };
    List<string> date = new List<string>() { "1-Jan", "26-Jan", "15-Aug" };
    List<string> des = new List<string>() { "New Year", "Republic Day", "Independence Day" };

    List<string> date1 = new List<string>() { "1-Jan", "26-Jan", "15-Aug", "25-Dec" };
    List<string> des1 = new List<string>() { "New Year", "Republic Day", "Independence Day", "Christmas Day" };

    List<string> date2 = new List<string>() { "1-Jan", "25-Dec" };
    List<string> des2 = new List<string>() { "New Year", "Christmas Day" };

    List<AdaptiveCard> cards = new List<AdaptiveCard>();
    cards.Add(HolidayListAdaptiveCard(date, des));
    cards.Add(HolidayListAdaptiveCard(date1, des1));
    cards.Add(HolidayListAdaptiveCard(date2, des2));

    var mainCard = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0));
    var column3 = new AdaptiveColumn();
    column3.Items.Add(new AdaptiveTextBlock() { Text = "Holiday City", Weight = AdaptiveTextWeight.Bolder });
    var columnSet1 = new AdaptiveColumnSet();
    columnSet1.Columns.Add(column3);
    var container1 = new AdaptiveContainer();
    container1.Style = AdaptiveContainerStyle.Emphasis;
    container1.Items.Add(columnSet1);
    mainCard.Body.Add(container1);

    List<AdaptiveShowCardAction> adaptiveShowCardActions = new List<AdaptiveShowCardAction>();
    for (int i = 0; i < city.Count; i++)
    {
        mainCard.Actions.Add(new AdaptiveShowCardAction() { Title = city[i], Card = cards[i] });
    }

    var attachment = new Attachment
    {
        ContentType = AdaptiveCard.ContentType,
        Content = mainCard
    };
    var reply = MessageFactory.Attachment(attachment);
    await stepContext.Context.SendActivityAsync(reply);
    return new DialogTurnResult(DialogTurnStatus.Waiting);
}

private AdaptiveCard HolidayListAdaptiveCard(List<string> date, List<string> description)
{
    var card = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0));
    List<AdaptiveColumn> columns = new List<AdaptiveColumn>();
    var column = new AdaptiveColumn();
    var column1 = new AdaptiveColumn();
    var column2 = new AdaptiveColumn();

    var textBlock = new AdaptiveTextBlock();
    textBlock.Text = "Sr. No";
    textBlock.Weight = AdaptiveTextWeight.Bolder;
    textBlock.Size = AdaptiveTextSize.Large;
    textBlock.Color = AdaptiveTextColor.Accent;
    column.Items.Add(textBlock);

    var textBlock1 = new AdaptiveTextBlock();
    textBlock1.Text = "Date";
    textBlock1.Weight = AdaptiveTextWeight.Bolder;
    textBlock1.Size = AdaptiveTextSize.Large;
    textBlock1.Color = AdaptiveTextColor.Good;
    column1.Items.Add(textBlock1);

    var textBlock2 = new AdaptiveTextBlock();
    textBlock2.Text = "Description";
    textBlock2.Weight = AdaptiveTextWeight.Bolder;
    textBlock2.Size = AdaptiveTextSize.Large;
    textBlock2.Color = AdaptiveTextColor.Dark;
    column2.Items.Add(textBlock2);

    for (int i = 0; i < date.Count; i++)
    {
        column.Items.Add(new AdaptiveTextBlock() { Text = (i + 1).ToString() });
        column1.Items.Add(new AdaptiveTextBlock() { Text = date[i] });
        column2.Items.Add(new AdaptiveTextBlock() { Text = description[i] });
    }

    var columnSet = new AdaptiveColumnSet();
    columnSet.Columns.Add(column);
    columnSet.Columns.Add(column1);
    columnSet.Columns.Add(column2);
    var container = new AdaptiveContainer();
    container.Style = AdaptiveContainerStyle.Emphasis;
    container.Items.Add(columnSet);
    card.Body.Add(container);
    return card;
}

O/P:

enter image description here enter image description here

Issue: City name coming as separate button but i need city name in dropdown list.

Kyle Delaney
  • 11,616
  • 6
  • 39
  • 66
  • At https://adaptivecards.io/designer/ I am seeing an Input.ChoiceSet option for dropdown, but standard WebChat host app is no longer available (it was the old version of webchat) and the new version "Bot Framework Other Channels" doesn't appear to support this anymore. – billoverton Apr 16 '20 at 16:01
  • Are we to assume you're using Web Chat? (Since there are multiple people in this thread, you will need to @ mention me if you want me to see your reply.) – Kyle Delaney Apr 16 '20 at 18:13
  • @kyle Delaney I am using this chatbot in Microsoft teams. – utkarshsinghal17 Apr 17 '20 at 11:58
  • @utkarshsinghal17 did you get this working.. i also have similar requirement to load in dropdown.. – Sanjeev Gautam Aug 13 '21 at 07:58

1 Answers1

1

You can create a dropdown menu in an Adaptive Card by using an Input.ChoiceSet element and setting style to "compact". Note that the compact style is the default in Teams.

Compact choice set

You can only extend Adaptive Card functionality if you're using Web Chat so you won't be able to respond to events from this dropdown and you won't be able to modify the card as the user is filling it out. You'll need to have the user select a city and then click the submit button. While Teams does allow message updates and so you could update the card in response to the submit action, it's probably better and easier just to send a whole new card with the holiday list.

Kyle Delaney
  • 11,616
  • 6
  • 39
  • 66
  • Based on adaptivecards.io/designer, it appears that this doesn't work with the current card host for webchat, only the older (non-Gemini) version. Can you confirm? When you change the card host from WebChat to Other Channel (which Other Channel matches what I see in new version of OOTB webchat and directline webchat), it says ChoiceSets are not supported. – billoverton Apr 17 '20 at 17:24
  • @billoverton - I'm rather confused about your expectations here, but I think I kind of see what you're talking about. When I select "Bot Framework Other Channels" from the dropdown in the [designer](https://adaptivecards.io/designer/) I see a lot of elements not rendering, so I presume they're referring to third-party channels (none of which support Adaptive Cards). In a third-party channel you need to use Bot Framework rich cards, none of which have any input fields. I'm not sure why you think this is referring to Web Chat, but that's not what we're talking about here in any case. – Kyle Delaney Apr 17 '20 at 22:38
  • It's related to this issue here https://stackoverflow.com/questions/60383301/how-to-format-adaptive-cards-like-the-old-version-of-webchat. The "Botframework WebChat" card host on adaptivecards.io/designer renders cards in the "old" format as on the right in my SO question, but how the new webchat (and directline) channels render is like the "Botframework Other Channels" on the left. Perhaps there is a "Botframework WebChat New" card host that is not available on the designer but allows for things like ChoiceSet in the new webchat. – billoverton Apr 20 '20 at 13:34
  • @KyleDelaney I want to use the concept of ShowCard in Adaptive card so without posting to chatbot again, I want to see different child card(Holiday List) associated with different City. – utkarshsinghal17 Apr 20 '20 at 14:29
  • As you see in my code as well i am using AdaptiveShowCardAction. So only issue is coming that city name coming as button instead of dropdown(Input.Choice), I need to show these city name in dropdown list and selecting of different city i need to show different child adaptive card without using Submit Action(means without posting again) – utkarshsinghal17 Apr 20 '20 at 14:58
  • @ukkarshsinghal17 - I understand what you want to do but I explained that this is not possible in Teams. "You can only extend Adaptive Card functionality if you're using Web Chat so you won't be able to respond to events from this dropdown and you won't be able to modify the card as the user is filling it out." Is my workaround acceptable or do you want a different workaround? – Kyle Delaney Apr 20 '20 at 17:11
  • @KyleDelaney, is there any other workaround possible? – utkarshsinghal17 Apr 23 '20 at 14:16
  • @utkarshsinghal17 - Well you've already tried Action.ShowCard, so the only other possibility is Action.ToggleVisibility. This would work a lot like Action.ShowCard but it gives you a bit more control so you could do things like automatically hide the other cards when you click to show a new one. Given that I've already explained a few times that what you're trying to do is impossible, are you willing to accept my workaround as an answer? The place to make Adaptive Cards feature requests is in the Adaptive Cards GitHub repo, not on Stack Overflow. https://github.com/microsoft/AdaptiveCards – Kyle Delaney Apr 24 '20 at 21:43