private async Task faceReceivedAsync(IDialogContext context, IAwaitable <IEnumerable <Attachment> > arguement) { // here, the images will go thru "checkFace" to get the users // if face is not found, computer vision is performed to get the caption of this image // or else if face is found, then it will response the message // note that the message here is hard coded, purely for demo purpose var uploadImage = await arguement; if (uploadImage != null) { string faceURL = uploadImage.Last().ContentUrl; string userName = await SLADemo2.Dialog.FaceData.checkFace(faceURL); if (userName == "notFound") { await context.PostAsync("Sorry, the face doesn't match with the registered face."); context.Wait(MessageReceived); } else if (userName == "noFaceFound") { visionObj visionJSON = await SLADemo2.Dialog.ComputerVision.GetImageJSON(faceURL); string caption = visionJSON.description.captions[0].text; await context.PostAsync("I think I saw " + caption + ". This is an invalid photo."); context.Wait(MessageReceived); } else { await context.PostAsync(userName + " is found."); await context.PostAsync("According to HDB, the address that you provided is not registered under your name. It is a rental unit."); context.Wait(MessageReceived); } } else { await context.PostAsync("No image received."); } }
public static async Task <visionObj> GetImageJSON(string imageURL) {//Http post and retrive JSON from cognitive services var client = new HttpClient(); client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "<computer vision api>"); var uri = "https://api.projectoxford.ai/vision/v1.0/analyze?visualFeatures=Tags,Description&language=en"; HttpResponseMessage response; byte[] byteData = Encoding.UTF8.GetBytes("{\"url\":\"" + imageURL + "\"}"); using (var content = new ByteArrayContent(byteData)) { content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); response = await client.PostAsync(uri, content); var result = await response.Content.ReadAsStringAsync(); visionObj ImageJSON = JsonConvert.DeserializeObject <visionObj>(result); return(ImageJSON); } }