// Will only be included if _feedbackOptions.FeedbackEnabled is set to true private async Task <DialogTurnResult> ProcessFeedback(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var record = await _feedbackAccessor.GetAsync(stepContext.Context, () => new FeedbackRecord()).ConfigureAwait(false); var passQueryToNext = stepContext.Result is FeedbackUtil.RouteQueryFlag; var userResponse = stepContext.Context.Activity.Text; if (passQueryToNext) { // skip this step and pass the query into next step return(await stepContext.NextAsync(stepContext.Result)); } else if (userResponse == (string)_feedbackOptions.DismissAction.Value && record.Feedback == null) { // user dismissed first feedback prompt, skip this step return(await stepContext.NextAsync()); } if (_feedbackOptions.CommentsEnabled) { if (userResponse != (string)_feedbackOptions.DismissAction.Value) { // user responded to first feedback prompt and replied to comment prompt record.Comment = userResponse; FeedbackUtil.LogFeedback(record, TelemetryClient); await stepContext.Context.SendActivityAsync(MessageFactory.Text(_feedbackOptions.FeedbackReceivedMessage)); return(await stepContext.NextAsync()); } } FeedbackUtil.LogFeedback(record, TelemetryClient); return(await stepContext.NextAsync()); }
// Wil only be included if _feedbackOptions.FeedbackEnabled is set to true private async Task <DialogTurnResult> RequestFeedback(WaterfallStepContext stepContext, CancellationToken cancellationToken) { return(await stepContext.PromptAsync(DialogIds.FeedbackPrompt, new PromptOptions() { Prompt = FeedbackUtil.CreateFeedbackActivity(stepContext.Context), })); }
// Will only be included if _feedbackOptions.FeedbackEnabled is set to true private async Task <DialogTurnResult> RequestFeedbackComment(WaterfallStepContext stepContext, CancellationToken cancellationToken) { // Clear feedback state await _feedbackAccessor.DeleteAsync(stepContext.Context).ConfigureAwait(false); var userResponse = stepContext.Context.Activity.Text; if (userResponse == (string)_feedbackOptions.DismissAction.Value) { // user dismissed feedback action prompt return(await stepContext.NextAsync()); } var botResponses = await _previousResponseAccessor.GetAsync(stepContext.Context, () => new List <Activity>()); // Get last activity of previous dialog to send with feedback data var feedbackActivity = botResponses.Count >= 2 ? botResponses[botResponses.Count - 2] : botResponses.LastOrDefault(); var record = new FeedbackRecord() { Request = feedbackActivity, Tag = "EndOfDialogFeedback" }; if (_feedbackOptions.FeedbackActions.Any(f => userResponse == (string)f.Value)) { // user selected a feedback action record.Feedback = userResponse; await _feedbackAccessor.SetAsync(stepContext.Context, record).ConfigureAwait(false); if (_feedbackOptions.CommentsEnabled) { return(await stepContext.PromptAsync(DialogIds.FeedbackPrompt, new PromptOptions() { Prompt = FeedbackUtil.GetFeedbackCommentPrompt(stepContext.Context), })); } else { return(await stepContext.NextAsync()); } } else { // user sent a query unrelated to feedback return(await stepContext.NextAsync(new FeedbackUtil.RouteQueryFlag { RouteQuery = true })); } }
public void Test_FeedbackCommentPrompt() { // Get TestAdapter var sp = Services.BuildServiceProvider(); var adapter = sp.GetService<TestAdapter>(); // Create EventActivity var eventActivity = new Activity() { ChannelId = "Test", Type = ActivityTypes.Message, Conversation = new ConversationAccount(id: $"{Guid.NewGuid()}"), From = new ChannelAccount(id: "Test", name: "Test"), Recipient = new ChannelAccount(id: "Test", name: "Test"), Value = "Test" }; // Create turnContext with EventActivity var turnContext = new TurnContext(adapter, eventActivity); var testFeedback = FeedbackUtil.GetFeedbackCommentPrompt(turnContext); Assert.IsTrue(testFeedback.Text != null && testFeedback.Text.Contains(FeedbackResponses.FeedbackReceivedMessage)); }