public async Task StartAsync(IDialogContext context) { //Use FormFlow to get details of the Person object. This sample is not about FormFlow but it is the simplest way to create a complex type with data from the user var personDialog = FormDialog.FromType <Person>(FormOptions.PromptInStart); context.Call(personDialog, ResumeAfterPersonFormDialog); }
public async Task StartAsync(IDialogContext context) { await context.PostAsync("Salut je suis M. Bot à votre service"); await context.PostAsync("Avant tout, il vous faut un nom de Super Héros!"); var infoDialog = FormDialog.FromType <InfoHeros>(FormOptions.PromptInStart); context.Call(infoDialog, ResumeAfterInfoHerosDialog); }
static void Main(string[] args) { // TestValidate(); var callDebug = Chain .From(() => new PromptDialog.PromptString("Locale?", null, 1)) .ContinueWith <string, Choices>(async(ctx, locale) => { Locale = await locale; CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo(Locale); CultureInfo.CurrentCulture = CultureInfo.CurrentUICulture; return(FormDialog.FromType <Choices>(FormOptions.PromptInStart)); }) .ContinueWith <Choices, object>(async(context, result) => { Choices choices; try { choices = await result; } catch (Exception error) { await context.PostAsync(error.ToString()); throw; } switch (choices.Choice) { case DebugOptions.AnnotationsAndNumbers: return(MakeForm(() => PizzaOrder.BuildForm(noNumbers: false))); case DebugOptions.AnnotationsAndNoNumbers: return(MakeForm(() => PizzaOrder.BuildForm(noNumbers: true))); case DebugOptions.AnnotationsAndText: return(MakeForm(() => PizzaOrder.BuildForm(style: ChoiceStyleOptions.AutoText))); case DebugOptions.NoAnnotations: return(MakeForm(() => PizzaOrder.BuildForm(noNumbers: true, ignoreAnnotations: true))); case DebugOptions.NoFieldOrder: return(MakeForm(() => new FormBuilder <PizzaOrder>().Build())); case DebugOptions.WithState: return(new FormDialog <PizzaOrder>(new PizzaOrder() { Size = SizeOptions.Large, Kind = PizzaOptions.BYOPizza }, () => PizzaOrder.BuildForm(noNumbers: false), options: FormOptions.PromptInStart, entities: new Luis.Models.EntityRecommendation[] { new Luis.Models.EntityRecommendation("Address", "abc", "DeliveryAddress"), new Luis.Models.EntityRecommendation("Toppings", "onions", "BYO.Toppings"), new Luis.Models.EntityRecommendation("Toppings", "peppers", "BYO.Toppings"), new Luis.Models.EntityRecommendation("Toppings", "ice", "BYO.Toppings"), new Luis.Models.EntityRecommendation("NotFound", "OK", "Notfound") } )); case DebugOptions.Localized: { var form = PizzaOrder.BuildForm(false, false); using (var stream = new FileStream("pizza.resx", FileMode.Create)) using (var writer = new ResXResourceWriter(stream)) { form.SaveResources(writer); } Process.Start(new ProcessStartInfo(@"RView.exe", "pizza.resx -c " + Locale) { UseShellExecute = false, CreateNoWindow = true }).WaitForExit(); return(MakeForm(() => PizzaOrder.BuildForm(false, false, true))); } case DebugOptions.SimpleSandwichBot: return(MakeForm(() => SimpleSandwichOrder.BuildForm())); case DebugOptions.AnnotatedSandwichBot: return(MakeForm(() => AnnotatedSandwichOrder.BuildLocalizedForm())); case DebugOptions.JSONSandwichBot: return(MakeForm(() => AnnotatedSandwichOrder.BuildJsonForm())); default: throw new NotImplementedException(); } }) .Do(async(context, result) => { try { var item = await result; Debug.WriteLine(item); } catch (FormCanceledException e) { if (e.InnerException == null) { await context.PostAsync($"Quit on {e.Last} step."); } else { await context.PostAsync($"Exception {e.Message} on step {e.Last}."); } } }) .DefaultIfException() .Loop(); Interactive(callDebug).GetAwaiter().GetResult(); }
static void Main(string[] args) { // TestValidate(); var callDebug = Chain .From(() => FormDialog.FromType <Choices>(FormOptions.PromptInStart)) .ContinueWith <Choices, object>(async(context, result) => { Choices choices; try { choices = await result; } catch (Exception error) { await context.PostAsync(error.ToString()); throw; } switch (choices.Choice) { case DebugOptions.AnnotationsAndNumbers: return(MakeForm(() => BuildForm(noNumbers: false))); case DebugOptions.AnnotationsAndNoNumbers: return(MakeForm(() => BuildForm(noNumbers: true))); case DebugOptions.NoAnnotations: return(MakeForm(() => BuildForm(noNumbers: true, ignoreAnnotations: true))); case DebugOptions.NoFieldOrder: return(MakeForm(() => new FormBuilder <PizzaOrder>().Build())); case DebugOptions.WithState: return(new FormDialog <PizzaOrder>(new PizzaOrder() { Size = SizeOptions.Large, DeliveryAddress = "123 State", Kind = PizzaOptions.BYOPizza }, () => BuildForm(noNumbers: false), options: FormOptions.PromptInStart)); #if LOCALIZE case DebugOptions.Localized: return(MakeForm(() => BuildForm(false, false, true))); #endif case DebugOptions.SimpleSandwichBot: return(MakeForm(() => SimpleSandwichOrder.BuildForm())); case DebugOptions.AnnotatedSandwichBot: return(MakeForm(() => AnnotatedSandwichOrder.BuildForm())); default: throw new NotImplementedException(); } }) .Do(async(context, result) => { try { var item = await result; Debug.WriteLine(item); } catch (FormCanceledException e) { if (e.InnerException == null) { await context.PostAsync($"Quit on {e.Last} step."); } else { await context.PostAsync($"Exception {e.Message} on step {e.Last}."); } } }) .Loop(); Interactive(callDebug).GetAwaiter().GetResult(); }
static void Main(string[] args) { // TestValidate(); var callDebug = Chain .From(() => FormDialog.FromType <Choices>()) .ContinueWith <Choices, object>(async(context, result) => { Choices choices; try { choices = await result; } catch (Exception error) { await context.PostAsync(error.ToString()); throw; } switch (choices.Choice) { case DebugOptions.AnnotationsAndNumbers: return(MakeForm(() => BuildForm(noNumbers: false))); case DebugOptions.AnnotationsAndNoNumbers: return(MakeForm(() => BuildForm(noNumbers: true))); case DebugOptions.NoAnnotations: return(MakeForm(() => BuildForm(noNumbers: true, ignoreAnnotations: true))); case DebugOptions.NoFieldOrder: return(MakeForm(() => new FormBuilder <PizzaOrder>().Build())); case DebugOptions.SimpleSandwichBot: return(MakeForm(() => SimpleSandwichOrder.BuildForm())); case DebugOptions.AnnotatedSandwichBot: return(MakeForm(() => AnnotatedSandwichOrder.BuildForm())); default: throw new NotImplementedException(); } }) .Do(async result => { try { var item = await result; Debug.WriteLine(item); } catch (OperationCanceledException) { Debug.WriteLine("you cancelled"); } }) .Loop(); Interactive(callDebug); /* * var dialogs = new DialogCollection().Add(debugForm); * var form = AddFields(new Form<PizzaOrder>("full"), noNumbers: true); * Console.WriteLine("\nWith annotations and numbers\n"); * Interactive<Form<PizzaOrder>>(AddFields(new Form<PizzaOrder>("No numbers"), noNumbers: false)); * * Console.WriteLine("With annotations and no numbers"); * Interactive<Form<PizzaOrder>>(form); * * Console.WriteLine("\nWith no annotations\n"); * Interactive<Form<PizzaOrder>>(AddFields(new Form<PizzaOrder>("No annotations", ignoreAnnotations: true), noNumbers: false)); * * Console.WriteLine("\nWith no fields.\n"); * Interactive<Form<PizzaOrder>>(new Form<PizzaOrder>("No fields")); */ }
static void Main(string[] args) { var callJoke = Chain .From(() => new FormDialog <TopChoice>(new TopChoice(), options: FormOptions.PromptInStart)) .ContinueWith <TopChoice, object>(async(context, result) => { switch ((await result).Choice) { case TopChoices.Joke: return(new FormDialog <ChooseJoke>(new ChooseJoke(), options: FormOptions.PromptInStart)); default: await context.PostAsync("I don't understand"); return(new NullDialog <object>()); } }) .ContinueWith <object, object>(async(context, result) => { var choice = await result; if (choice is ChooseJoke) { switch ((choice as ChooseJoke).KindOfJoke) { case TypeOfJoke.Funny: await context.PostAsync("Something funny"); break; case TypeOfJoke.KnockKnock: await context.PostAsync("Knock-knock..."); break; } } return(new NullDialog <object>()); }); // TestValidate(); var callDebug = Chain .From(() => FormDialog.FromType <Choices>(FormOptions.PromptInStart)) .ContinueWith <Choices, object>(async(context, result) => { Choices choices; try { choices = await result; } catch (Exception error) { await context.PostAsync(error.ToString()); throw; } switch (choices.Choice) { case DebugOptions.AnnotationsAndNumbers: return(MakeForm(() => BuildForm(noNumbers: false))); case DebugOptions.AnnotationsAndNoNumbers: return(MakeForm(() => BuildForm(noNumbers: true))); case DebugOptions.NoAnnotations: return(MakeForm(() => BuildForm(noNumbers: true, ignoreAnnotations: true))); case DebugOptions.NoFieldOrder: return(MakeForm(() => new FormBuilder <PizzaOrder>().Build())); case DebugOptions.WithState: return(new FormDialog <PizzaOrder>(new PizzaOrder() { Size = SizeOptions.Large, DeliveryAddress = "123 State", Kind = PizzaOptions.BYOPizza }, () => BuildForm(noNumbers: false), options: FormOptions.PromptInStart)); case DebugOptions.SimpleSandwichBot: return(MakeForm(() => SimpleSandwichOrder.BuildForm())); case DebugOptions.AnnotatedSandwichBot: return(MakeForm(() => AnnotatedSandwichOrder.BuildForm())); default: throw new NotImplementedException(); } }) .Do(async result => { try { var item = await result; Debug.WriteLine(item); } catch (OperationCanceledException) { Debug.WriteLine("you cancelled"); } }) .Loop(); Interactive(callDebug).GetAwaiter().GetResult(); /* * var dialogs = new DialogCollection().Add(debugForm); * var form = AddFields(new Form<PizzaOrder>("full"), noNumbers: true); * Console.WriteLine("\nWith annotations and numbers\n"); * Interactive<Form<PizzaOrder>>(AddFields(new Form<PizzaOrder>("No numbers"), noNumbers: false)); * * Console.WriteLine("With annotations and no numbers"); * Interactive<Form<PizzaOrder>>(form); * * Console.WriteLine("\nWith no annotations\n"); * Interactive<Form<PizzaOrder>>(AddFields(new Form<PizzaOrder>("No annotations", ignoreAnnotations: true), noNumbers: false)); * * Console.WriteLine("\nWith no fields.\n"); * Interactive<Form<PizzaOrder>>(new Form<PizzaOrder>("No fields")); */ }