Example #1
0
        private async Task <DialogTurnResult> FindSimilarProductsStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var userData = await UserStateAccessor.GetAsync(stepContext.Context, () => new Models.UserData(), cancellationToken);

            var activity = stepContext.Context.Activity;
            var reply    = activity.CreateReply();

            // Search for the uploaded picture in the attachments
            if (activity.Attachments != null && activity.Attachments.Any())
            {
                var file = activity.Attachments[0];

                // Using the gender from Face Recognition we can get the customer category (Women, Men, Boys, Girls...) and filter suggested products.
                var category        = userData.Gender.Equals("female", StringComparison.InvariantCultureIgnoreCase) ? CustomerCategory.Women : CustomerCategory.Men;
                var similarProducts = await ProductService.GetSuggestedProductsByGenderAsync(file.ContentUrl, category);

                var similarProductsAttachment = new Attachment
                {
                    Content = new Dictionary <string, SuggestedProductsResult>
                    {
                        { "products", similarProducts },
                    },
                    ContentType = "text/plain",
                    Name        = "products",
                };

                var msg = "I found these similar products. Let me know if you have any questions.";
                reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                reply.Text             = msg;

                // Add audio response as an attachment

                var audioResponse = await SpeechService.SynthesizeSpeechAsync(msg);

                var audioAttachment = await BotUtils.CreateAndUploadAttachmentAsync(reply.ServiceUrl, "audio/wav", reply.Conversation.Id, audioResponse, AttachmentName, _botConfigOptions);

                reply.Attachments = new List <Attachment>
                {
                    similarProductsAttachment,
                    BotUtils.CreateAudioCard("Similar products", reply.Text, audioAttachment.ContentUrl).ToAttachment(),
                };

                // Send the card(s) to the user as an attachment to the activity
                await stepContext.Context.SendActivityAsync(reply, cancellationToken);

                // We end the dialog flow on this step as we don't need any other confirmation at this point.
                return(await stepContext.EndDialogAsync(cancellationToken : cancellationToken));
            }
            else
            {
                return(await stepContext.PromptAsync(UploadPicturePrompt, new PromptOptions { Prompt = MessageFactory.Text("Please upload an image") }, cancellationToken));
            }
        }
Example #2
0
        private async Task DisplayWelcomeAudioMessageAsync(ITurnContext turnContext, CancellationToken cancellationToken)
        {
            var activity = turnContext.Activity;
            var name     = activity.From.Name;
            var reply    = activity.CreateReply();

            reply.Text = $"Hi {name}! How can I help you today?";

            var audioResponse = await SpeechService.SynthesizeSpeechAsync(reply.Text);

            var audioAttachment = await BotUtils.CreateAndUploadAttachmentAsync(reply.ServiceUrl, "audio/wav", reply.Conversation.Id, audioResponse, "AudioGreeting", _botConfigOptions);

            var audioCard = BotUtils.CreateAudioCard("Greeting Audio", reply.Text, audioAttachment.ContentUrl).ToAttachment();

            reply.Attachments = new List <Attachment> {
                audioCard
            };

            // Store the user name in the User State
            var userData = await _accessors.UserData.GetAsync(turnContext, () => new UserData(), cancellationToken);

            userData.Name = name;

            // Store the gender

            string gender = null;

            if (turnContext.Activity.ChannelData != null)
            {
                var values = ((JObject)turnContext.Activity.ChannelData).ToObject <Dictionary <string, object> >();
                if (values.ContainsKey("gender"))
                {
                    gender          = (string)values["gender"];
                    userData.Gender = gender;

                    var imageUrl = gender.Equals("female", StringComparison.InvariantCultureIgnoreCase) ? $"{SiteImagesPath}/greeting/Kiosk_CustomAdvert_ActiveWear.png" : $"{SiteImagesPath}/greeting/Kiosk_CustomAdvert_Xbox.png";

                    var card = new HeroCard
                    {
                        Images = new List <CardImage> {
                            new CardImage(imageUrl)
                        },
                    };

                    reply.Attachments.Add(card.ToAttachment());
                }
            }

            // Send welcome message with attachment
            await turnContext.SendActivityAsync(reply);
        }
Example #3
0
        private async Task <DialogTurnResult> UploadPictureStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var reply     = stepContext.Context.Activity.CreateReply();
            var replyText = "click on the camera icon and upload a picture of yourself to show your style!";

            // Add audio response as an attachment

            var audioResponse = await SpeechService.SynthesizeSpeechAsync(replyText);

            var audioAttachment = await BotUtils.CreateAndUploadAttachmentAsync(reply.ServiceUrl, "audio/wav", reply.Conversation.Id, audioResponse, AttachmentName, _botConfigOptions);

            reply.Attachments = new List <Attachment> {
                BotUtils.CreateAudioCard("Photo Request", replyText, audioAttachment.ContentUrl).ToAttachment()
            };

            return(await stepContext.PromptAsync(UploadPicturePrompt, new PromptOptions { Prompt = reply }, cancellationToken));
        }
        private async Task <DialogTurnResult> SearchWatchesStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var userData = await BotStateAccessor.GetAsync(stepContext.Context, () => new UserData(), cancellationToken);

            if (userData.ProductWasFound)
            {
                await stepContext.Context.SendActivityAsync("I'm happy that you like them! Please take your time looking at these items. I'm here to help in case of any questions.", cancellationToken : cancellationToken);

                // We end the dialog flow on this step as we don't need any other confirmation at this point.
                return(await stepContext.EndDialogAsync(cancellationToken : cancellationToken));
            }
            else
            {
                var activity = stepContext.Context.Activity;
                var file     = activity.Attachments[0];
                var reply    = activity.CreateReply();

                // Display cropped picture of the watch
                var croppedImageAttachment = await BotUtils.CreateAndUploadAttachmentAsync(reply.ServiceUrl, "image/png", reply.Conversation.Id, userData.CroppedImage.Image, "Cropped Image", _botConfigOptions);

                reply.Attachments = new List <Attachment>()
                {
                    croppedImageAttachment
                };
                reply.Text = "I can see the watch. Let me see what we have in stock.";
                await stepContext.Context.SendActivityAsync(reply, cancellationToken);

                var imageBoxCoordinates = userData.ImageBoundingBox;
                var boundingRectangle   = await ImageUtils.GetBoundingRectangleAsync(imageBoxCoordinates.Top, imageBoxCoordinates.Left, imageBoxCoordinates.Width, imageBoxCoordinates.Height, file.ContentUrl);

                reply.Attachments = await GetSimilarWatchesAsync(file.ContentUrl, boundingRectangle);

                reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                reply.Text             = "I found these similar watches. Let me know if you have any questions.";

                // Send the card(s) to the user as an attachment to the activity
                await stepContext.Context.SendActivityAsync(reply, cancellationToken);

                // We end the dialog flow on this step as we don't need any other confirmation at this point.
                return(await stepContext.EndDialogAsync(cancellationToken : cancellationToken));
            }
        }