Пример #1
0
        public async Task <IMessageActivity> SearchImages(IMessageActivity replyMsg, string query)
        {
            try
            {
                var client      = BingSearch.GetHttpClientConnection();
                var imagelist   = new List <Attachment>();
                var queryString = ServiceUrls.BingImageSearchUrl + "q=" + query + "&count=10" + "&mkt=en-us";
                replyMsg.Attachments = new List <Attachment>();
                string r = await client.GetStringAsync(queryString);

                var jsonResult = JsonConvert.DeserializeObject <BingImageSearchResponse.RootObject>(r);
                foreach (var rjson in jsonResult.value.ToList())
                {
                    replyMsg.Attachments.Add(

                        new Attachment
                    {
                        Name         = rjson.name,
                        ThumbnailUrl = rjson.thumbnailUrl,
                        ContentType  = "image / png",
                        ContentUrl   = rjson.contentUrl
                    }


                        );
                }
                return(replyMsg);
            }
            catch (Exception t)
            {
                throw t;
            }
        }
Пример #2
0
        public async Task <IMessageActivity> Search(IMessageActivity replyMsg, string query)
        {
            try
            {
                // Request parameters
                var client = BingSearch.GetHttpClientConnection();
                replyMsg.Attachments = new List <Attachment>();
                var    queryString = ServiceUrls.BingSearchUrl + "?q=" + query + "&count=10" + "&mkt=en-us";
                int    i           = 0;
                string r           = await client.GetStringAsync(queryString);

                var jsonResult = JsonConvert.DeserializeObject <RootObject>(r);
                var result     = new StringBuilder();
                /// web result

                foreach (var jresult in jsonResult.webPages.value.ToList())
                {
                    replyMsg.Attachments.Add(new Attachment
                    {
                        Name       = jresult.name,
                        Content    = jresult.snippet,
                        ContentUrl = jresult.url
                    }
                                             );
                }
                return(replyMsg);
            }
            catch (Exception t)
            {
                throw t;
            }
        }