private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <object> result) { var activity = await result as Activity; List <FoodModel> foodList = FoodModel.GetFoodList(); //Get state StateClient stateClient = activity.GetStateClient(); BotData userData = await stateClient.BotState.GetUserDataAsync(activity.ChannelId, activity.From.Id); var sentGreeting = userData.GetProperty <bool>("SentGreeting"); if (activity.Text.Contains(MoreOption)) { //More of the same food //await DisplayFoodCard(context, result); if (currentFood == null) { //No current food - generate random currentFood = getRandomFood(foodList); } else { currentFood.IncrementIndex(); } } else if (activity.Text == NextOption) { //Next food type currentFood = getRandomFood(foodList); } else if (activity.Text.Contains(FindOption)) { //Find restaurant closest return; } else { if (!sentGreeting) { WelcomePrompt(context); //Save state var data = context.UserData; data.SetValue("SentGreeting", true); } else { //Unknown - unrecognized message UnrecognisedPrompt(context); } return; } ShowFoodCard(currentFood, context); }
private async void ShowFoodCard(FoodCardModel currentFood, IDialogContext context) { var message = context.MakeMessage(); var attachment = BuildHeroCard(currentFood); message.Attachments.Add(attachment); await context.PostAsync(message); }
private async Task DisplayRandomCard(IDialogContext context, IAwaitable <Object> result) { var userText = await result; var message = context.MakeMessage(); List <FoodModel> foodList = FoodModel.GetFoodList(); currentFood = getRandomFood(foodList); var attachment = BuildHeroCard(currentFood); message.Attachments.Add(attachment); await context.PostAsync(message); context.Wait(MessageReceivedAsync); }
private static Attachment BuildHeroCard(FoodCardModel currentFood) { var foodName = currentFood.name; var foodURL = currentFood.getCurrentURL(); var heroCard = new HeroCard { Title = String.Format("How about {0}?", foodName), Images = new List <CardImage> { new CardImage(foodURL) }, Buttons = new List <CardAction> { new CardAction(ActionTypes.ImBack, MoreOption, value: "Show me more " + foodName), new CardAction(ActionTypes.ImBack, NextOption, value: NextOption), new CardAction(ActionTypes.OpenUrl, FindOption, value: String.Format(yelpUrl, foodName)) } }; return(heroCard.ToAttachment()); }
private FoodCardModel getRandomFood(List <FoodModel> list) { //Randomize order Random rnd = new Random(); int index = rnd.Next(0, list.Count); FoodModel selectedFood = list[index]; var name = selectedFood.Name; List <string> urlList = new List <string>(); urlList.Add(selectedFood.URL1); urlList.Add(selectedFood.URL2); urlList.Add(selectedFood.URL3); urlList.Add(selectedFood.URL4); urlList.Add(selectedFood.URL5); urlList.Add(selectedFood.URL6); FoodCardModel foodCard = new FoodCardModel(name, urlList); return(foodCard); }
private async Task UserChoice(IDialogContext context, IAwaitable <object> result) { var activity = await result; //await context.PostAsync($@"Hi {activity}!"); List <FoodModel> foodList = FoodModel.GetFoodList(); var userText = activity.ToString(); if (userText.Contains(MoreOption.Substring(0, 4))) { //More of the same food if (currentFood == null) { //No current food - generate random currentFood = getRandomFood(foodList); } else { currentFood.IncrementIndex(); } } else if (userText.Contains(NextOption)) { //Next food type currentFood = getRandomFood(foodList); } else if (userText.Contains(FindOption)) { //Find restaurant if (currentFood != null) { Uri uri = new Uri(String.Format(yelpUrl, currentFood.name)); await context.PostAsync("Our friends at Yelp will help you find " + currentFood.name.ToLower() + " here: " + uri.AbsoluteUri); return; } else { //User types find food without previous prompt PromptDialog.Choice <string>( context, UserChoice, new string[] { StartOption }, "Not sure what you mean... but I'm guessing you're hungry?", ErrorMsg, 3, PromptStyle.Auto); } } else { //New session- Show random food currentFood = getRandomFood(foodList); } //Image attachment message var message = context.MakeMessage(); var attachment = GetImageAttachment(currentFood.getCurrentURL()); message.Attachments.Add(attachment); await context.PostAsync(message); //Next available choice dialog PromptDialog.Choice <string>( context, UserChoice, new string[] { String.Format(MoreOption, currentFood.name), NextOption, FindOption }, "How about " + currentFood.name + "?", ChoiceErrorMsg, 3, PromptStyle.Auto); }