Ejemplo n.º 1
0
        private async Task TheftObjectUploaded(IDialogContext context, IAwaitable <IEnumerable <Attachment> > arg)
        {
            var stolen = await arg;

            StolenObjectImages = stolen.Select(x => x.ContentUrl).ToList();

            var att = StolenObjectImages.FirstOrDefault();

            if (att != null)
            {
                var req      = WebRequest.Create(att);
                var response = req.GetResponse();
                using (var stream = response.GetResponseStream())
                {
                    var client = new ComputerVisionClient(new ApiKeyServiceClientCredentials(PrivateKeys.VisionApiKey));
                    client.Endpoint = "https://northeurope.api.cognitive.microsoft.com";
                    var imageAnalysis = await client.AnalyzeImageInStreamAsync(stream, features);

                    if (ContainsItemOrPseudonym(imageAnalysis.Tags, LUISIssueResult.CurrentResponse.Entities.Where(x => x.Type == Entities.StolenObject).FirstOrDefault()?.Entity))
                    {
                        await IssueCrimeReferenceNumber(context);
                    }
                    else
                    {
                        PromptDialog.Confirm(
                            context,
                            ConfirmPictureOfStolenObjectIsCorrect,
                            $"That looks like {imageAnalysis.Description.Captions[0].Text}. Are you sure this is a picture of the " +
                            $"{LUISIssueResult.CurrentResponse.Entities.Where(x => x.Type == Entities.StolenObject).FirstOrDefault()?.Entity}",
                            "Sorry, I didn't quite understand you, can you try again?",
                            promptStyle: PromptStyle.None);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private async Task ConfirmPictureOfStolenObjectIsCorrect(IDialogContext context, IAwaitable <bool> result)
        {
            var confirmed = await result;

            if (confirmed)
            {
                State = BotState.AskLocation;
                await ForwardToOperator(context);

                context.Wait(MessageReceivedAsync);
            }
            else
            {
                StolenObjectImages.ToList().Clear();
                PromptForStolenObjectUpload(context);
            }
        }