0

Issue: Doesn't render more than five actions

Background:

I was doing an integration of the BotFramework-WebChat with SharePoint Framework and all is working fine. But, when I try to display an adaptive card with more than 5 actions inside the WebChat the chat show's me a card with the text "Can't render card" but if tested in BotFramework-Emulator works or Console Directline works fine.

For testing proposes I wrote a C# method in which you pass the number of actions, that you want to show in the chat.

Test with Adaptative Card

Issue: Render a card with the message "Can't render card" if there are more than five actions

Excepected : Render an adaptative card with more than five actions private async Task MessageReceivedAsync(IDialogContext context, IAwaitable argument) { var message = await argument; var reply = context.MakeMessage();

    if (message.Text.Equals("3 btn"))
    {
        reply.Attachments.Add(GetAdaptativeCard(3));
        reply.Value = " { nombre : 'BTN'}";
    }
    else if (message.Text.Equals("5 btn"))
    {
        reply.Attachments.Add(GetAdaptativeCard(5));
        reply.Value = " { nombre : 'BTN'}";
    } 
    else if (message.Text.Equals("7 btn"))
    {
        reply.Attachments.Add(GetAdaptativeCard(7));
        reply.Value = " { nombre : 'BTN'}";
    }
    else if (message.Text.Equals("18 btn"))
    {
        reply.Attachments.Add(GetAdaptativeCard(18));
        reply.Value = " { nombre : 'BTN'}";
    }
    else
    if (message.Text.Equals("gif"))
    {
        reply.Attachments.Add(GetAnimationCard());
    await context.PostAsync(reply);
}

private Attachment GetAdaptativeCard(int numberOfButtons) {

    var actions = new List<ActionBase>();
    for (int i = 0; i < numberOfButtons; i++)
    {
        actions.Add(new SubmitAction()
        {
            Title = i.ToString(),
            Speak = "<s>Search</s>",
            DataJson = "{ \"Type\": \"HotelSearch\" }"
        });
    }

    AdaptiveCard card = new AdaptiveCard()
    {
        Body = new List<CardElement>()
        {
            new Container()
            {
                Speak = "<s>Hello!</s><s>How many buttons are in the chat?(18)</s>",
                Items = new List<CardElement>()
                {
                    new ColumnSet()
                    {
                        Columns = new List<Column>()
                        {
                            new Column()
                            {
                                Size = ColumnSize.Auto,
                                Items = new List<CardElement>()
                                {
                                    new Image()
                                    {
                                        Url = "https://placeholdit.imgix.net/~text?txtsize=65&txt=Adaptive+Cards&w=300&h=300",
                                        Size = ImageSize.Medium,
                                        Style = ImageStyle.Person
                                    }
                                }
                            },
                            new Column()
                            {
                                Size = ColumnSize.Stretch,
                                Items = new List<CardElement>()
                                {
                                    new TextBlock()
                                    {
                                        Text =  "Hello!",
                                        Weight = TextWeight.Bolder,
                                        IsSubtle = true
                                    }
                                }
                            }
                        }
                    }
                }
        }
    },
        // Buttons
        Actions = actions
    };
    return new Attachment()
    {
        ContentType = AdaptiveCard.ContentType,
        Content = card
    };

}

Screenshots:

Test with HeroCard:

I just try using HeroCard instead of AdaptiveCard. And in this case when are more than 5 buttons only shows the first 5 buttons. Maybe this is a limitation?

Issue: The card only render the first five actions

Excepected : Render a hero card with more than five actions

private Attachment GetHeroCard(int numbersOfButtons)
{
    var actions = new List<CardAction>();
    for (int i = 0; i < numbersOfButtons; i++)
    {
        actions.Add(new CardAction(ActionTypes.OpenUrl, $"Get Started {i}", value: "https://learn.microsoft.com/bot-framework"));
    }
    HeroCard card = new HeroCard()
    {
        Title = "BotFramework Hero Card",
        Subtitle = "Your bots — wherever your users are talking",
        Text = "Build and connect intelligent bots to interact with your users naturally wherever they are, from text/sms to Skype, Slack, Office 365 mail and other popular services.",
        Images = new List<CardImage> { new CardImage("https://sec.ch9.ms/ch9/7ff5/e07cfef0-aa3b-40bb-9baa-7c9ef8ff7ff5/buildreactionbotframework_960.jpg") },
        Buttons = actions
    };
    return card.ToAttachment();
}
D4RKCIDE
  • 3,439
  • 1
  • 18
  • 34
Ghad
  • 3
  • 1
  • "I was doing an integration of the BotFramework-WebChat with SharePoint Framework and all is working fine": have you more details on this implementation? Are you using https://github.com/SharePoint/sp-dev-fx-webparts/tree/master/samples/react-bot-framework ? – Nicolas R Apr 25 '18 at 10:11
  • Hi, I integrate the https://github.com/Microsoft/BotFramework-WebChat into the react project for SPFX. The issue that I have happens when the bots returns me a Card with more than five actions, if the cards is the type **herocard** the card only show's the first five actions and if the type is **AdaptiveCard** returns a card with the message "Can't render the card". I think that the issue with the number of actions in the card is related with https://github.com/Microsoft/AdaptiveCards, but I not sure. – Ghad Apr 25 '18 at 15:16
  • So to summarize: Adaptive Card: OK with max 5 actions, else no render // HeroCard: OK with max 5 actions, else rendering only the first 5 – Nicolas R Apr 25 '18 at 15:21
  • Yea exactly. Do you know if that is a limitation? – Ghad Apr 25 '18 at 15:25

1 Answers1

1

This is a limitation of adaptive cards in webchat. Luckily there is a workaround.

WIthout making any changes you will see a limit of 5 Actions you can see this when you go to the visualizer and add over 5 actions such as

{
    "type": "Action.OpenUrl",
    "title": "View",
    "url": "http://adaptivecards.io"
},
{
    "type": "Action.OpenUrl",
    "title": "View",
    "url": "http://adaptivecards.io"
},
{
    "type": "Action.OpenUrl",
    "title": "View",
    "url": "http://adaptivecards.io"
},
{
    "type": "Action.OpenUrl",
    "title": "View",
    "url": "http://adaptivecards.io"
},
{
    "type": "Action.OpenUrl",
    "title": "View",
    "url": "http://adaptivecards.io"
},
{
    "type": "Action.OpenUrl",
    "title": "View",
    "url": "http://adaptivecards.io"
}

you will get this error:

enter image description here

However, you can change this. It can be achieved by editing the host config file in the visualizer Specifically the maxactions field. webchat includes a host config file as well so in theory you could just edit that file and it should work.

"actions": {
    "maxActions": 20,
    "spacing": "default",
    "buttonSpacing": 8,
    "showCard": {
      "actionMode": "inline",
      "inlineTopMargin": 8
    },
    "actionsOrientation": "vertical",
    "actionAlignment": "stretch"
  },
D4RKCIDE
  • 3,439
  • 1
  • 18
  • 34
  • Thanks You Jason, i will try it in a minute :) – Ghad Apr 25 '18 at 19:17
  • Looking into the source of the webchat, there is a file with has the configuration for the adaptive cards **adaptivecards-hostconfig.json** [link](https://gist.github.com/GuillermoADC/b161b2f00b9c933f54208a7b85db27bc), but its seens that no have any effects. – Ghad Apr 25 '18 at 20:02
  • Well, that shoots my idea in the foot. How are you using webchat? via a custom build I assume? Not via Iframe? – D4RKCIDE Apr 25 '18 at 20:07
  • Yea, i using webchat via custom build. – Ghad Apr 25 '18 at 20:34
  • Thank you @JasonSowers :). Looking into the code I see that the webchat is using this.props.hostconfig instead of the defaultsHostConfig which has the maxAction 100 `mountAdaptiveCards() { // Render for non adaptative cards debugger; const adaptiveCard = this.props.nativeCard || new AdaptiveCard(); console.error("Check HERE the props of the default hosting config"); debugger; adaptiveCard.hostConfig = this.props.hostConfig || defaultHostConfig;` – Ghad Apr 25 '18 at 20:59
  • I would file this as a bug/issue in the [webchat repo](https://github.com/Microsoft/BotFramework-WebChat) and the experts over there can have a look at it. The bug being that changing the host config does not actually work. Once you do that, I can bug that team to take a look at it. – D4RKCIDE Apr 25 '18 at 21:00
  • Ahh so you found a solution? – D4RKCIDE Apr 25 '18 at 21:01
  • Yea, now i will try to see why is using this.props.hostConfig instead of the default. Thank you for all the help :) – Ghad Apr 25 '18 at 21:03