private ChoicePromptOptions GenerateOptions(DialogContext dc) { var choices = new List <Choice>(); Task <List <SKU> > response = Task.Run <List <SKU> >( async() => await _kenticoRestService.GetTopSKUsAsync(5) ); List <SKU> skus = response.Result; dc.ActiveDialog.State.Add("skus", skus); skus.ForEach(x => choices.Add( new Choice() { Value = $"{x.SKUName.Replace("+", "and")} {x.SKUPrice:C} USD".Replace("$", ""), Synonyms = new List <string> { x.SKUID.ToString() } }) ); var promptOptions = new ChoicePromptOptions() { Choices = choices, RetryPromptString = "Please choose a product." }; return(promptOptions); }
private async Task ChooseProductsToBuy(DialogContext dc, IDictionary <string, object> args, SkipStepFunction next) { var cardPrompt = new Microsoft.Bot.Builder.Dialogs.ChoicePrompt(Culture.English) { Style = Microsoft.Bot.Builder.Prompts.ListStyle.List }; ChoicePromptOptions cardOptions = GenerateOptions(dc); await dc.Prompt("productsPrompt", "Which of our popular items would you like to add to your order:", cardOptions).ConfigureAwait(false); }
public async Task BasicChoicePrompt() { TestAdapter adapter = new TestAdapter() .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage())); await new TestFlow(adapter, async(turnContext) => { var dialogs = new DialogSet(); dialogs.Add("test-prompt", new ChoicePrompt(Culture.English) { Style = ListStyle.Inline }); var state = ConversationState <Dictionary <string, object> > .Get(turnContext); var dc = dialogs.CreateContext(turnContext, state); await dc.Continue(); var dialogResult = dc.DialogResult; if (!dialogResult.Active) { if (dialogResult.Result != null) { var choiceResult = (ChoiceResult)dialogResult.Result; await turnContext.SendActivity($"Bot received the choice '{choiceResult.Value.Value}'."); } else { var promptOptions = new ChoicePromptOptions { Choices = new List <Choice> { new Choice { Value = "red" }, new Choice { Value = "green" }, new Choice { Value = "blue" }, } }; await dc.Prompt("test-prompt", "favorite color?", promptOptions); } } }) .Send("hello") .AssertReply("favorite color? (1) red, (2) green, or (3) blue") .Send("green") .AssertReply("Bot received the choice 'green'.") .StartTest(); }
public RichCardsBot() { dialogs = new DialogSet(); // Choice prompt with list style to show card types var cardPrompt = new ChoicePrompt(Culture.English) { Style = Microsoft.Bot.Builder.Prompts.ListStyle.List }; cardOptions = GenerateOptions(); // Register the card prompt dialogs.Add("cardPrompt", cardPrompt); // Create a dialog waterfall for prompting the user dialogs.Add("cardSelector", new WaterfallStep[] { ChoiceCardStep, ShowCardStep }); }
public AAAClaimBot() { dialogs = new DialogSet(); var cardPrompt = new PromptsDialog.ChoicePrompt(Culture.English) { Style = Microsoft.Bot.Builder.Prompts.ListStyle.List }; cardOptions = GenerateOptions(); dialogs.Add(PromptStep.NamePrompt, new PromptsDialog.TextPrompt(NameValidator)); // Add a dialog that uses both prompts to gather information from the user dialogs.Add(PromptStep.GatherInfo, new WaterfallStep[] { AskNameStep, GatherInfoStep }); dialogs.Add(CARD_PROMPT_ID, cardPrompt); dialogs.Add(CARD_SELECTOR_ID, new WaterfallStep[] { ChoiceCardStep, ShowCardStep }); dialogs.Add("session", new StartSessionDialog()); }
public MyBot() { if (dialogs == null) { dialogs = new DialogSet(); dialogs.Add("initial", new WaterfallStep[] { async(dc, args, next) => { var convo = ConversationState <Dictionary <string, object> > .Get(dc.Context); if (convo.ContainsKey("Name")) { await next.Invoke(args); } else { dc.ActiveDialog.State = new Dictionary <string, object>(); await dc.Prompt("textPrompt", "Hey there ya shifty wanker! What's your name?"); } }, async(dc, args, next) => { var convo = ConversationState <Dictionary <string, object> > .Get(dc.Context); if (args != null) { convo["Name"] = args["Value"]; } Choice echoBotChoice = new Choice { Value = "echo_bot" /* * Action = new CardAction * { * Type = ActionTypes.ImBack, * Title = "Echo Bot", * Text = "Echo Bot", * Value = "echo_bot" * } */ }; var prompt = new ChoicePromptOptions { Choices = new List <Choice>() { new Choice { Value = "echo_bot" }, new Choice { Value = "intent_bot" }, new Choice { Value = "luis_bot" }, new Choice { Value = "I'm Done Here" } } }; await dc.Prompt("choicePrompt", $"What Bot do you want to play with, {convo["Name"]}?", prompt); }, async(dc, args, next) => { var foundChoice = (FoundChoice)args["Value"]; await dc.Prompt("textPrompt", $"You selected: {foundChoice.Value}"); switch (foundChoice.Value) { case "echo_bot": await dc.Replace("echo", args); break; case "intent_bot": await dc.Replace("intent", args); break; case "I'm Done Here": await dc.Context.SendActivity("See ya!"); await dc.End(); break; default: await dc.Context.SendActivity("You selected something I don't understand."); await dc.Replace("initial"); break; } } }); dialogs.Add("echo", new WaterfallStep[] { async(dc, args, next) => { var convo = ConversationState <Dictionary <string, object> > .Get(dc.Context); if (!convo.ContainsKey("promptedOnce")) { convo["promptedOnce"] = true; await dc.Prompt("textPrompt", $"Tell me something, {convo["Name"]}. Say 'done' to quit."); } else { await dc.Prompt("textPrompt", "Tell me something else..."); } }, async(dc, args, next) => { string whatYouSaid = (string)args["Value"]; if (whatYouSaid.ToLower() == "done") { await dc.Replace("initial"); } else { await dc.Prompt("textPrompt", $"You said {whatYouSaid}"); await dc.Replace("echo"); } } }); dialogs.Add("intent", new WaterfallStep[] { async(dc, args, next) => { var prompt = new ChoicePromptOptions { Choices = new List <Choice>() { new Choice { Value = "Latest Checkstub" }, new Choice { Value = "Retirement Plans" }, new Choice { Value = "PTO Balances" }, new Choice { Value = "I'm Done Here" } } }; var convo = ConversationState <Dictionary <string, object> > .Get(dc.Context); await dc.Prompt("choicePrompt", $"Go ahead {convo["Name"]}, what do you want to view?", prompt); }, async(dc, args, next) => { var foundChoice = (FoundChoice)args["Value"]; await dc.Prompt("textPrompt", $"You selected: {foundChoice.Value}"); if (foundChoice.Value == "I'm Done Here") { await dc.Replace("initial"); } else { await dc.Replace("intent"); } } }); dialogs.Add("textPrompt", new TextPrompt()); dialogs.Add("choicePrompt", new ChoicePrompt(Culture.English)); } }
public BookTable() : base("BookTable") { var promptOptions = new ChoicePromptOptions { Choices = new List <Choice> { new Choice { Value = "Seattle" }, new Choice { Value = "Bellevue" }, new Choice { Value = "Renton" }, } }; //Dialogs.Add("textPrompt", new TextPrompt()); Dialogs.Add("choicePrompt", new ChoicePrompt(Culture.English) { Style = Microsoft.Bot.Builder.Prompts.ListStyle.Auto }); Dialogs.Add("numberPrompt", new NumberPrompt <int>(Culture.English)); Dialogs.Add("timexPrompt", new TimexPrompt(Culture.English, TimexValidator)); Dialogs.Add("confirmationPrompt", new ConfirmPrompt(Culture.English)); Dialogs.Add("BookTable", new WaterfallStep[] { async(dc, args, next) => { dc.ActiveDialog.State = new Dictionary <string, object>(); // await dc.Prompt("textPrompt", "Sure. I can help with that. What City?"); await dc.Prompt("choicePrompt", "Which of our locations would you like?", promptOptions); }, async(dc, args, next) => { var choiceResult = (FoundChoice)args["Value"]; dc.ActiveDialog.State["bookingLocation"] = choiceResult.Value; await dc.Prompt("timexPrompt", $"Ok. I have {dc.ActiveDialog.State["bookingLocation"]} When would you like to arrive? (We open at 4PM.)", new PromptOptions { RetryPromptString = "Sorry, we only accept reservations for the next two weeks, 4PM-8PM" }); }, async(dc, args, next) => { var timexResult = (TimexResult)args; var timexResolution = timexResult.Resolutions.First(); var timexProperty = new TimexProperty(timexResolution.ToString()); var bookingDateTime = $"{timexProperty.ToNaturalLanguage(DateTime.Now)}"; dc.ActiveDialog.State["bookingDateTime"] = bookingDateTime; await dc.Prompt("numberPrompt", $"Ok. I have {dc.ActiveDialog.State["bookingDateTime"]}. How many in your party?"); }, async(dc, args, next) => { dc.ActiveDialog.State["bookingGuestCount"] = args["Value"]; var dialogState = dc.ActiveDialog.State; await dc.Prompt("confirmationPrompt", $"Thanks, Should I go ahead and book a table for {dialogState["bookingGuestCount"].ToString()} guests at our {dialogState["bookingLocation"].ToString()} location for {dialogState["bookingDateTime"].ToString()} ?"); }, async(dc, args, next) => { var dialogState = dc.ActiveDialog.State; // TODO: Verify user said yes to confirmation prompt // TODO: book the table! await dc.Context.SendActivity($"Thanks, I have {dialogState["bookingGuestCount"].ToString()} guests booked for our {dialogState["bookingLocation"].ToString()} location for {dialogState["bookingDateTime"].ToString()}."); } } ); }
public BookTable() : base("BookTable") { var promptOptions = new ChoicePromptOptions { Choices = new List <Choice> { new Choice { Value = "Seattle" }, new Choice { Value = "Bellevue" }, new Choice { Value = "Renton" }, } }; //Dialogs.Add("textPrompt", new TextPrompt()); Dialogs.Add("choicePrompt", new ChoicePrompt(Culture.English) { Style = Microsoft.Bot.Builder.Prompts.ListStyle.Auto }); Dialogs.Add("numberPrompt", new NumberPrompt <int>(Culture.English)); Dialogs.Add("timexPrompt", new TimexPrompt(Culture.English, TimexValidator)); Dialogs.Add("confirmationPrompt", new ConfirmPrompt(Culture.English)); Dialogs.Add("BookTable", new WaterfallStep[] { async(dc, args, next) => { dc.ActiveDialog.State = new Dictionary <string, object>(); IDictionary <string, object> state = dc.ActiveDialog.State; // add any LUIS entities to active dialog state. if (args.ContainsKey("luisResult")) { cafeLUISModel lResult = (cafeLUISModel)args["luisResult"]; updateContextWithLUIS(lResult, ref state); } // prompt if we do not already have cafelocation if (state.ContainsKey("cafeLocation")) { state["bookingLocation"] = state["cafeLocation"]; await next(); } else { await dc.Prompt("choicePrompt", "Which of our locations would you like?", promptOptions); } }, async(dc, args, next) => { var state = dc.ActiveDialog.State; if (!state.ContainsKey("cafeLocation")) { var choiceResult = (FoundChoice)args["Value"]; state["bookingLocation"] = choiceResult.Value; } bool promptForDateTime = true; if (state.ContainsKey("datetime")) { // validate timex var inputdatetime = new string[] { (string)state["datetime"] }; var results = evaluateTimeX((string[])inputdatetime); if (results.Count != 0) { var timexResolution = results.First().TimexValue; var timexProperty = new TimexProperty(timexResolution.ToString()); var bookingDateTime = $"{timexProperty.ToNaturalLanguage(DateTime.Now)}"; state["bookingDateTime"] = bookingDateTime; promptForDateTime = false; } } // prompt if we do not already have date and time if (promptForDateTime) { await dc.Prompt("timexPrompt", "When would you like to arrive? (We open at 4PM.)", new PromptOptions { RetryPromptString = "We only accept reservations for the next 2 weeks and in the evenings between 4PM - 8PM" }); } else { await next(); } }, async(dc, args, next) => { var state = dc.ActiveDialog.State; if (!state.ContainsKey("datetime")) { var timexResult = (TimexResult)args; var timexResolution = timexResult.Resolutions.First(); var timexProperty = new TimexProperty(timexResolution.ToString()); var bookingDateTime = $"{timexProperty.ToNaturalLanguage(DateTime.Now)}"; state["bookingDateTime"] = bookingDateTime; } // prompt if we already do not have party size if (state.ContainsKey("partySize")) { state["bookingGuestCount"] = state["partySize"]; await next(); } else { await dc.Prompt("numberPrompt", "How many in your party?"); } }, async(dc, args, next) => { var state = dc.ActiveDialog.State; if (!state.ContainsKey("partySize")) { state["bookingGuestCount"] = args["Value"]; } await dc.Prompt("confirmationPrompt", $"Thanks, Should I go ahead and book a table for {state["bookingGuestCount"].ToString()} guests at our {state["bookingLocation"].ToString()} location for {state["bookingDateTime"].ToString()} ?"); }, async(dc, args, next) => { var dialogState = dc.ActiveDialog.State; // TODO: Verify user said yes to confirmation prompt // TODO: book the table! await dc.Context.SendActivity($"Thanks, I have {dialogState["bookingGuestCount"].ToString()} guests booked for our {dialogState["bookingLocation"].ToString()} location for {dialogState["bookingDateTime"].ToString()}."); } } ); }
public async Task ChoicePrompt() { var dialogs = new DialogSet(); dialogs.Add("test-prompt", new Dialogs.ChoicePrompt(Culture.English) { Style = ListStyle.Inline }); var promptOptions = new ChoicePromptOptions { Choices = new List <Choice> { new Choice { Value = "red" }, new Choice { Value = "green" }, new Choice { Value = "blue" }, }, RetryPromptString = "I didn't catch that. Select a color from the list." }; dialogs.Add("test", new WaterfallStep[] { async(dc, args, next) => { await dc.Prompt("test-prompt", "favorite color?", promptOptions); }, async(dc, args, next) => { var choiceResult = (ChoiceResult)args; await dc.Context.SendActivityAsync($"Bot received the choice '{choiceResult.Value.Value}'."); await dc.End(); } } ); var activities = TranscriptUtilities.GetFromTestContext(TestContext); TestAdapter adapter = new TestAdapter() .Use(new ConversationState <Dictionary <string, object> >(new MemoryStorage())); await new TestFlow(adapter, async(turnContext) => { var state = ConversationState <Dictionary <string, object> > .Get(turnContext); var dc = dialogs.CreateContext(turnContext, state); await dc.Continue(); if (!turnContext.Responded) { await dc.Begin("test"); } }) .Test(activities) .StartTestAsync(); }
public async Task BasicChoicePrompt() { var dialogs = new DialogSet(); dialogs.Add("test-prompt", new ChoicePrompt(Culture.English) { Style = ListStyle.Inline }); var promptOptions = new ChoicePromptOptions { Choices = new List <Choice> { new Choice { Value = "red" }, new Choice { Value = "green" }, new Choice { Value = "blue" }, } }; dialogs.Add("test", new WaterfallStep[] { async(dc, args, next) => { await dc.PromptAsync("test-prompt", "favorite color?", promptOptions); }, async(dc, args, next) => { var choiceResult = (ChoiceResult)args; await dc.Context.SendActivityAsync($"Bot received the choice '{choiceResult.Value.Value}'."); await dc.EndAsync(); } } ); ConversationState convoState = new ConversationState(new MemoryStorage()); var testProperty = convoState.CreateProperty <Dictionary <string, object> >("test", () => new Dictionary <string, object>()); TestAdapter adapter = new TestAdapter() .Use(convoState); await new TestFlow(adapter, async(turnContext) => { var state = await testProperty.GetAsync(turnContext); var dc = dialogs.CreateContext(turnContext, state); await dc.ContinueAsync(); if (!turnContext.Responded) { await dc.BeginAsync("test"); } }) .Send("hello") .AssertReply("favorite color? (1) red, (2) green, or (3) blue") .Send("green") .AssertReply("Bot received the choice 'green'.") .StartTestAsync(); }
public BookTableControl() : base("order") { var promptOptions = new ChoicePromptOptions { Choices = new List <Choice> { new Choice { Value = "Seattle" }, new Choice { Value = "Bellevue" }, new Choice { Value = "Renton" }, } }; Dialogs.Add("order", new WaterfallStep[] { async(dc, args, next) => { // The dictionary passed into Begin is available here as the args // if you want anything saved from that then add it to the State dc.ActiveDialog.State = new Dictionary <string, object>(); await dc.Prompt("timexPrompt", "When would you like to arrive? (We open at 4PM.)", new PromptOptions { RetryPromptString = "Please pick a date in the future and a time in the evening." }); }, async(dc, args, next) => { var timexResult = (TimexResult)args; dc.ActiveDialog.State["bookingDateTime"] = timexResult.Resolutions.First(); await dc.Prompt("choicePrompt", "Which of our locations would you like?", promptOptions); }, async(dc, args, next) => { var choiceResult = (FoundChoice)args["Value"]; dc.ActiveDialog.State["bookingLocation"] = choiceResult.Value; await dc.Prompt("numberPrompt", "How many in your party?"); }, async(dc, args, next) => { dc.ActiveDialog.State["bookingGuestCount"] = args["Value"]; await dc.End(dc.ActiveDialog.State); } } ); // TimexPrompt is a very close copy of the existing DateTimePrompt - but manages to correctly handle multiple resolutions Dialogs.Add("timexPrompt", new TimexPrompt(Culture.English, TimexValidator)); Dialogs.Add("choicePrompt", new Microsoft.Bot.Builder.Dialogs.ChoicePrompt(Culture.English) { Style = ListStyle.Inline }); Dialogs.Add("numberPrompt", new Microsoft.Bot.Builder.Dialogs.NumberPrompt <int>(Culture.English)); }
public CoffeeBot() { dialogs = new DialogSet(); coffeeOptions = GenerateOptions(); coffeeSizeOptions = GenerateSizeOptions(); dialogs.Add("orderCoffee", new WaterfallStep[] { async(dc, args, next) => { // Prompt for the guest's name. await dc.Context.SendActivity("Welcome to Gurpal's Cafe!!"); await dc.Prompt("textPrompt", "What is your name?"); }, async(dc, args, next) => { customerName = args["Text"].ToString(); await dc.Context.SendActivity($"Hi {args["Text"]}!"); await dc.Prompt("choicePrompt", "What would you like to have today?", coffeeOptions); }, async(dc, args, next) => { //string selection=(args as Microsoft.Bot.Builder.Prompts.ChoiceResult).Value.Value.ToString(); //selectedOptions.Add(selection); selectedOption = (args as Microsoft.Bot.Builder.Prompts.ChoiceResult).Value.Value.ToString(); await dc.Prompt("sizeChoicePrompt", "What size??", coffeeSizeOptions); }, async(dc, args, next) => { size = (args as Microsoft.Bot.Builder.Prompts.ChoiceResult).Value.Value.ToString(); // await dc.Prompt("confirmPrompt","Anything else?Y/N"); //}, //async(dc, args, next)=> //{ // bool ans=(args as Microsoft.Bot.Builder.Prompts.ConfirmResult).Confirmation; // if (ans) // { // await dc.Begin("orderCoffee"); // } // else // { // await dc.Continue(); // } string msg = " Great!! " + customerName + ". You can pay and get your " + size + " " + selectedOption + " at the next window.\n Have a great day."; await dc.Context.SendActivity(msg); await dc.End(); } }); dialogs.Add("textPrompt", new TextPrompt()); var coffeePrompt = new ChoicePrompt(Culture.English) { Style = Microsoft.Bot.Builder.Prompts.ListStyle.List }; dialogs.Add("choicePrompt", coffeePrompt); var coffeeSizePrompt = new ChoicePrompt(Culture.English) { Style = Microsoft.Bot.Builder.Prompts.ListStyle.List }; dialogs.Add("sizeChoicePrompt", coffeeSizePrompt); dialogs.Add("confirmPrompt", new ConfirmPrompt(Culture.English)); }
public ChoicesExamplesDialog() : base(Id) { Dialogs.Add(Id, new WaterfallStep[] { AutoPrompt, SuggestedActionPrompt, InlinePrompt, ListPrompt, NonePrompt, DonePrompt }); var auto = new ChoicePrompt(Culture.English) { Style = ListStyle.Auto }; Dialogs.Add("auto", auto); var suggestedAction = new ChoicePrompt(Culture.English) { Style = ListStyle.SuggestedAction }; Dialogs.Add("suggestedAction", suggestedAction); var inline = new ChoicePrompt(Culture.English) { Style = ListStyle.Inline }; Dialogs.Add("inline", inline); var list = new ChoicePrompt(Culture.English) { Style = ListStyle.List, }; Dialogs.Add("list", list); var none = new ChoicePrompt(Culture.English) { Style = ListStyle.None }; Dialogs.Add("none", none); var choices = new List <Choice>(); choices.Add(new Choice { Value = "Plain Pizza", Synonyms = new List <string> { "plain" } }); choices.Add(new Choice { Value = "Pizza with Pepperoni", Synonyms = new List <string> { "4 Day", "workshop", "full" } }); choices.Add(new Choice { Value = "Pizza with Mushrooms", Synonyms = new List <string> { "mushroom", "mushrooms", "shrooms" } }); choices.Add(new Choice { Value = "Pizza with Peppers, Mushrooms and Brocolli", Synonyms = new List <string> { "vegtable", "veggie" } }); choices.Add(new Choice { Value = "Pizza with Anchovies" }); _choicePromptOptions = new ChoicePromptOptions { Choices = choices, RetryPromptString = "Sorry, that isn't on the list. Please pick again." }; }