/// <summary> /// Creates a 'prompt for feedback' activity with message text and feedback actions defined by passed FeedbackOptions param. /// </summary> /// <param name="context">ITurnContext used to extract channel info to ensure feedback actions are renderable in current channel.</param> /// <param name="feedbackOptions">FeedbackOptions instance used to customize feedback experience.</param> /// <returns> /// A 'prompt for feedback' Activity. /// Has feedback options displayed in a manner supported by the current channel. /// </returns> public static Activity CreateFeedbackActivity(ITurnContext context, FeedbackOptions feedbackOptions = null) { // Check for null options param, if null, instanticate default feedbackOptions = feedbackOptions == null ? new FeedbackOptions() : feedbackOptions; var feedbackActivity = ChoiceFactory.ForChannel(context.Activity.ChannelId, new List<Choice>(feedbackOptions.FeedbackActions) { feedbackOptions.DismissAction }, feedbackOptions.FeedbackPromptMessage); return (Activity)feedbackActivity; }
private static async Task ShowChoices(ITurnContext turnContext, CancellationToken cancellationToken) { // Create choices for the prompt var choices = new List <Choice>(); choices.Add(new Choice() { Value = QuickRepliesOption, Action = new CardAction() { Title = QuickRepliesOption, Type = ActionTypes.PostBack, Value = QuickRepliesOption } }); choices.Add(new Choice() { Value = FacebookPageIdOption, Action = new CardAction() { Title = FacebookPageIdOption, Type = ActionTypes.PostBack, Value = FacebookPageIdOption } }); choices.Add(new Choice() { Value = PostBackOption, Action = new CardAction() { Title = PostBackOption, Type = ActionTypes.PostBack, Value = PostBackOption } }); // Create the prompt message var message = ChoiceFactory.ForChannel(turnContext.Activity.ChannelId, choices, "What looks interesting? Here are some quick replies to choose from:"); await turnContext.SendActivityAsync(message, cancellationToken); }
/// <summary> /// Creates a 'prompt for feedback comment' activity with message text and dismess action defined by passed FeedbackOptions param. /// </summary> /// <param name="context">ITurnContext used to extract channel info to ensure dismiss action is renderable in current channel.</param> /// <param name="feedbackOptions">FeedbackOptions instance used to customize comment prompt text and dismiss action.</param> /// <returns> /// A 'prompt for feedback comment' Activity. /// Has dismiss option displayed in a manner supported by the current channel. /// </returns> public static Activity GetFeedbackCommentPrompt(ITurnContext context, FeedbackOptions feedbackOptions = null) { // Check for null options param, if null, instanticate default feedbackOptions = feedbackOptions == null ? new FeedbackOptions() : feedbackOptions; var message = ChoiceFactory.ForChannel(context.Activity.ChannelId, new List<Choice>() { feedbackOptions.DismissAction }, $"{feedbackOptions.FeedbackReceivedMessage} {feedbackOptions.CommentPrompt}"); return (Activity)message; }
/// <summary> /// Create a prompt for feedback comment activity with message text and dismiss action defined by passed FeedbackOptions parameter. /// </summary> /// <param name="context"></param> /// <returns></returns> public static Activity GetFeedbackCommentPrompt(ITurnContext context, FeedbackOptions feedbackOptions = null) { feedbackOptions ??= new FeedbackOptions(); var choices = new List <Choice> { feedbackOptions.DismissAction }; var message = ChoiceFactory.ForChannel(context.Activity.ChannelId, choices, $"{feedbackOptions.FeedbackReceivedMessage},{feedbackOptions.CommentPrompt}"); return(message as Activity); }
protected Activity GetNavigatePrompt(ITurnContext context, string response, int pageIndex, int maxPage) { var token = new StringDictionary() { { "Navigate", GetNavigateString(pageIndex, maxPage) }, }; var prompt = ResponseManager.GetResponse(response, token); return(ChoiceFactory.ForChannel(context.Activity.ChannelId, GetNavigateList(pageIndex, maxPage), prompt.Text, prompt.Speak) as Activity); }
/// <summary> /// Create a prompt for feedback activity with message text and feedback actions defined by passed FeedbackOptions parameter. /// </summary> /// <param name="context"></param> /// <param name="feedbackOptions"></param> /// <returns></returns> public static Activity CreateFeedbackActivity(ITurnContext context, FeedbackOptions feedbackOptions = null) { feedbackOptions ??= new FeedbackOptions(); var choices = new List <Choice>(feedbackOptions.FeedbackActions) { feedbackOptions.DismissAction }; var feedbackActivity = ChoiceFactory.ForChannel(context.Activity.ChannelId, choices, feedbackOptions.FeedbackPromptMessage); return(feedbackActivity as Activity); }
protected IMessageActivity AppendChoices(IMessageActivity prompt, string channelId, IList <Choice> choices, ListStyle style, ChoiceFactoryOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { // Get base prompt text (if any) var text = prompt != null && !string.IsNullOrEmpty(prompt.Text) ? prompt.Text : string.Empty; // Create temporary msg IMessageActivity msg; switch (style) { case ListStyle.Inline: msg = ChoiceFactory.Inline(choices, text, null, options); break; case ListStyle.List: msg = ChoiceFactory.List(choices, text, null, options); break; case ListStyle.SuggestedAction: msg = ChoiceFactory.SuggestedAction(choices, text); break; case ListStyle.None: msg = Activity.CreateMessageActivity(); msg.Text = text; break; default: msg = ChoiceFactory.ForChannel(channelId, choices, text, null, options); break; } // Update prompt with text and actions if (prompt != null) { // clone the prompt the set in the options (note ActivityEx has Properties so this is the safest mechanism) prompt = JsonConvert.DeserializeObject <Activity>(JsonConvert.SerializeObject(prompt)); prompt.Text = msg.Text; if (msg.SuggestedActions != null && msg.SuggestedActions.Actions != null && msg.SuggestedActions.Actions.Count > 0) { prompt.SuggestedActions = msg.SuggestedActions; } return(prompt); } else { msg.InputHint = InputHints.ExpectingInput; return(msg); } }
protected IMessageActivity AppendChoices(IMessageActivity prompt, string channelId, IList <Choice> choices, ListStyle style, ChoiceFactoryOptions options = null) { // Get base prompt text (if any) var text = prompt != null && !string.IsNullOrEmpty(prompt.Text) ? prompt.Text : string.Empty; // Create temporary msg IMessageActivity msg; switch (style) { case ListStyle.Inline: msg = ChoiceFactory.Inline(choices, text, null, options); break; case ListStyle.List: msg = ChoiceFactory.List(choices, text, null, options); break; case ListStyle.SuggestedAction: msg = ChoiceFactory.SuggestedAction(choices, text); break; case ListStyle.None: msg = Activity.CreateMessageActivity(); msg.Text = text; break; default: msg = ChoiceFactory.ForChannel(channelId, choices, text, null, options); break; } // Update prompt with text and actions if (prompt != null) { prompt.Text = msg.Text; if (msg.SuggestedActions != null && msg.SuggestedActions.Actions != null && msg.SuggestedActions.Actions.Count > 0) { prompt.SuggestedActions = msg.SuggestedActions; } return(prompt); } else { msg.InputHint = InputHints.ExpectingInput; return(msg); } }
public void ShouldAutomaticallyChooseRenderStyleBasedOnChannelType() { var activity = ChoiceFactory.ForChannel("emulator", colorChoices, "select from:"); Assert.AreEqual("select from:", activity.Text); Assert.IsNotNull(activity.SuggestedActions); Assert.AreEqual(3, activity.SuggestedActions.Actions.Count); Assert.AreEqual("imBack", activity.SuggestedActions.Actions[0].Type); Assert.AreEqual("red", activity.SuggestedActions.Actions[0].Value); Assert.AreEqual("red", activity.SuggestedActions.Actions[0].Title); Assert.AreEqual("imBack", activity.SuggestedActions.Actions[1].Type); Assert.AreEqual("green", activity.SuggestedActions.Actions[1].Value); Assert.AreEqual("green", activity.SuggestedActions.Actions[1].Title); Assert.AreEqual("imBack", activity.SuggestedActions.Actions[2].Type); Assert.AreEqual("blue", activity.SuggestedActions.Actions[2].Value); Assert.AreEqual("blue", activity.SuggestedActions.Actions[2].Title); }
public void ShouldChooseCorrectStylesForTeams() { var activity = ChoiceFactory.ForChannel(Channels.Msteams, colorChoices, "select from:"); Assert.IsNotNull(activity.Attachments); var heroCard = (HeroCard)activity.Attachments.First().Content; Assert.AreEqual(3, heroCard.Buttons.Count); Assert.AreEqual(ActionTypes.ImBack, heroCard.Buttons[0].Type); Assert.AreEqual("red", heroCard.Buttons[0].Value); Assert.AreEqual("red", heroCard.Buttons[0].Title); Assert.AreEqual(ActionTypes.ImBack, heroCard.Buttons[1].Type); Assert.AreEqual("green", heroCard.Buttons[1].Value); Assert.AreEqual("green", heroCard.Buttons[1].Title); Assert.AreEqual(ActionTypes.ImBack, heroCard.Buttons[2].Type); Assert.AreEqual("blue", heroCard.Buttons[2].Value); Assert.AreEqual("blue", heroCard.Buttons[2].Title); }
public async Task Prompt(ITurnContext context, List <Choice> choices, string prompt = null, string speak = null) { BotAssert.ContextNotNull(context); if (choices == null) { throw new ArgumentNullException(nameof(choices)); } IMessageActivity msg; switch (Style) { case ListStyle.Inline: msg = ChoiceFactory.Inline(choices, prompt, speak, ChoiceOptions); break; case ListStyle.List: msg = ChoiceFactory.List(choices, prompt, speak, ChoiceOptions); break; case ListStyle.SuggestedAction: msg = ChoiceFactory.SuggestedAction(choices, prompt, speak); break; case ListStyle.None: msg = Activity.CreateMessageActivity(); msg.Text = prompt; msg.Speak = speak; break; case ListStyle.Auto: default: msg = ChoiceFactory.ForChannel(context, choices, prompt, speak, ChoiceOptions); break; } msg.InputHint = InputHints.ExpectingInput; await context.SendActivity(msg); }
private static async Task ShowChoices(ITurnContext turnContext, CancellationToken cancellationToken) { // Create the message var message = ChoiceFactory.ForChannel(turnContext.Activity.ChannelId, _options, "Secondary Bot: Please type a message or choose an option"); await turnContext.SendActivityAsync(message, cancellationToken); }