public AdapterWithErrorHandler(IConfiguration configuration, ILogger <BotFrameworkHttpAdapter> logger, Translator translatorMiddleware, VoiceMiddleware voiceMiddleware, ConversationState conversationState = null) : base(configuration, logger) { if (translatorMiddleware != null) { // Add translator middleware to the adapter's middleware pipeline Use(translatorMiddleware); } if (voiceMiddleware == null) { throw new NullReferenceException(nameof(voiceMiddleware)); } // Add voice middleware to the adapter's middleware pipeline Use(voiceMiddleware); 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"); }; }
public CrunchAdapterWithErrorHandler(ILogger <CrunchAdapter> logger, Translator translatorMiddleware = null, VoiceMiddleware voiceMiddleware = null) : base(new CrunchAdapterOptions() { ShouldEndSessionByDefault = false, ValidateIncomingCrunchRequests = false, AlexaSkillId = "XXXX" }, logger) { if (translatorMiddleware != null) { // Add translator middleware to the adapter's middleware pipeline Use(translatorMiddleware); } if (voiceMiddleware != null) { // Add voice middleware to the adapter's middleware pipeline Use(voiceMiddleware); } //Adapter.Use(new AlexaIntentRequestToMessageActivityMiddleware()); OnTurnError = async(turnContext, exception) => { Console.WriteLine(exception); // Log any leaked exception from the application. logger.LogError($"Exception caught : {exception.Message}"); // Send a catch-all apology to the user. await turnContext.SendActivityAsync("Sorry, it looks like something went wrong."); }; }