David
David

Reputation: 31

Does botbuilder support Facebook Messenger's Button Template?

After reading this question, which is quite old now: Does the Bot Framework support Facebook Messenger's Button Template? and viewing the list of available cards using Bot Framework.

Does botbuilder currently support Facebook Messenger's Button Template? I would like the solution to be channel-agnostic so no JSON would be required to manipulate in order to achieve this. I've tried using the hero card with no title and no image but the result is not aesthetically pleasant and the normal text stays in bold.

enter image description here

This is the code which renders de card:

const attachment = CardFactory.heroCard(
        "",
        "BotFramework Hero Card",
        CardFactory.images([]),
        CardFactory.actions([
            {
                type: "openUrl",
                title: "Get started",
                value: "https://learn.microsoft.com/en-us/azure/bot-service/"
            },
            {   
                type: "openUrl",
                title: "Get started2",
                value: "https://learn.microsoft.com/en-us/azure/bot-service/"
            }
        ])
    );

    return MessageFactory.attachment(attachment);

Tried also with the ThumbnailCard but shows the same result...

Upvotes: 2

Views: 153

Answers (1)

Kyle Delaney
Kyle Delaney

Reputation: 12264

If you send a hero card through the Facebook connector then it will automatically be converted to a button template if the card has only buttons and no text or images, and it will be converted to a generic template otherwise. If you want to send a customized template of your choice, you can use Bot Framework channel data. It might look something like this:

reply = {
    'type': ActivityTypes.Message,
    'channelData': {
        'attachment': {
            'type': 'template',
            'payload': {
                'template_type': 'button',
                'text': 'Button Template',
                'buttons': buttons
            }
        }
    }
};

Note that while the answer to your question is yes, you may still be unsatisfied. You only asked for a way to use the button template instead of the generic template but your reasoning was that you want it to look better. The problem there is that the look will depend on which Messenger client you're using, and in some clients this button template will look no different from a generic template. If you try out the button template and you're still unsatisfied then you may have to do some experimenting. I think the fastest way to test this would be to send messages as your bot in an HTTP application like Postman using the Bot Framework REST API.

Upvotes: 1

Related Questions