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); }