I\'m working on a bot using the C# Microsoft Bot Framework and I\'d like to send messages with action buttons to Facebook Messenger. I\'ve successfully created the bot, depl
To add buttons to your message, you can add multiple actions to the attachment. Each action will be mapped to a button by connector. Multiple attachments will be mapped into a carousel in Facebook messenger. Below is an example of adding 3 buttons to the message.
var reply = context.MakeMessage();
reply.Attachments = new List<Attachment>();
var actions = new List<Microsoft.Bot.Connector.Action>();
for (int i = 0; i < 3; i++)
{
actions.Add(new Microsoft.Bot.Connector.Action
{
Title = $"Button:{i}",
Message = $"Action:{i}"
});
}
reply.Attachments.Add(new Attachment
{
Title = "Choose one:",
Actions = actions
});
await context.PostAsync(reply);
Updating solution for version 3.9.0 :
var actions = new List<CardAction>();
for (int i = 0; i < 3; i++)
{
actions.Add(new CardAction
{
Title = $"Button:{i}",
Text = $"Action:{i}"
});
}
reply.Attachments.Add(
new HeroCard
{
Title = "Choose option",
Buttons = actions
}.ToAttachment()
);
await context.PostAsync(reply);