Exemplo n.º 1
0
        public void SetBotAdapter(BotAdapter adapter, IStorage storage, BotSettings settings, UserState userState, ConversationState conversationState, IServiceProvider s, TelemetryInitializerMiddleware telemetryInitializerMiddleware)
        {
            adapter
            .UseStorage(storage)
            .UseBotState(userState)
            .Use(new RegisterClassMiddleware <ConversationState>(conversationState, typeof(ConversationState).FullName))
            .Use(new RegisterClassMiddleware <IConfiguration>(Configuration))
            .Use(new RegisterClassMiddleware <BotAdapter>(adapter))
            .Use(new RegisterClassMiddleware <TaskManager>(new TaskManager()))
            .Use(new HandleGroupMentionMiddleware())
            .Use(new ReferenceMiddleware())
            .Use(telemetryInitializerMiddleware);

            // Configure Middlewares
            ConfigureTranscriptLoggerMiddleware(adapter, settings);
            ConfigureInspectionMiddleWare(adapter, settings, storage);
            ConfigureShowTypingMiddleWare(adapter, settings);

            adapter.OnTurnError = async(turnContext, exception) =>
            {
                await turnContext.SendActivityAsync(exception.Message).ConfigureAwait(false);

                await conversationState.ClearStateAsync(turnContext).ConfigureAwait(false);

                await conversationState.SaveChangesAsync(turnContext).ConfigureAwait(false);
            };
        }