Skip to content

Instantly share code, notes, and snippets.

@sunnyy02
Created March 3, 2022 00:03
Show Gist options
  • Save sunnyy02/434a8f6d0f93551e2ad7931e9fddf745 to your computer and use it in GitHub Desktop.
Save sunnyy02/434a8f6d0f93551e2ad7931e9fddf745 to your computer and use it in GitHub Desktop.
using Microsoft.Bot.Builder.Adapters.Twilio;
using Microsoft.Bot.Builder.TraceExtensions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace AppointmentBot
{
public class TwilioAdapterWithErrorHandler : TwilioAdapter
{
public TwilioAdapterWithErrorHandler(IConfiguration configuration, ILogger<TwilioAdapter> logger)
: base(configuration, null, 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
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");
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment