Ejemplo n.º 1
0
        public async Task DefaultOptions_Positive()
        {
            var storage   = new MemoryStorage();
            var convState = new ConversationState(storage);

            var adapter = new TestAdapter(TestAdapter.CreateConversation("Name"))
                          .Use(new FeedbackMiddleware(convState, new NullBotTelemetryClient()));

            var response = "Response";
            var tag      = "Tag";

            await new TestFlow(adapter, async(context, cancellationToken) =>
            {
                await context.SendActivityAsync(response);
                await FeedbackMiddleware.RequestFeedbackAsync(context, tag);

                // TODO save manualy
                await convState.SaveChangesAsync(context, false, cancellationToken);
            })
            .Send("foo")
            .AssertReply(response)
            .AssertReply((activity) =>
            {
                var card = activity.AsMessageActivity().Attachments[0].Content as HeroCard;
                Assert.AreEqual(card.Buttons.Count, 3);
            })
            .Send(positiveFeedback)
            .AssertReply("Thanks, I appreciate your feedback.")
            .StartTestAsync();
        }
Ejemplo n.º 2
0
        protected override async Task CompleteAsync(DialogContext dc, DialogTurnResult result = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            // The active dialog's stack ended with a complete status
            await _responder.ReplyWith(dc.Context, MainResponses.ResponseIds.Completed);

            // Request feedback on the last activity.
            await FeedbackMiddleware.RequestFeedbackAsync(dc.Context, Id);
        }
Ejemplo n.º 3
0
        public async Task DefaultOptions_Comment()
        {
            var storage   = new MemoryStorage();
            var convState = new ConversationState(storage);

            var adapter = new TestAdapter(TestAdapter.CreateConversation("Name"))
                          .Use(new FeedbackMiddleware(convState, new NullBotTelemetryClient(), new FeedbackOptions
            {
                CommentsEnabled = true,
            }));

            var response = "Response";
            var tag      = "Tag";

            await new TestFlow(adapter, async(context, cancellationToken) =>
            {
                await context.SendActivityAsync(response);
                await FeedbackMiddleware.RequestFeedbackAsync(context, tag);

                // TODO save manualy
                await convState.SaveChangesAsync(context, false, cancellationToken);
            })
            .Send("foo")
            .AssertReply(response)
            .AssertReply((activity) =>
            {
                var card = activity.AsMessageActivity().Attachments[0].Content as HeroCard;
                Assert.AreEqual(card.Buttons.Count, 3);
            })
            .Send(negativeFeedback)
            .AssertReply((activity) =>
            {
                var card = activity.AsMessageActivity().Attachments[0].Content as HeroCard;
                Assert.AreEqual(card.Text, "Please add any additional comments in the chat.");
                Assert.AreEqual(card.Buttons.Count, 1);
            })
            .Send("comment")
            .AssertReply("Your comment has been received.")
            .StartTestAsync();
        }
        public AdapterWithErrorHandler(IConfiguration configuration, ILogger <BotFrameworkHttpAdapter> logger, FeedbackMiddleware feedbackMiddleware, TranslationMiddleware translationMiddleware, ConversationState conversationState = null)
            : base(configuration, logger)
        {
            if (Util.IsSupportingMultiLingual)
            {
                if (translationMiddleware == null)
                {
                    throw new NullReferenceException(nameof(translationMiddleware));
                }

                // Add to the adapter's middleware pipeline
                Use(translationMiddleware);
            }
            if (Util.IsRequestingUserFeedback)
            {
                if (feedbackMiddleware == null)
                {
                    throw new NullReferenceException(nameof(feedbackMiddleware));
                }
                // Add to the adapter's middleware pipeline
                Use(feedbackMiddleware);
            }

            OnTurnError = async(turnContext, exception) =>
            {
                // Log any leaked exception from the application.
                logger.LogError(exception, $"[OnTurnError] unhandled error : {exception.Message}");

                await SendWithoutMiddleware(turnContext, configuration["InternalErrorResponse"]);

                if (conversationState != null)
                {
                    try
                    {
                        // Delete the conversationState for the current conversation to prevent the
                        // bot from getting stuck in a error-loop caused by being in a bad state.
                        // ConversationState should be thought of as similar to "cookie-state" in a Web pages.
                        await conversationState.DeleteAsync(turnContext);
                    }
                    catch (Exception e)
                    {
                        logger.LogError(e, $"Exception caught on attempting to Delete ConversationState : {e.Message}");
                    }
                }

                // Send a trace activity, which will be displayed in the Bot Framework Emulator
                await turnContext.TraceActivityAsync("OnTurnError Trace", exception.Message, "https://www.botframework.com/schemas/error", "TurnError");
            };
        }