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