/// <summary>
        /// Initializes a new instance of the <see cref="SkillAdapterWithErrorHandler"/> class to handle errors.
        /// </summary>
        /// <param name="botFrameworkAuthentication">The cloud environment for the bot.</param>
        /// <param name="logger">An instance of a logger.</param>
        public SkillAdapterWithErrorHandler(BotFrameworkAuthentication botFrameworkAuthentication, ILogger <CloudAdapter> logger)
            : base(botFrameworkAuthentication, logger)
        {
            OnTurnError = async(turnContext, exception) =>
            {
                try
                {
                    // Log any leaked exception from the application.
                    logger.LogError(exception, $"[OnTurnError] unhandled error : {exception.Message}");

                    // Send a message to the user
                    var errorMessageText = "The skill encountered an error or bug.";
                    var errorMessage     = MessageFactory.Text(errorMessageText + Environment.NewLine + exception, errorMessageText, InputHints.IgnoringInput);
                    errorMessage.Value = exception;
                    await turnContext.SendActivityAsync(errorMessage);

                    errorMessageText = "To continue to run this bot, please fix the bot source code.";
                    errorMessage     = MessageFactory.Text(errorMessageText, errorMessageText, InputHints.ExpectingInput);
                    await turnContext.SendActivityAsync(errorMessage);

                    // Send a trace activity, which will be displayed in the Bot Framework Emulator
                    // Note: we return the entire exception in the value property to help the developer, this should not be done in prod.
                    await turnContext.TraceActivityAsync("OnTurnError Trace", exception.ToString(), "https://www.botframework.com/schemas/error", "TurnError");

                    // Send and EndOfConversation activity to the skill caller with the error to end the conversation
                    // and let the caller decide what to do.
                    var endOfConversation = Activity.CreateEndOfConversationActivity();
                    endOfConversation.Code = "SkillError";
                    endOfConversation.Text = exception.Message;
                    await turnContext.SendActivityAsync(endOfConversation);
                }
                catch (Exception ex)
                {
                    logger.LogError(ex, $"Exception caught in SkillAdapterWithErrorHandler : {ex}");
                }
            };
        }
Esempio n. 2
0
        public AdapterWithErrorHandler(BotFrameworkAuthentication auth, ILogger <IBotFrameworkHttpAdapter> logger, ConversationState conversationState = default)
            : base(auth, logger)
        {
            OnTurnError = async(turnContext, exception) =>
            {
                // Log any leaked exception from the application.
                logger.LogError(exception, $"[OnTurnError] unhandled error : {exception.Message}");

                // Send a message to the user
                var errorMessageText = "The bot encountered an error or bug.";
                var errorMessage     = MessageFactory.Text(errorMessageText, errorMessageText, InputHints.ExpectingInput);
                await turnContext.SendActivityAsync(errorMessage);

                errorMessageText = "To continue to run this bot, please fix the bot source code.";
                errorMessage     = MessageFactory.Text(errorMessageText, errorMessageText, InputHints.ExpectingInput);
                await turnContext.SendActivityAsync(errorMessage);

                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");
            };
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CloudAdapter"/> class.
 /// </summary>
 /// <param name="botFrameworkAuthentication">The <see cref="BotFrameworkAuthentication"/> this adapter should use.</param>
 /// <param name="logger">The <see cref="ILogger"/> implementation this adapter should use.</param>
 public CloudAdapter(
     BotFrameworkAuthentication botFrameworkAuthentication,
     ILogger logger = null)
     : base(botFrameworkAuthentication, logger)
 {
 }
Esempio n. 4
0
 public ServiceNowHandoffMiddleware(ConversationHandoffRecordMap conversationHandoffRecordMap, IServiceNowCredentialsProvider creds, BotFrameworkAuthentication botFrameworkAuth) : base(conversationHandoffRecordMap)
 {
     _conversationHandoffRecordMap = conversationHandoffRecordMap;
     _creds            = creds;
     _botFrameworkAuth = botFrameworkAuth;
 }
Esempio n. 5
0
 public TestCloudChannelServiceHandler(BotFrameworkAuthentication auth)
     : base(auth)
 {
 }
Esempio n. 6
0
 public SkillAdapterWithErrorHandler(BotFrameworkAuthentication auth, ILogger <IBotFrameworkHttpAdapter> logger)
     : base(auth, logger)
 {
     _logger     = logger ?? throw new ArgumentNullException(nameof(logger));
     OnTurnError = HandleTurnError;
 }
Esempio n. 7
0
 public StreamingTestCloudAdapter(BotFrameworkAuthentication auth, StreamingConnection connection)
     : base(auth)
 {
     _connection = connection;
 }
Esempio n. 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CloudChannelServiceHandler"/> class, using Bot Framework Authentication.
 /// </summary>
 /// <param name="auth">The Bot Framework Authentication object.</param>
 public CloudChannelServiceHandler(BotFrameworkAuthentication auth)
 {
     _auth = auth ?? throw new ArgumentNullException(nameof(auth));
 }
 public TestCloudAdapter(BotFrameworkAuthentication botFrameworkAuthentication)
     : base(botFrameworkAuthentication)
 {
 }