Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft Bot Framework messages with buttons in Facebook Messenger

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, deployed it and can communicate with it through Messenger and am now trying to refine the appearance of the bot's responses. I have been able to create single cards and carousels by putting the card info into Message.Attachements but I'd like to also include action buttons. The Messenger Platform docs describe button and "generic" templates in their Send API Reference but for the life of me I can't figure out how to coerce the Bot Connector to send buttons to Messenger. It'd be great if I could just put the Send API json into the Message.ChannelData property but no luck. Has anyone managed to get Messenger to show buttons from the Bot Framework?

like image 978
Bill Avatar asked May 03 '16 18:05

Bill


People also ask

Does Facebook Messenger allow bots?

Facebook Messenger bots live within Facebook Messenger, and can converse with some of the 1.3 billion people who use Facebook Messenger every month. Chatbots are like virtual assistants. They can be programmed to understand questions, provide answers, and execute tasks.

How can you tell a bot on Facebook Messenger?

Under the Home tab (house icon), you'll see a search bar at the top. Tap it. Facebook Messenger will then show you a small selection of bots it recommends (beneath a list of people you can start chats with). You can also use the search bar at the top of this screen to search for other available bots.

What is the best chatbot for Facebook Messenger?

ManyChat is considered one of the best free chatbot platforms available, and it's easy to see why. You don't need coding skills to build Facebook Messenger chatbots using Manychat.


1 Answers

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);
like image 95
Shahin Shayandeh Avatar answered Oct 05 '22 22:10

Shahin Shayandeh