Exemple #1
0
        private static IMessageActivity HandleSearch(ITurnContext turnContext, IMessageActivity activity)
        {
            // Look at the user input, and figure out what kind of attachment to send.
            IMessageActivity     reply = null;
            List <ThumbnailCard> cards = null;

            if (activity.Text.StartsWith("1"))
            {
                WebPageList results = WebPagesHelper.BingWebPageSearch(Common.searchText);
                reply = (turnContext.Activity as Activity)
                        .CreateReply($"## Reading news about {Common.searchText}");

                cards = WebPagesHelper.GetHeroCardsForWebPages(results);
            }
            else if (activity.Text.StartsWith("2"))
            {
                Images pictures = ImageHelper.BingImagesSearch(Common.searchText);
                reply = (turnContext.Activity as Activity)
                        .CreateReply($"## Showing images about {Common.searchText}");

                cards = ImageHelper.GetHeroCardsForImages(pictures);
            }
            else if (activity.Text.StartsWith("3"))
            {
                Videos recordings = VideoHelper.BingVideosSearch(Common.searchText);
                reply = (turnContext.Activity as Activity)
                        .CreateReply($"## Showing videos about {Common.searchText}");

                cards = VideoHelper.GetHeroCardsForVideos(recordings);
            }
            else if (activity.Text.StartsWith("4"))
            {
                News articles = NewsHelper.BingNewsSearch(Common.searchText);
                reply = (turnContext.Activity as Activity)
                        .CreateReply($"## Reading news about {Common.searchText}");

                cards = NewsHelper.GetHeroCardsForArticles(articles);
            }
            if (cards != null)
            {
                cards.ForEach(card =>
                              reply.Attachments.Add(card.ToAttachment()));

                reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
            }
            return(reply);
        }