Akash Pavate
Akash Pavate

Reputation: 93

Issue with List of buttons in Microsoft Bot Builder for .NET - Channel: Facebook Messenger

I am trying to add a list of buttons as inside a herocard. It works fine in Bot Emulator but doesn't work in Messenger Channel. Here's my code.

public static IList<Attachment> ToAttachmentList(this List<string> items)
{
        var attachments = new List<Attachment>();
        var actions = new List<CardAction>();

        foreach (var item in items)
        {
            actions.Add(new CardAction(ActionTypes.ImBack, title: item, value: item));
        }

        var heroCard = new HeroCard
        {
            Buttons = actions
        };

        attachments.Add(heroCard.ToAttachment());

        return attachments;
}

private async Task ShowOptions(IDialogContext context)
{
        var reply = context.MakeMessage();
        reply.Text = $"Here's what you can do.";
        reply.AttachmentLayout = AttachmentLayoutTypes.List;
        reply.Attachments = Messages.OrderingOptions.ToAttachmentList();

        await context.PostAsync(reply);
}

Output in Bot Emulator

Output in Messenger

In Messenger, the last button gets added as a Carousel, all the button text is truncated.

Please help me fix this.

In Messenger

Upvotes: 1

Views: 904

Answers (1)

Ezequiel Jadib
Ezequiel Jadib

Reputation: 14787

Per the documentation, the button title has a 20 character limit.

Also, if you have more that 3 buttons, Facebook will split them as the Button template expects from 1-3 buttons.

You will need to limit the characters to 20, so instead of "I want to order pizza", you might want to use "Order pizza" for example. To add more buttons; you might want to explore Quick Replies since the limit is 11 "buttons" (but you still have the 20 chars limit on the title). You can check this other post to understand more about Quick Replies.

Upvotes: 2

Related Questions