-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdapterWithErrorHandler.cs
More file actions
31 lines (28 loc) · 1.38 KB
/
AdapterWithErrorHandler.cs
File metadata and controls
31 lines (28 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Extensions.Logging;
namespace InterviewSchedulingBot
{
public class AdapterWithErrorHandler : CloudAdapter
{
public AdapterWithErrorHandler(
BotFrameworkAuthentication botFrameworkAuthentication,
ILogger<IBotFrameworkHttpAdapter> logger)
: base(botFrameworkAuthentication, logger)
{
OnTurnError = async (turnContext, exception) =>
{
// Log any leaked exception from the application.
logger.LogError(exception, "[OnTurnError] unhandled error : {ExceptionMessage}", exception.Message);
// Send a message to the user
var errorMessageText = "The bot encountered an error or bug.";
var errorMessage = MessageFactory.Text(errorMessageText, errorMessageText, Microsoft.Bot.Schema.InputHints.IgnoringInput);
await turnContext.SendActivityAsync(errorMessage);
errorMessageText = "To continue to run this bot, please fix the bot source code.";
errorMessage = MessageFactory.Text(errorMessageText, errorMessageText, Microsoft.Bot.Schema.InputHints.ExpectingInput);
await turnContext.SendActivityAsync(errorMessage);
};
}
}
}