I've added 6 buttons in Hero card and tried to display them. It works fine in Teams and emulator but doesn't work on Skype. It just displays 3 buttons.
private List<CardAction> GetCardButton(List<string> opts)
{
List<CardAction> cardButtons = new List<CardAction>();
int i = 1;
foreach(string opt in opts)
{
CardAction plButton = new CardAction()
{
Title = opt,
Type = "postBack",
Text = i.ToString(),
Value = i.ToString()
};
cardButtons.Add(plButton);
i++;
}
return cardButtons;
}
//passing list of strings.
List<CardAction> cardButtons = GetCardButton(cardOpts);
HeroCard plCard = new HeroCard()
{
Title = "Try here",
Text = "with:",
Buttons = cardButtons
};
plAttachment = plCard.ToAttachment();
But in skype i see only first 3 buttons. is there any way to make the card scrollable or reduce button size?
As shown in the previous answer each channel has limitations on what exactly can be displayed, number of buttons, length of the text, etc. It seems you are running into this limitation. one thing you can do is if there are more than three buttons display another card and present them in a list or a carousel.
here is a hacked together code example:
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Bot_Application13.Dialogs
{
[Serializable]
public class RootDialog : IDialog<object>
{
public Task StartAsync(IDialogContext context)
{
context.Wait(MessageReceivedAsync);
return Task.CompletedTask;
}
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
List<Attachment> cards = new List<Attachment>();
List<CardAction> buttons = new List<CardAction>();
for (int i = 0; i < 10; i++)
{
CardAction ca = new CardAction()
{
Title = i.ToString(),
Type = "postBack",
Text = i.ToString(),
Value = i.ToString()
};
buttons.Add(ca);
}
var reply = context.MakeMessage();
GetCardsAttachments(buttons, cards);
//reply.AttachmentLayout = AttachmentLayoutTypes.List;
//or
reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
reply.Attachments = cards;
await context.PostAsync(reply);
context.Wait(this.MessageReceivedAsync);
}
private Attachment GetHeroCard(List<CardAction> buttons)
{
var heroCard = new HeroCard();
//heroCard.Title = "Title";
heroCard.Buttons = buttons;
return heroCard.ToAttachment();
}
private void GetCardsAttachments(List<CardAction> buttons, List<Attachment> cards)
{
if (buttons.Count <= 3)
{
cards.Add(GetHeroCard(buttons));
}
else
{
var temp = new List<CardAction>();
for (int i = 0; i < buttons.Count; i++)
{
if (i % 3 != 0)
{
temp.Add(buttons.ElementAt(i));
}
else
{
if (i != 0)
{
cards.Add(GetHeroCard(temp));
}
temp = new List<CardAction>();
temp.Add(buttons.ElementAt(i));
}
}
cards.Add(GetHeroCard(temp));
}
}
}
}