Exemplo n.º 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers().AddNewtonsoftJson();

            services.AddSingleton <IConfiguration>(this.Configuration);

            // Load settings
            var settings = new BotSettings();

            Configuration.Bind(settings);

            var storage = ConfigureStorage(settings);

            services.AddSingleton(storage);
            var userState         = new UserState(storage);
            var conversationState = new ConversationUserState(storage);

            services.AddSingleton(userState);
            services.AddSingleton <ConversationState>(conversationState);

            // Create the credential provider to be used with the Bot Framework Adapter.
            services.AddSingleton <ICredentialProvider, ConfigurationCredentialProvider>();
            services.AddSingleton <BotAdapter>(sp => (BotFrameworkHttpAdapter)sp.GetService <IBotFrameworkHttpAdapter>());

            // Register AuthConfiguration to enable custom claim validation.
            services.AddSingleton <AuthenticationConfiguration>();

            // register components.
            ComponentRegistration.Add(new DialogsComponentRegistration());
            ComponentRegistration.Add(new DeclarativeComponentRegistration());
            ComponentRegistration.Add(new AdaptiveComponentRegistration());
            ComponentRegistration.Add(new LanguageGenerationComponentRegistration());
            ComponentRegistration.Add(new QnAMakerComponentRegistration());

            // ComponentRegistration.Add(new LuisComponentRegistration());

            // This is for custom action component registration.
            ComponentRegistration.Add(new CustomActionComponentRegistration());

            // Register the skills client and skills request handler.
            var skillConversationIdFactory = new SkillConversationIdFactory(storage);

            services.AddSingleton <SkillConversationIdFactoryBase>(skillConversationIdFactory);
            services.AddHttpClient <BotFrameworkClient, SkillHttpClient>();
            services.AddSingleton <ChannelServiceHandler, SkillHandler>();

            // Register telemetry client, initializers and middleware
            services.AddApplicationInsightsTelemetry(settings.ApplicationInsights.InstrumentationKey);
            services.AddSingleton <ITelemetryInitializer, OperationCorrelationTelemetryInitializer>();
            services.AddSingleton <ITelemetryInitializer, TelemetryBotIdInitializer>();
            services.AddSingleton <IBotTelemetryClient, BotTelemetryClient>();
            services.AddSingleton <TelemetryLoggerMiddleware>(sp =>
            {
                var telemetryClient = sp.GetService <IBotTelemetryClient>();
                return(new TelemetryLoggerMiddleware(telemetryClient, logPersonalInformation: settings.Telemetry.LogPersonalInformation));
            });
            services.AddSingleton <TelemetryInitializerMiddleware>(sp =>
            {
                var httpContextAccessor       = sp.GetService <IHttpContextAccessor>();
                var telemetryLoggerMiddleware = sp.GetService <TelemetryLoggerMiddleware>();
                return(new TelemetryInitializerMiddleware(httpContextAccessor, telemetryLoggerMiddleware, settings.Telemetry.LogActivities));
            });

            var cachedLuisManager = new CachedLuisManager(settings.CachedLuis);

            // Configure bot loading path
            var botDir           = settings.Bot;
            var resourceExplorer = new ResourceExplorer().AddFolder(botDir).RegisterType(LuisAdaptiveRecognizer.Kind, typeof(CachedLuisRecognizer), new CachedLuisLoader(cachedLuisManager));
            var rootDialog       = GetRootDialog(botDir);

            var defaultLocale = Configuration.GetValue <string>("defaultLanguage") ?? "en-us";

            services.AddSingleton(resourceExplorer);

            resourceExplorer.RegisterType <OnQnAMatch>("Microsoft.OnQnAMatch");

            services.AddSingleton <IBotFrameworkHttpAdapter, BotFrameworkHttpAdapter>((s) => GetBotAdapter(storage, settings, userState, conversationState, s, s.GetService <TelemetryInitializerMiddleware>()));

            var removeRecipientMention = settings?.Feature?.RemoveRecipientMention ?? false;

            services.AddSingleton <IBot>((s) => new ComposerBot(
                                             conversationState,
                                             userState,
                                             resourceExplorer,
                                             s.GetService <BotFrameworkClient>(),
                                             skillConversationIdFactory,
                                             s.GetService <IBotTelemetryClient>(),
                                             rootDialog,
                                             defaultLocale,
                                             removeRecipientMention));

            var discordAdapterOptions = new DiscordAdapterOptions
            {
                Token = settings.DiscordToken
            };

            services.AddSingleton((s) =>
            {
                var adapter = new DiscordAdapter(
                    discordAdapterOptions,
                    s.GetService <IBot>());
                SetBotAdapter(adapter, storage, settings, userState, conversationState, s, s.GetService <TelemetryInitializerMiddleware>());
                return(adapter);
            });

            Task.Run(async() =>
            {
                var client = new HttpClient();
                await client.GetAsync(settings.HostUrl + "/discord");
            });
        }
Exemplo n.º 2
0
 public DiscordController(DiscordAdapter adapter)
 {
     this._adapter = adapter;
 }
Exemplo n.º 3
0
 public NotificationManager()
 {
     api     = DiscordAdapter.Instance;
     taskbar = new TaskBarNotice();
 }