Ejemplo n.º 1
0
        // 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));
        }