//Create Custom Map Url for search public string CreateCustomMapUrl(FindLocationResponse locationInfo) { Address address = locationInfo.resourceSets[0].resources[0].address; string searchQuery = $"{address.landmark},{address.adminDistrict},{address.countryRegion}"; return($"{CustomMapUrl}where1={HttpUtility.UrlEncode(searchQuery)}"); }
/// <summary> /// POST: api/Messages /// Receive a message from a user and reply to it /// </summary> public async Task <HttpResponseMessage> Post([FromBody] Activity activity) { if (activity.Type == ActivityTypes.Message) { var connector = new ConnectorClient(new Uri(activity.ServiceUrl)); string message = null; bool replied = false; try { var result = await this.GetSimilarImagesAsync(activity, connector); var images = result.similarImages; if (images != null && images.Any()) { //Make attachment and reply it to user Activity reply = activity.CreateReply("Here are some web pages or blog posts to know this location more."); reply.Type = ActivityTypes.Message; reply.AttachmentLayout = "carousel"; reply.Attachments = this.BuildImageAttachments(images.Take(MaxCardCount)); await connector.Conversations.ReplyToActivityAsync(reply); //Find location from similiar search result FindLocationResponse locationData = await bingMapSevice.FindLocation(result.suggestedText); Activity replyPlace = activity.CreateReply($"You may want to go [{locationData.resourceSets[0].resources[0].name}]({bingMapSevice.CreateCustomMapUrl(locationData)})"); replyPlace.Type = ActivityTypes.Message; await connector.Conversations.ReplyToActivityAsync(replyPlace); replied = true; } else { message = "Couldn't find information. Let's try other photos"; } } catch (ArgumentException e) { message = "Did you upload an image? I'm more of a visual person. " + "Try sending me an image or an image URL"; Trace.TraceError(e.ToString()); } catch (Exception e) { message = "Oops! Something went wrong. Try again later."; Trace.TraceError(e.ToString()); } if (!replied) { Activity reply = activity.CreateReply(message); await connector.Conversations.ReplyToActivityAsync(reply); } } else { await this.HandleSystemMessage(activity); } var response = this.Request.CreateResponse(HttpStatusCode.OK); return(response); }