-
Notifications
You must be signed in to change notification settings - Fork 177
/
Copy pathAdapterWithMiddleware.cs
54 lines (46 loc) · 2.33 KB
/
AdapterWithMiddleware.cs
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using Bot.Builder.Community.Cards.Management;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Bot.Builder.TraceExtensions;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace Cards_Library_Sample
{
public class AdapterWithMiddleware : BotFrameworkHttpAdapter
{
public AdapterWithMiddleware(
IConfiguration configuration,
InspectionState inspectionState,
ConversationState conversationState,
CardManager cardManager,
ILogger<BotFrameworkHttpAdapter> logger)
: base(configuration, logger)
{
// Inspection needs credentials because it will be sending the Activities and User and Conversation State to the emulator
var credentials = new MicrosoftAppCredentials(configuration["MicrosoftAppId"], configuration["MicrosoftAppPassword"]);
Use(new InspectionMiddleware(inspectionState, null, conversationState, credentials));
var cardManagerMiddleware = new CardManagerMiddleware(cardManager);
cardManagerMiddleware.NonUpdatingOptions.AutoClearEnabledOnSend = false;
Use(cardManagerMiddleware
.SetAutoApplyIds(false)
.SetIdOptions(new DataIdOptions(new[]
{
DataIdScopes.Action,
DataIdScopes.Card,
DataIdScopes.Carousel,
DataIdScopes.Batch,
})));
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");
};
}
}
}