public static void Main() { // search term to be run against bing string searchTerm; // set console encoding Console.OutputEncoding = System.Text.Encoding.UTF8; // prompt search term System.Console.WriteLine("Please enter a search term to run against bing: "); searchTerm = System.Console.ReadLine(); Console.WriteLine("Searching the Web for: " + searchTerm); // Create instance of Bing Search Class and return results BingWebSearch search = new BingWebSearch(); SearchResult result = search.BingTextSearch(searchTerm); Console.WriteLine("\nRelevant HTTP Headers:\n"); foreach (var header in result.relevantHeaders) { Console.WriteLine(header.Key + ": " + header.Value); } Console.WriteLine("\nJSON Response:\n"); Console.WriteLine(JsonPrettyPrint(result.jsonResult)); Console.Write("\nPress Enter to exit: "); Console.ReadLine(); }
public async Task MessageRecievedAsync(IDialogContext context, IAwaitable <IMessageActivity> argument) { var message = await argument; if (message.Attachments != null && message.Attachments.Any()) { Debug.WriteLine("message has attachment"); //read the images var attachmentUrl = message.Attachments[0].ContentUrl; var httpClient = new HttpClient(); try { var attachmentData = await httpClient.GetByteArrayAsync(attachmentUrl); var resp = await CustomVisionService.GetPredictionsAsync2(attachmentData, "Insurance"); if (resp != null) { Debug.WriteLine($"prediction response {resp}"); //we got the image recognized from cog custom service var webresult = await BingWebSearch.SearchWeb(resp + " insurance bangalore"); //once the result is there build the card var adaptiveCards = BuildCard(webresult); var reply = context.MakeMessage(); reply.Attachments = adaptiveCards; reply.AttachmentLayout = AttachmentLayoutTypes.Carousel; await context.PostAsync(reply); } else { await context.PostAsync("Sorry, I didn't recognize the image"); } } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.InnerException); Debug.WriteLine(ex.Source); Debug.WriteLine(ex.StackTrace); } } //only show the prompt once if (!isUserUploadingPic) { PromptDialog.Confirm(context, AfterConfirm, "Do you have a picture of the car?"); } }
public async Task MessageRecievedAsync(IDialogContext context, IAwaitable <IMessageActivity> argument) { Debug.WriteLine($"Looking up restaurants"); //we got the image recognized from cog custom service var webresult = await BingWebSearch.SearchWeb("find restaurants near me"); //once the result is there build the card var adaptiveCards = BuildCard(webresult); var reply = context.MakeMessage(); reply.Attachments = adaptiveCards; reply.AttachmentLayout = AttachmentLayoutTypes.Carousel; await context.PostAsync(reply); context.Done(true); }
public async Task <IActionResult> Search(SearchModel model) { if (ModelState.IsValid) { if (model.StatusCode == HttpStatusCode.NoContent) { model.StatusCode = HttpStatusCode.NotFound; model.WebActive = string.Empty; model.WebResult.StatusCode = HttpStatusCode.NotFound; model.WebResult.StatusMessage = HttpStatusCode.NotFound.ToString(); model.ImageActive = string.Empty; model.ImageResult.StatusCode = HttpStatusCode.NotFound; model.ImageResult.StatusMessage = HttpStatusCode.NotFound.ToString(); model.VideoActive = string.Empty; model.VideoResult.StatusCode = HttpStatusCode.NotFound; model.VideoResult.StatusMessage = HttpStatusCode.NotFound.ToString(); if (!string.IsNullOrEmpty(model.SearchRequest.Trim())) { BingWebSearch bingWebSearch = new BingWebSearch( _appSettings.Application.BingWebSearch.SubscriptionKey, _appSettings.Application.BingWebSearch.CustomConfigId ); model.WebResult = await bingWebSearch.Search("Web", model.SearchRequest); if (model.WebResult.StatusCode == HttpStatusCode.OK) { model.StatusCode = model.WebResult.StatusCode; model.WebActive = "active"; } model.ImageResult = await bingWebSearch.Search("Image", model.SearchRequest); if (model.ImageResult.StatusCode == HttpStatusCode.OK) { model.StatusCode = model.ImageResult.StatusCode; if (string.IsNullOrEmpty(model.WebActive)) { model.ImageActive = "active"; } } model.VideoResult = await bingWebSearch.Search("Video", model.SearchRequest); if (model.VideoResult.StatusCode == HttpStatusCode.OK) { model.StatusCode = model.VideoResult.StatusCode; if (string.IsNullOrEmpty(model.WebActive) && string.IsNullOrEmpty(model.ImageActive)) { model.VideoActive = "active"; } } } } return(View(model)); } model = new SearchModel(); model.StatusCode = HttpStatusCode.BadRequest; return(View(model)); }