public override void Apply <T>(ref IMessageActivity message, string prompt, IList <T> options) { if (message.ChannelId.Equals("facebook", StringComparison.InvariantCultureIgnoreCase) && this.PromptStyle == PromptStyle.Auto && options != null && options.Any()) { var channelData = new FacebookChannelData(); var quickReplies = new List <FacebookQuickReply>(); foreach (var option in options) { var quickReply = option as FacebookQuickReply; if (quickReply == null) { quickReply = new FacebookTextQuickReply(option.ToString(), option.ToString()); } quickReplies.Add(quickReply); } channelData.QuickReplies = quickReplies.ToArray(); message.Text = prompt; message.ChannelData = channelData; } else { base.Apply <T>(ref message, prompt, options); } }
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> result) { await context.PostAsync("Hi! I'm sample bot that will show you how to use Facebook's Quick Replies with BotFramework."); var reply = context.MakeMessage(); reply.Text = "What's your favorite color?"; if (reply.ChannelId.Equals("facebook", StringComparison.InvariantCultureIgnoreCase)) { //var channelData = JObject.FromObject(new //{ // quick_replies = new dynamic[] // { // new // { // content_type = "text", // title = "Blue", // payload = "DEFINED_PAYLOAD_FOR_PICKING_BLUE", // image_url = "https://cdn3.iconfinder.com/data/icons/developperss/PNG/Blue%20Ball.png" // }, // new // { // content_type = "text", // title = "Green", // payload = "DEFINED_PAYLOAD_FOR_PICKING_GREEN", // image_url = "https://cdn3.iconfinder.com/data/icons/developperss/PNG/Green%20Ball.png" // }, // new // { // content_type = "text", // title = "Red", // payload = "DEFINED_PAYLOAD_FOR_PICKING_RED", // } // } //}); var channelData = new FacebookChannelData { QuickReplies = new[] { new FacebookTextQuickReply("Blue", "DEFINED_PAYLOAD_FOR_PICKING_BLUE", "https://cdn3.iconfinder.com/data/icons/developperss/PNG/Blue%20Ball.png"), new FacebookTextQuickReply("Green", "DEFINED_PAYLOAD_FOR_PICKING_GREEN", "https://cdn3.iconfinder.com/data/icons/developperss/PNG/Green%20Ball.png"), new FacebookTextQuickReply("Red", "DEFINED_PAYLOAD_FOR_PICKING_RED") } }; reply.ChannelData = channelData; } await context.PostAsync(reply); context.Wait(this.OnColorPicked); }
private static async Task SendCard(IDialogContext context, Card card) { try { // Title var title = CardHelper.GetTitle(card.IntentionId); await context.PostAsync(title); //send a feeback to user var activity = context.MakeMessage(); activity.Type = ActivityTypes.Typing; await context.PostAsync(activity); // Image var imageMessage = context.MakeMessage(); imageMessage.Attachments.Add(new Attachment { ContentType = "image/jpg", ContentUrl = card.ImageLink }); await context.PostAsync(imageMessage); // Buttons var reply = context.MakeMessage(); if (reply.ChannelId == null) { reply.ChannelId = "facebook"; } if (reply.ChannelId.Equals("facebook", StringComparison.InvariantCultureIgnoreCase)) { reply.Text = card.Content.Replace("\n", "<br/>"); var channelData = new FacebookChannelData { QuickReplies = new[] { new FacebookTextQuickReply("Show another", $"SHOW_ANOTHER_{card.IntentionId}"), new FacebookTextQuickReply("Change topic", "CHANGE_TOPIC") } }; reply.ChannelData = channelData; await context.PostAsync(reply); } } catch (Exception) { await context.PostAsync("We don't understand your request. Please type a new message"); } }
private static async Task SendTopics(IDialogContext context, List <Intention> intentions) { var reply = context.MakeMessage(); if (reply.ChannelId.Equals("facebook", StringComparison.InvariantCultureIgnoreCase)) { reply.Text = "Which topic inspires you?"; var channelData = new FacebookChannelData { QuickReplies = intentions .Select(i => new FacebookTextQuickReply(i.Label, "CHANGE_TOPIC_" + i.IntentionId)).ToArray() }; reply.ChannelData = channelData; await context.PostAsync(reply); } }