agentpx
agentpx

Reputation: 1081

BotFramework Action does not rendered as Buttons (empty) in Facebook Messenger and Telegram

I'm trying Microsoft Bot Connector action to be rendered as Buttons in Facebook Messenger but it is not being rendered as expected. In fact the messenger does not display anything. While Testing on the BotFramework Emulator only display the .Text property but does not display buttons as well.

class myFactory
{

public static IForm<myButton> BuildForm()
{
    return new FormBuilder<myButton>()
           .Message("Welcome to my test Button!")
           .OnCompletionAsync(async (context, myButton) =>
           {
               var reply = context.MakeMessage();
               reply.Text = "Test actions";
               reply.Attachments = new List<Attachment>();

               var actions = new List<Microsoft.Bot.Connector.Action>();

               actions.Add(new Microsoft.Bot.Connector.Action() { Title = "button1", Message = "message1", Url = "http://google.com" });
               actions.Add(new Microsoft.Bot.Connector.Action() { Title = "button2", Message = "message2", Url = "http://google.com" });
               actions.Add(new Microsoft.Bot.Connector.Action() { Title = "button3", Message = "message3", Url = "http://google.com" });

               Attachment at = new Attachment();
                   at.Title = "Choose One:";
                   at.Actions = actions;
                   at.ContentType = "template";
                   at.Text = "Text choose";
                   at.TitleLink = "http://www.google.com";
                   at.ContentUrl = "http://msdn.microsoft.com";

                   reply.Attachments.Add(at);

                    await context.PostAsync(reply);
           })
           .Build();
    }
};

Upvotes: 1

Views: 1236

Answers (3)

Kien Chu
Kien Chu

Reputation: 4895

in the newest version of botbuilder (v1.2.3), by default, prompt will be generated as selectable buttons in supported chat platforms (for example: telegram, facebook).

Reference: https://github.com/Microsoft/BotBuilder/blob/master/CSharp/Library/FormFlow/FormDialog.cs

Relevant code:

if (prompt != null)
{
    var msg = context.MakeMessage();
    msg.Text = prompt.Prompt;
    msg.Attachments = prompt.Buttons.GenerateAttachments();
    await context.PostAsync(msg);
}
return prompt;

Upvotes: 0

Shahin Shayandeh
Shahin Shayandeh

Reputation: 304

Buttons should work universally across all Facebook messenger clients, kik, and telegram. I guess you are using an older version of Facebook messenger app that doesn't have support for buttons and carousel. I generate buttons in my bot using Actions and rely on connector to downgrade them to text options for channels that don't have button support. Here is an example of a bot with attachments that works with facebook.

Upvotes: 1

Bill
Bill

Reputation: 75

I've not worked with Telegram but for Facebook action buttons you only need to supply the Message or the Url, not both. If the Url property is supplied then the action button will link out to that url but when the Message is supplied then when clicked that text will be sent to your bot as if the user had typed it.

Also, the ContentType and ContentUrl in the Attachment might be causing problems. The ContentUrl, if supplied, should point to an image or video and then the ContentType should be "image" or "video". You do not need to specify "template", the Bot Connector does that for you. Try something like:

var reply = context.MakeMessage();
reply.Text = "Test actions";
reply.Attachments = new List<Attachment>();

var actions = new List<Microsoft.Bot.Connector.Action>();

actions.Add(new Microsoft.Bot.Connector.Action() { Title = "button1", Message = "message1" });
actions.Add(new Microsoft.Bot.Connector.Action() { Title = "button2", Url = "http://bing.com" });
actions.Add(new Microsoft.Bot.Connector.Action() { Title = "button3", Message = "message3" });

Attachment at = new Attachment();
at.Title = "Choose One:";
at.Actions = actions;

reply.Attachments.Add(at);

Upvotes: 2

Related Questions