public async Task ScenarioWithInspectionMiddlwarePassthrough()
        {
            var inspectionState      = new InspectionState(new MemoryStorage());
            var inspectionMiddleware = new InspectionMiddleware(inspectionState);

            var adapter = new TestAdapter();

            adapter.Use(inspectionMiddleware);

            var inboundActivity = MessageFactory.Text("hello");

            await adapter.ProcessActivityAsync(inboundActivity, async (turnContext, cancellationToken) =>
            {
                await turnContext.SendActivityAsync(MessageFactory.Text("hi"));
            });

            var outboundActivity = adapter.ActiveQueue.Dequeue();

            Assert.AreEqual("hi", outboundActivity.Text);
        }
Exemplo n.º 2
0
        public AdapterWithErrorHandler(IConfiguration configuration, ILogger <BotFrameworkHttpAdapter> logger, InspectionMiddleware inspectionMiddleware, ConversationState conversationState)
            : base(configuration, logger)
        {
            OnTurnError = async(turnContext, exception) =>
            {
                // Log any leaked exception from the application.
                logger.LogError($"Exception caught : {exception.Message}");

                // Send a catch-all appology to the user.
                await turnContext.SendActivityAsync("Sorry, it looks like something went wrong.");

                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($"Exception caught on attempting to Delete ConversationState : {e.Message}");
                    }
                }
            };

            Use(inspectionMiddleware);
        }
Exemplo n.º 3
0
 public DebugBot(InspectionMiddleware inspectionMiddleware)
 {
     _inspectionMiddleware = inspectionMiddleware;
 }