/// <summary> /// Create a <see cref="HostedActivityService"/> instance for processing Bot Framework Activities\ /// on background threads. /// </summary> /// <param name="config"><see cref="IConfiguration"/> used to retrieve ShutdownTimeoutSeconds from appsettings.</param> /// <param name="bot">IBot which will be used to process Activities.</param> /// <param name="adapter"><see cref="ImmediateAcceptAdapter"/> used to process Activities. </param> /// <param name="activityTaskQueue"><see cref="IActivityTaskQueue"/>Queue of activities to be processed. This class /// contains a semaphore which the BackgroundService waits on to be notified of activities to be processed.</param> /// <param name="logger">Logger to use for logging BackgroundService processing and exception information.</param> public HostedActivityService(IConfiguration config, IBot bot, ImmediateAcceptAdapter adapter, IActivityTaskQueue activityTaskQueue, ILogger <HostedTaskService> logger) { if (config == null) { throw new ArgumentNullException(nameof(config)); } if (bot == null) { throw new ArgumentNullException(nameof(bot)); } if (adapter == null) { throw new ArgumentNullException(nameof(adapter)); } if (activityTaskQueue == null) { throw new ArgumentNullException(nameof(activityTaskQueue)); } _shutdownTimeoutSeconds = config.GetValue <int>("ShutdownTimeoutSeconds"); _activityQueue = activityTaskQueue; _bot = bot; _adapter = adapter; _logger = logger ?? NullLogger <HostedTaskService> .Instance; }
/// <summary> /// Create an instance of <see cref="ImmediateAcceptAdapter"/>. /// </summary> /// <param name="configuration"></param> /// <param name="logger"></param> /// <param name="activityTaskQueue"></param> public ImmediateAcceptAdapter(IConfiguration configuration, ILogger <BotFrameworkHttpAdapter> logger, IActivityTaskQueue activityTaskQueue) : base(configuration, logger) { _activityTaskQueue = activityTaskQueue; 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 await turnContext.SendActivityAsync("The bot encountered an error or bug."); await turnContext.SendActivityAsync("To continue to run this bot, please fix the bot source code."); // 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"); }; }