public static Activity GetRecipeFor(Activity message, string dish, string defaultResponse) { BotService.SendATextResponse(message, defaultResponse); RecipePuppyDataModel webResponse = WebApiConnectorService.GenericGetRequest <RecipePuppyDataModel>(BotConstants.BotApiSettings.RecipePuppyWebApiUrlWithQuery + "" + dish); IEnumerable <int> randomNumbers = MiscService.GiveXFromYNumbers(BotConstants.OtherConstants.MaxOptionsGives, webResponse.results.Count()); return(GenerateRecipeMessage(message, webResponse, randomNumbers, defaultResponse)); }
public static Activity GetTopNRecipes(Activity message, int n, string defaultResponse) { if (!string.IsNullOrEmpty(defaultResponse)) { BotService.SendATextResponse(message, defaultResponse); } RecipePuppyDataModel webResponse = WebApiConnectorService.GenericGetRequest <RecipePuppyDataModel>(BotConstants.BotApiSettings.RecipePuppyWebApiUrl); IEnumerable <int> randomNumbers = MiscService.GiveXFromYNumbers(n, webResponse.results.Count()); return(GenerateRecipeMessage(message, webResponse, randomNumbers, defaultResponse)); }
public static Activity GetRecipeWith(Activity message, string[] ingredients, string defaultResponse) { if (!string.IsNullOrEmpty(defaultResponse)) { BotService.SendATextResponse(message, defaultResponse); } string listOfIngredients = string.Join(",", ingredients.Select(item => item).ToArray()); RecipePuppyDataModel webResponse = WebApiConnectorService.GenericGetRequest <RecipePuppyDataModel>(BotConstants.BotApiSettings.RecipePuppyWebApiUrlWithIngredients + "" + listOfIngredients); IEnumerable <int> randomNumbers = MiscService.GiveXFromYNumbers(BotConstants.OtherConstants.MaxOptionsGives, webResponse.results.Count()); return(GenerateRecipeMessage(message, webResponse, randomNumbers, defaultResponse)); }
private static Activity GenerateRecipeMessage(Activity message, RecipePuppyDataModel recipes, IEnumerable <int> randomNumbers, string defaultResponse) { try { Activity replyToConversation = message.CreateReply(); replyToConversation.AttachmentLayout = AttachmentLayoutTypes.Carousel; replyToConversation.Attachments = new List <Attachment>(); Dictionary <string, string> cardContentList = new Dictionary <string, string>(); foreach (var value in randomNumbers) { var recipe = recipes.results.ElementAt(value); string recipeImage = FlickrService.GetImage(recipe.title); // Add basic card content details cardContentList.Add( recipe.title, recipe.href ); // Add the card image and button element to a thumbnail of the response replyToConversation.Attachments.Add( new HeroCard() { Title = recipe.title, Subtitle = MiscService.GetRandomTagline(), Text = MiscService.GetRandomIngredientsPrefix() + recipe.ingredients, Images = new List <CardImage> { new CardImage(recipeImage) }, //recipe.thumbnail Buttons = new List <CardAction> { new CardAction(ActionTypes.OpenUrl, BotConstants.PreDefinedActions.VisitRecipeActionButton, value: recipe.href) } }.ToAttachment() ); } return(replyToConversation); } catch (NullReferenceException nex) { System.Diagnostics.Trace.TraceError("GenerateRecipeMessage " + nex.Message); return(message.CreateReply("Apologies, we couldn't find any recipes at this moment.")); } catch (Exception e) { System.Diagnostics.Trace.TraceError("GenerateRecipeMessage " + e.Message); return(message.CreateReply("Apologies, we couldn't find any GIF at this moment.")); } }