Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am using Bot Framework 3.3.0 which I understand supports Facebook's quick replies implemented properly (as opposed to creating a dynamic object and sending it via ChannelData). The class name is Microsoft.Bot.Builder.ConnectorEx.FacebookQuickReply.

Here is how I create the quick replies from within an IDialog:

var reply = context.MakeMessage();
reply.Text = msg;
var quickReplies = new List<FacebookQuickReply>()
{
    new FacebookQuickReply(FacebookQuickReply.ContentTypes.Text, "Cathay", "Cathay"),
    new FacebookQuickReply(FacebookQuickReply.ContentTypes.Text, "HK Airlines", "Hong Kong Airlines"),
    new FacebookQuickReply(FacebookQuickReply.ContentTypes.Text, "HK Express", "HK Express")
};

And here are the two ways of how I'm trying to send them into the chat:

//I tried both of the lines below
//reply.ChannelData = quickReplies.ToArray();
reply.AddKeyboardCard<FacebookQuickReply>("quick_replies", quickReplies);

await context.PostAsync(reply);

The first way that I got from Ezequiel Jadib's article (hi, I know you're reading this!) didn't work for me on facebook messenger. Partly the reason is that it seems in v3.3 the FacebookQuickReply class is now sealed and cannot be derived from.

UPDATE: I got it to work by using this:

var channelData = new FacebookChannelData();

channelData.QuickReplies = new[]
{
    new FacebookQuickReply(FacebookQuickReply.ContentTypes.Text, "Cathay", "Cathay"),
    new FacebookQuickReply(FacebookQuickReply.ContentTypes.Text, "HK Airlines", "Hong Kong Airlines"),
    new FacebookQuickReply(FacebookQuickReply.ContentTypes.Text, "HK Express", "HK Express")
};

reply.ChannelData = channelData;

Where FacebookChannelData class is simply this:

public class FacebookChannelData
{
    [JsonProperty("quick_replies")]
    public FacebookQuickReply[] QuickReplies { get; set; }
}

Even though it works, it doesn't seem to be a proper way because the bot framework now provides ready to use classes for that.

END UPDATE

The second way (AddKeyboardCard) kind of works in the emulator (but doesn't work on actual facebook), but produces totally wrong JSON that I can see in the emulator. The resulting JSON uses the class name (why?) instead of the text I provided:

"attachments": [
    {
      "contentType": "application/vnd.microsoft.card.hero",
      "content": {
        "text": "quick_replies",
        "buttons": [
          {
            "type": "imBack",
            "title": "Microsoft.Bot.Builder.ConnectorEx.FacebookQuickReply",
            "value": "Microsoft.Bot.Builder.ConnectorEx.FacebookQuickReply"
          },
          {
            "type": "imBack",
            "title": "Microsoft.Bot.Builder.ConnectorEx.FacebookQuickReply",
            "value": "Microsoft.Bot.Builder.ConnectorEx.FacebookQuickReply"
          },
          {
            "type": "imBack",
            "title": "Microsoft.Bot.Builder.ConnectorEx.FacebookQuickReply",
            "value": "Microsoft.Bot.Builder.ConnectorEx.FacebookQuickReply"
          }
        ]
      }
    }
  ],

What am I doing wrong and how do you use FacebookQuickReply and AddKeyboardCard()?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
102 views
Welcome To Ask or Share your Answers For Others

1 Answer

The key of the FacebookQuickReply feature recently added is on this commit.

It seems the way to go is to create a KeyboardCard and the use the ToFacebookMessage extension method to get the ChannelData value (as used here)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...