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 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); }