Alexander
Alexander

Reputation: 12785

How to create Quick Replies using MS Bot Framework on Facebook Messenger?

I have been using Node.js and the MS Bot Framework(3.0) for my bot development needs for quite some time now.

One of my needs is to request a user to share its e-mail address with the bot.
Facebook offers a Quick Replies API exactly for that.

I am having a hard time understanding how should i utilize the framework to create a custom message with the quick reply option.

One of my first attempts was to pass native metadata to a channel using custom channel data
I have succeeded implementing various templates which are supported by Messenger platform, but quick replies are sort of other beast compared to buttons, lists and other templates. currently i struggle to create a quick reply message using the framework provided tools.

Please point me in the right direction.

Upvotes: 1

Views: 936

Answers (2)

tdurnford
tdurnford

Reputation: 3712

You can send Facebook quick replies either through the source data in V3 of the BotFramework or through the channel data in V4 of the framework. See the two examples below:

Node

V4

await turnContext.sendActivity({
    text: 'What is your email?',
    channelData: {
        "quick_replies":[
            {
                "content_type": "user_email"
            }
        ]
    }
});

V3

var message = new botbuilder.Message(session)
   .text('What is your email?')
   .sourceEvent({
      facebook: {
         "quick_replies":[
            {
               "content_type": "user_email"
            }
         ]
      }
   });

session.send(message);

CSharp

V4

Activity reply = turnContext.Activity.CreateReply();
reply.Text = "What is your location?";
reply.ChannelData = JObject.FromObject( new {
    quick_replies = new object[]
    {
        new
        {
            content_type = "location",
        },
    },
});

await turnContext.SendActivityAsync(reply, cancellationToken);

Hope this helps!

Upvotes: 7

carlo
carlo

Reputation: 107

On v3 you can just add the JSON of the quick_reply template defined by facebook to the channeldata as JSON object (JObject)

reply.channelData = new JOBject("[JSON HERE]");

Upvotes: 0

Related Questions