Ejemplo n.º 1
0
        public async Task displayMore(IDialogContext context, IAwaitable <object> result, LuisResult res, Goodreads.IGoodreadsClient client)
        {
            if (more_genre == 1 || more_author == 1)
            {
                var activity = await result as Activity;
                Goodreads.Models.Response.Book book;
                int i = 0;
                List <Attachment> l = new List <Attachment>();
                while (i < 10 && sugg.List.Count() > i)
                {
                    book = await client.Books.GetByBookId(sugg.List.ElementAt(i).BestBook.Id);

                    if (book != null && book.AverageRating > ratings)
                    {
                        l.Add(new ThumbnailCard
                        {
                            Title    = book.Title,
                            Subtitle = $"Rating:{book.AverageRating}",
                            Text     = $"Summary:{book.Description}",
                            Images   = new List <CardImage> {
                                new CardImage(book.ImageUrl)
                            },
                            Buttons = new List <CardAction> {
                                new CardAction(ActionTypes.OpenUrl, "more..", value: "https://www.goodreads.com/search?q=" + book.Title)
                            }
                        }.ToAttachment());
                    }
                    i    = i + 1;
                    book = null;
                }
                var message = context.MakeMessage();
                message.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                message.Attachments      = l;
                var reply = activity.CreateReply("Want more..?!");
                reply.Type       = ActivityTypes.Message;
                reply.TextFormat = TextFormatTypes.Plain;
                if (more_genre == 1)
                {
                    reply.SuggestedActions = new SuggestedActions()
                    {
                        Actions = new List <CardAction>()
                        {
                            new CardAction()
                            {
                                Title = "show more genre books", Type = ActionTypes.ImBack, Value = "more genre books"
                            },
                        }
                    };
                }
                else if (more_author == 1)
                {
                    reply.SuggestedActions = new SuggestedActions()
                    {
                        Actions = new List <CardAction>()
                        {
                            new CardAction()
                            {
                                Title = "show more author books", Type = ActionTypes.ImBack, Value = "more author books"
                            },
                        }
                    };
                }
                await context.PostAsync(message);

                await context.PostAsync(reply);

                sugg = null;
            }
        }
Ejemplo n.º 2
0
        public async Task displayAsync(IDialogContext context, IAwaitable <object> result, LuisResult res, Goodreads.IGoodreadsClient client)
        {
            var activity = await result as Activity;

            // await context.PostAsync($"display gen ={gen_working} auth={author_working}");
            if (activity.Text == "All" && find == 1)
            {
                int i = 0;
                ratings = 0;
                Goodreads.Models.Response.Book book;
                find = 0;
                List <Attachment> l = new List <Attachment>();
                while (i < 10 && sugg.List.Count() > i)
                {
                    book = await client.Books.GetByBookId(sugg.List.ElementAt(i).BestBook.Id);

                    if (book != null)
                    {
                        l.Add(new ThumbnailCard
                        {
                            Title    = book.Title,
                            Subtitle = $"Rating:{book.AverageRating}",
                            Text     = $"Summary:{book.Description}",
                            Images   = new List <CardImage> {
                                new CardImage(book.ImageUrl)
                            },
                            Buttons = new List <CardAction> {
                                new CardAction(ActionTypes.OpenUrl, "more..", value: "https://www.goodreads.com/search?q=" + book.Title)
                            }
                        }.ToAttachment());
                    }
                    i    = i + 1;
                    book = null;
                }
                var message = context.MakeMessage();
                message.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                message.Attachments      = l;
                var reply = activity.CreateReply("Want more...?!");
                reply.Type       = ActivityTypes.Message;
                reply.TextFormat = TextFormatTypes.Plain;
                if (gen_working == 1)
                {
                    reply.SuggestedActions = new SuggestedActions()
                    {
                        Actions = new List <CardAction>()
                        {
                            new CardAction()
                            {
                                Title = "show more genre books", Type = ActionTypes.ImBack, Value = "more genre books"
                            },
                        }
                    };
                }
                else if (author_working == 1)
                {
                    reply.SuggestedActions = new SuggestedActions()
                    {
                        Actions = new List <CardAction>()
                        {
                            new CardAction()
                            {
                                Title = "show more author books", Type = ActionTypes.ImBack, Value = "more author books"
                            },
                        }
                    };
                }
                await context.PostAsync(message);

                await context.PostAsync(reply);

                sugg = null;
            }
            else if (activity.Text == "Ratings" && find == 1)
            {
                int i = 0;
                find = 2;
                var reply = activity.CreateReply("choose from the following ratings");
                reply.Type             = ActivityTypes.Message;
                reply.TextFormat       = TextFormatTypes.Plain;
                reply.SuggestedActions = new SuggestedActions()
                {
                    Actions = new List <CardAction>()
                    {
                        new CardAction()
                        {
                            Title = ">1", Type = ActionTypes.ImBack, Value = "1"
                        },
                        new CardAction()
                        {
                            Title = ">2", Type = ActionTypes.ImBack, Value = "2"
                        },
                        new CardAction()
                        {
                            Title = ">3", Type = ActionTypes.ImBack, Value = "3"
                        },
                        new CardAction()
                        {
                            Title = ">4", Type = ActionTypes.ImBack, Value = "4"
                        },
                    }
                };
                await context.PostAsync(reply);
            }
            else
            {
                string mes = $"Found few interesting books from good reads ....Do you want to search by following?";
                find = 1;
                var reply = activity.CreateReply(mes);
                reply.Type             = ActivityTypes.Message;
                reply.TextFormat       = TextFormatTypes.Plain;
                reply.SuggestedActions = new SuggestedActions()
                {
                    Actions = new List <CardAction>()
                    {
                        new CardAction()
                        {
                            Title = "Ratings", Type = ActionTypes.ImBack, Value = "Ratings"
                        },
                        new CardAction()
                        {
                            Title = "All", Type = ActionTypes.ImBack, Value = "All"
                        },
                    }
                };
                await context.PostAsync(reply);
            }
        }