private static async Task <IDialog <Beer> > ChooseBeer <T>(IBotContext context, IAwaitable <T> awaitableArgument, Func <T, Task <IEnumerable <Beer> > > beerSelector, IDialog <Beer> retryDialog) { T argument = await awaitableArgument; var recommendation = (await beerSelector(argument)).Random(3).ToList(); switch (recommendation.Count) { case 0: await context.SpeakAsync("Oops! I havn't found any beer!"); return(retryDialog ?? Chain.Return <Beer>(null)); case 1: await context.SpeakAsync("Eureka! I've got a beer for you"); return(Chain.Return(recommendation[0])); default: return(new PromptDialog.PromptChoice <Beer>(new PromptOptions <Beer>( "Which one of these works?", "I probably drank too much. Which one of these work?", options: recommendation, speak: "Which one of these works?", retrySpeak: "I probably drank too much. Which one of these work?"))); } }
private static async Task <IDialog <Brewery> > ChooseBrewery(IBotContext context, IAwaitable <string> countryAwaitable) { var country = await countryAwaitable; var breweries = (await BeerApiClient.BreweriesGetByCountryAsync(country)).Random(5).ToList(); Debug.Assert(breweries.Count > 0, "There is no country in the list with zero breweries!"); if (breweries.Count == 1) { await context.SpeakAsync($"Then you need a beer made by {breweries[0].Name}"); return(Chain.Return(breweries[0])); } return(new PromptDialog.PromptChoice <Brewery>(new PromptOptions <Brewery>( "Which brewery?", "I probably drank too much. Which brewery was it?", options: breweries, speak: "Which brewery?", retrySpeak: "I probably drank too much. Which brewery was it?"))); }