Exemple #1
0
        public void CanPageThroughResults()
        {
            var agg = new BingNews();
            var q   = agg.SearchAsync("China", count: 361).Result;

            Assert.NotEmpty(q);
        }
        public async Task News(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result)
        {
            var message = await activity;
            var reply   = context.MakeMessage();
            EntityRecommendation locEntity;

            if (result.TryFindEntity("Location", out locEntity))
            {
                BingNews bingNews = await getBingNews(locEntity.Entity);


                if (bingNews == null || bingNews.totalEstimatedMatches == 0)
                {
                    await context.PostAsync("Sorry, couldn't find any news about '" + locEntity.Entity);
                }
                else
                {
                    reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                    reply.Attachments      = new List <Attachment>();
                    for (int i = 0; i < 10 && i < (bingNews?.totalEstimatedMatches ?? 0); i++)
                    {
                        var      article    = bingNews.value[i];
                        HeroCard attachment = new HeroCard()
                        {
                            Title = article.name.Length > 60 ?
                                    article.name.Substring(0, 57) + "..." : article.name,
                            Text = article.provider[0].name + ", " +
                                   article.datePublished.ToString("d") + " - " +
                                   article.description,
                            Images = new List <CardImage>()
                            {
                                new
                                CardImage(article.image?.thumbnail?.contentUrl + "&w=400&h=400")
                            },
                            Buttons = new List <CardAction>()
                            {
                                new CardAction(
                                    ActionTypes.OpenUrl,
                                    title: "View on Web",
                                    value: article.url)
                            }
                        };
                        reply.Attachments.Add(attachment.ToAttachment());
                    }
                    await context.PostAsync(reply);
                }
            }

            else if (result.Query.Contains("news") || result.Query.Contains("News"))
            {
                await context.PostAsync("Enter in a proper format like news at hyderabad or search for news in hyderabad");
            }
            else
            {
                await context.PostAsync($"I couldn't understand what you're looking for. ");
            }
            context.Wait(this.MessageReceived);
        }
Exemple #3
0
        public void CanConstructClient()
        {
            BingNews b = new BingNews();

            Assert.NotNull(b);
            Assert.True(b.Initialized);
            var q = b.SearchAsync("Donald Trump").Result;

            Assert.NotEmpty(q);
        }
Exemple #4
0
        public IActionResult DelNews(string id)
        {
            BingNews news = _context.BingNews.Find(Guid.Parse(id));

            _context.BingNews.Remove(news);
            var re = _context.SaveChanges();

            if (re > 0)
            {
                return(JsonOk(re));
            }
            return(JsonFailed());
        }
Exemple #5
0
 public BingNewsAzure(string topic, string dbEndpointUrl, string dbAuthKey, string searchApiKey)
 {
     Aggregator = new BingNews(searchApiKey);
     Db         = new CosmosDB(dbEndpointUrl, dbAuthKey, "articles", CancellationToken);
 }
Exemple #6
0
 public BingNewsAzure(string topic)
 {
     Aggregator = new BingNews();
     Db         = new CosmosDB("tradnews");
 }