Exemplo n.º 1
0
        public void ConfigureServices(IServiceCollection services)
        {
            // Configure MVC
            services.AddControllers().AddNewtonsoftJson();

            // Configure channel provider
            services.AddSingleton <IChannelProvider, ConfigurationChannelProvider>();

            // Register AuthConfiguration to enable custom claim validation.
            services.AddSingleton(sp => new AuthenticationConfiguration {
                ClaimsValidator = new AllowedCallersClaimsValidator(sp.GetService <IConfiguration>())
            });

            // Configure server options
            services.Configure <KestrelServerOptions>(options =>
            {
                options.AllowSynchronousIO = true;
            });

            services.Configure <IISServerOptions>(options =>
            {
                options.AllowSynchronousIO = true;
            });

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

            Configuration.Bind(settings);
            services.AddSingleton <BotSettings>(settings);
            services.AddSingleton <BotSettingsBase>(settings);

            // Configure credentials
            services.AddSingleton <ICredentialProvider, ConfigurationCredentialProvider>();
            services.AddSingleton(new MicrosoftAppCredentials(settings.MicrosoftAppId, settings.MicrosoftAppPassword));

            // Configure bot state
            // Uncomment the following line for local development without Cosmos Db
            // services.AddSingleton<IStorage>(new MemoryStorage());
            services.AddSingleton <IStorage>(new CosmosDbPartitionedStorage(settings.CosmosDb));
            services.AddSingleton <UserState>();
            services.AddSingleton <ConversationState>();
            services.AddSingleton(sp =>
            {
                var userState         = sp.GetService <UserState>();
                var conversationState = sp.GetService <ConversationState>();
                return(new BotStateSet(userState, conversationState));
            });

            // Configure telemetry
            services.AddApplicationInsightsTelemetry();
            services.AddSingleton <IBotTelemetryClient, BotTelemetryClient>();
            services.AddSingleton <ITelemetryInitializer, OperationCorrelationTelemetryInitializer>();
            services.AddSingleton <ITelemetryInitializer, TelemetryBotIdInitializer>();
            services.AddSingleton <TelemetryInitializerMiddleware>();
            services.AddSingleton <TelemetryLoggerMiddleware>();

            // Configure bot services
            services.AddSingleton <BotServices>();

            // Configure proactive
            services.AddSingleton <IBackgroundTaskQueue, BackgroundTaskQueue>();
            services.AddHostedService <QueuedHostedService>();

            // Configure HttpContext required for path resolution
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            services.AddSingleton(LocaleTemplateManagerWrapper.CreateLocaleTemplateManager("en-us", "de-de", "es-es", "fr-fr", "it-it", "zh-cn"));

            // register dialogs
            services.AddTransient <MainDialog>();
            services.AddTransient <BookingDialog>();
            services.AddTransient <CancelDialog>();

            // Configure adapters
            services.AddSingleton <IBotFrameworkHttpAdapter, DefaultAdapter>();

            // Configure bot
            services.AddTransient <MainDialog>();
            services.AddTransient <IBot, DefaultActivityHandler <MainDialog> >();
        }
Exemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Configure MVC
            services.AddControllers().AddNewtonsoftJson();;

            // Configure server options
            services.Configure <KestrelServerOptions>(options =>
            {
                options.AllowSynchronousIO = true;
            });

            services.Configure <IISServerOptions>(options =>
            {
                options.AllowSynchronousIO = true;
            });

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

            Configuration.Bind(settings);
            services.AddSingleton(settings);
            services.AddSingleton <BotSettingsBase>(settings);

            // Configure channel provider
            services.AddSingleton <IChannelProvider, ConfigurationChannelProvider>();

            // Register AuthConfiguration to enable custom claim validation.
            services.AddSingleton(sp => new AuthenticationConfiguration {
                ClaimsValidator = new AllowedCallersClaimsValidator(sp.GetService <IConfiguration>())
            });

            // Configure configuration provider
            services.AddSingleton <ICredentialProvider, ConfigurationCredentialProvider>();

            // Configure telemetry
            services.AddApplicationInsightsTelemetry();
            services.AddSingleton <IBotTelemetryClient, BotTelemetryClient>();
            services.AddSingleton <ITelemetryInitializer, OperationCorrelationTelemetryInitializer>();
            services.AddSingleton <ITelemetryInitializer, TelemetryBotIdInitializer>();
            services.AddSingleton <TelemetryInitializerMiddleware>();
            services.AddSingleton <TelemetryLoggerMiddleware>();

            // Configure bot services
            services.AddSingleton <BotServices>();

            // Configure storage
            // Uncomment the following line for local development without Cosmos Db
            // services.AddSingleton<IStorage>(new MemoryStorage());
            services.AddSingleton <IStorage>(new CosmosDbPartitionedStorage(settings.CosmosDb));
            services.AddSingleton <SubscriptionManager>();
            services.AddSingleton <UserState>();
            services.AddSingleton <ConversationState>();
            services.AddSingleton(sp =>
            {
                var userState         = sp.GetService <UserState>();
                var conversationState = sp.GetService <ConversationState>();
                return(new BotStateSet(userState, conversationState));
            });

            // Configure proactive
            services.AddSingleton <ProactiveState>();
            services.AddSingleton <IMessageReceiver <ServiceNowNotification>, ServiceNowMessageReceiver>();
            services.AddSingleton <IBackgroundTaskQueue, BackgroundTaskQueue>();
            services.AddHostedService <QueuedHostedService>();

            // Configure responses
            services.AddSingleton(LocaleTemplateManagerWrapper.CreateLocaleTemplateManager("en-us"));

            // Configure service
            services.AddSingleton <IServiceManager>(new ServiceManager());

            // Configure TeamsConnectorClient
            ///// TODO: Check the ConnectorClient from TurnState
            services.AddSingleton <IConnectorClient>(new ConnectorClient(new Uri(Configuration["TeamsTrustedUrl"]), new MicrosoftAppCredentials(settings.MicrosoftAppId, settings.MicrosoftAppPassword)));

            // Configure TeamsUpdateActivity
            services.AddSingleton <ITeamsActivity <AdaptiveCard>, TeamsUpdateAdaptiveCardActivity>();

            // Register dialogs
            services.AddTransient <CreateTicketDialog>();
            services.AddTransient <UpdateTicketDialog>();
            services.AddTransient <ShowTicketDialog>();
            services.AddTransient <CloseTicketDialog>();
            services.AddTransient <ShowKnowledgeDialog>();
            services.AddTransient <CreateSubscriptionDialog>();
            services.AddTransient <MainDialog>();

            // Configure adapters
            services.AddSingleton <IBotFrameworkHttpAdapter, DefaultAdapter>();

            // Configure bot
            services.AddTransient <IBot, DefaultActivityHandler <MainDialog> >();
        }
        public void Initialize()
        {
            // Initialize service collection
            Services = new ServiceCollection();
            Services.AddSingleton(new BotSettings()
            {
                AzureMapsKey = MockData.Key
            });
            Services.AddSingleton(new BotServices()
            {
                CognitiveModelSets = new Dictionary <string, CognitiveModelSet>
                {
                    {
                        "en", new CognitiveModelSet()
                        {
                            LuisServices = new Dictionary <string, LuisRecognizer>
                            {
                                { "General", new Fakes.MockGeneralLuisRecognizer() },
                                {
                                    "PointOfInterest", new Fakes.MockPointOfInterestLuisRecognizer(
                                        new FindParkingUtterances(),
                                        new FindPointOfInterestUtterances(),
                                        new RouteFromXToYUtterances())
                                }
                            }
                        }
                    }
                }
            });

            Services.AddSingleton <IBotTelemetryClient, NullBotTelemetryClient>();
            Services.AddSingleton(new UserState(new MemoryStorage()));
            Services.AddSingleton(new ConversationState(new MemoryStorage()));
            Services.AddSingleton(new ProactiveState(new MemoryStorage()));
            Services.AddSingleton(sp =>
            {
                var userState         = sp.GetService <UserState>();
                var conversationState = sp.GetService <ConversationState>();
                var proactiveState    = sp.GetService <ProactiveState>();
                return(new BotStateSet(userState, conversationState));
            });

            // Configure localized responses
            var templateEngine = LocaleTemplateManagerWrapper.CreateLocaleTemplateManager("en-us", "de-de", "es-es", "fr-fr", "it-it", "zh-cn");

            Services.AddSingleton(templateEngine);

            AllTemplates = LocaleTemplateManagerWrapper.CreateTemplates();

            Services.AddSingleton <IServiceManager, MockServiceManager>();
            Services.AddSingleton <IBackgroundTaskQueue, BackgroundTaskQueue>();
            Services.AddSingleton <TestAdapter, DefaultTestAdapter>();
            Services.AddTransient <MainDialog>();
            Services.AddTransient <CancelRouteDialog>();
            Services.AddTransient <FindParkingDialog>();
            Services.AddTransient <FindPointOfInterestDialog>();
            Services.AddTransient <RouteDialog>();
            Services.AddTransient <GetDirectionsDialog>();
            Services.AddTransient <IBot, DefaultActivityHandler <MainDialog> >();

            var mockHttpContext = new DefaultHttpContext();

            mockHttpContext.Request.Scheme = "http";
            mockHttpContext.Request.Host   = new HostString("localhost", 3980);
            Services.AddSingleton <IHttpContextAccessor>(new HttpContextAccessor {
                HttpContext = mockHttpContext
            });
        }
Exemplo n.º 4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Configure MVC
            services.AddControllers().AddNewtonsoftJson();

            // Configure server options
            services.Configure <KestrelServerOptions>(options =>
            {
                options.AllowSynchronousIO = true;
            });

            services.Configure <IISServerOptions>(options =>
            {
                options.AllowSynchronousIO = true;
            });

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

            Configuration.Bind(settings);
            services.AddSingleton(settings);
            services.AddSingleton <BotSettingsBase>(settings);

            // Configure channel provider
            services.AddSingleton <IChannelProvider, ConfigurationChannelProvider>();

            // Register AuthConfiguration to enable custom claim validation.
            services.AddSingleton(sp => new AuthenticationConfiguration {
                ClaimsValidator = new AllowedCallersClaimsValidator(sp.GetService <IConfiguration>())
            });

            // Configure credentials
            services.AddSingleton <ICredentialProvider, ConfigurationCredentialProvider>();

            // Configure telemetry
            services.AddApplicationInsightsTelemetry();
            services.AddSingleton <IBotTelemetryClient, BotTelemetryClient>();
            services.AddSingleton <ITelemetryInitializer, OperationCorrelationTelemetryInitializer>();
            services.AddSingleton <ITelemetryInitializer, TelemetryBotIdInitializer>();
            services.AddSingleton <TelemetryInitializerMiddleware>();
            services.AddSingleton <TelemetryLoggerMiddleware>();

            // Configure bot services
            services.AddSingleton <BotServices>();

            // Configure storage
            // Uncomment the following line for local development without Cosmos Db
            // services.AddSingleton<IStorage, MemoryStorage>();
            services.AddSingleton <IStorage>(new CosmosDbPartitionedStorage(settings.CosmosDb));
            services.AddSingleton <UserState>();
            services.AddSingleton <ConversationState>();
            services.AddSingleton(sp =>
            {
                var userState         = sp.GetService <UserState>();
                var conversationState = sp.GetService <ConversationState>();
                return(new BotStateSet(userState, conversationState));
            });

            // Configure proactive
            services.AddSingleton <IBackgroundTaskQueue, BackgroundTaskQueue>();
            services.AddHostedService <QueuedHostedService>();

            // Configure responses
            services.AddSingleton(LocaleTemplateManagerWrapper.CreateLocaleTemplateManager("en-us"));

            // Configure services
            services.AddSingleton <IHotelService, HotelService>();

            // Register dialogs
            services.AddTransient <CheckOutDialog>();
            services.AddTransient <LateCheckOutDialog>();
            services.AddTransient <ExtendStayDialog>();
            services.AddTransient <GetReservationDialog>();
            services.AddTransient <RequestItemDialog>();
            services.AddTransient <RoomServiceDialog>();
            services.AddTransient <MainDialog>();

            // Configure adapters
            services.AddTransient <IBotFrameworkHttpAdapter, DefaultAdapter>();

            // Configure bot
            services.AddTransient <IBot, DefaultActivityHandler <MainDialog> >();
        }
Exemplo n.º 5
0
        public void Initialize()
        {
            // Initialize service collection
            Services = new ServiceCollection();

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

            settings.OAuthConnections = new List <OAuthConnection>()
            {
                new OAuthConnection()
                {
                    Name = AuthenticationProvider, Provider = AuthenticationProvider
                }
            };
            settings.LimitSize             = MockData.LimitSize;
            settings.ServiceNowUrl         = MockData.ServiceNowUrl;
            settings.ServiceNowGetUserId   = MockData.ServiceNowGetUserId;
            settings.ServiceNowNamespaceId = MockData.ServiceNowNamespaceId;
            settings.MicrosoftAppId        = MockData.MicrosoftAppId;
            settings.MicrosoftAppPassword  = MockData.MicrosoftAppPassword;
            Services.AddSingleton(settings);
            Services.AddSingleton <BotSettingsBase>(settings);

            // Configure TeamsUpdateActivity
            var mockTeamsUpdateActivity = new Mock <ITeamsActivity <AdaptiveCard> >();

            mockTeamsUpdateActivity.Setup(x => x.UpdateTaskModuleActivityAsync(
                                              It.IsAny <ITurnContext>(),
                                              It.IsAny <ActivityReference>(),
                                              It.IsAny <AdaptiveCard>(),
                                              It.IsAny <CancellationToken>())).Returns(Task.FromResult(new ResourceResponse {
                Id = "1"
            }));
            Services.AddSingleton <ITeamsActivity <AdaptiveCard> >(mockTeamsUpdateActivity.Object);

            // Configure telemetry
            Services.AddSingleton <IBotTelemetryClient, NullBotTelemetryClient>();

            // Configure bot services
            Services.AddSingleton(new BotServices()
            {
                CognitiveModelSets = new Dictionary <string, CognitiveModelSet>
                {
                    {
                        "en-us", new CognitiveModelSet()
                        {
                            LuisServices = new Dictionary <string, LuisRecognizer>
                            {
                                {
                                    "General", new BaseMockLuisRecognizer <GeneralLuis>(
                                        new GeneralTestUtterances())
                                },
                                {
                                    "ITSM", new BaseMockLuisRecognizer <ITSMLuis>(
                                        new TicketCloseUtterances(),
                                        new TicketCreateUtterances(),
                                        new TicketShowUtterances(),
                                        new TicketUpdateUtterances(),
                                        new KnowledgeShowUtterances())
                                }
                            }
                        }
                    }
                }
            });

            // Configure storage
            Services.AddSingleton <IStorage, MemoryStorage>();
            Services.AddSingleton <UserState>();
            Services.AddSingleton <ConversationState>();
            Services.AddSingleton <ProactiveState>();
            Services.AddSingleton(sp =>
            {
                var userState         = sp.GetService <UserState>();
                var conversationState = sp.GetService <ConversationState>();
                return(new BotStateSet(userState, conversationState));
            });

            // Configure proactive
            Services.AddSingleton <IBackgroundTaskQueue, BackgroundTaskQueue>();
            Services.AddHostedService <QueuedHostedService>();

            // Configure responses
            Services.AddSingleton(LocaleTemplateManagerWrapper.CreateLocaleTemplateManager("en-us"));
            Templates = LocaleTemplateManagerWrapper.CreateTemplates();

            // Configure service
            Services.AddSingleton <IServiceManager, MockServiceManager>();

            // Register dialogs
            Services.AddTransient <CreateTicketDialog>();
            Services.AddTransient <UpdateTicketDialog>();
            Services.AddTransient <ShowTicketDialog>();
            Services.AddTransient <CloseTicketDialog>();
            Services.AddTransient <ShowKnowledgeDialog>();
            Services.AddTransient <CreateSubscriptionDialog>();
            Services.AddTransient <MainDialog>();

            // Configure adapters
            Services.AddSingleton <TestAdapter, DefaultTestAdapter>();

            // Configure bot
            Services.AddTransient <IBot, DefaultActivityHandler <MainDialog> >();
        }
Exemplo n.º 6
0
        public void Initialize()
        {
            // Initialize service collection
            Services = new ServiceCollection();

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

            Services.AddSingleton(settings);
            Services.AddSingleton <BotSettingsBase>(settings);

            // Configure telemetry
            Services.AddSingleton <IBotTelemetryClient, NullBotTelemetryClient>();

            // Configure bot services
            Services.AddSingleton(new BotServices()
            {
                CognitiveModelSets = new Dictionary <string, CognitiveModelSet>
                {
                    {
                        "en-us", new CognitiveModelSet()
                        {
                            LuisServices = new Dictionary <string, LuisRecognizer>
                            {
                                {
                                    "General", new BaseMockLuisRecognizer <GeneralLuis>(
                                        new GeneralTestUtterances())
                                },
                                {
                                    "Hospitality", new BaseMockLuisRecognizer <HospitalityLuis>(
                                        new CheckOutUtterances(),
                                        new ExtendStayUtterances(),
                                        new GetReservationUtterances(),
                                        new LateCheckOutUtterances(),
                                        new RequestItemUtterances(),
                                        new RoomServiceUtterances())
                                }
                            }
                        }
                    }
                }
            });

            // Configure storage
            Services.AddSingleton <IStorage, MemoryStorage>();
            Services.AddSingleton <UserState>();
            Services.AddSingleton <ConversationState>();
            Services.AddSingleton(sp =>
            {
                var userState         = sp.GetService <UserState>();
                var conversationState = sp.GetService <ConversationState>();
                return(new BotStateSet(userState, conversationState));
            });

            // Configure proactive
            Services.AddSingleton <IBackgroundTaskQueue, BackgroundTaskQueue>();
            Services.AddHostedService <QueuedHostedService>();

            // Configure services
            Services.AddSingleton <IHotelService>(new HotelService(CheckInDate));

            // Configure responses
            Services.AddSingleton(LocaleTemplateManagerWrapper.CreateLocaleTemplateManager("en-us"));
            Templates = LocaleTemplateManagerWrapper.CreateTemplates();

            // Register dialogs
            Services.AddTransient <CheckOutDialog>();
            Services.AddTransient <LateCheckOutDialog>();
            Services.AddTransient <ExtendStayDialog>();
            Services.AddTransient <GetReservationDialog>();
            Services.AddTransient <RequestItemDialog>();
            Services.AddTransient <RoomServiceDialog>();
            Services.AddTransient <MainDialog>();

            // Configure adapters
            Services.AddSingleton <TestAdapter, DefaultTestAdapter>();

            // Configure bot
            Services.AddTransient <IBot, DefaultActivityHandler <MainDialog> >();
        }
Exemplo n.º 7
0
        public void Initialize()
        {
            // Initialize mock service manager
            ServiceManager = new FakeServiceManager();

            // Initialize service collection
            Services = new ServiceCollection();
            Services.AddSingleton(new BotSettings()
            {
                OAuthConnections = new List <OAuthConnection>()
                {
                    new OAuthConnection()
                    {
                        Name = Provider, Provider = Provider
                    }
                }
            });

            Services.AddSingleton(new BotServices()
            {
                CognitiveModelSets = new Dictionary <string, CognitiveModelSet>
                {
                    {
                        "en-us", new CognitiveModelSet()
                        {
                            LuisServices = new Dictionary <string, LuisRecognizer>
                            {
                                { "general", PhoneSkillMockLuisRecognizerFactory.CreateMockGeneralLuisRecognizer() },
                                { "phone", PhoneSkillMockLuisRecognizerFactory.CreateMockPhoneLuisRecognizer() },
                                { "contactSelection", PhoneSkillMockLuisRecognizerFactory.CreateMockContactSelectionLuisRecognizer() },
                                { "phoneNumberSelection", PhoneSkillMockLuisRecognizerFactory.CreateMockPhoneNumberSelectionLuisRecognizer() },
                            }
                        }
                    }
                }
            });

            Services.AddSingleton <IBotTelemetryClient, NullBotTelemetryClient>();
            Services.AddSingleton(new UserState(new MemoryStorage()));
            Services.AddSingleton(new ConversationState(new MemoryStorage()));
            Services.AddSingleton(new ProactiveState(new MemoryStorage()));
            Services.AddSingleton(sp =>
            {
                var userState         = sp.GetService <UserState>();
                var conversationState = sp.GetService <ConversationState>();
                var proactiveState    = sp.GetService <ProactiveState>();
                return(new BotStateSet(userState, conversationState));
            });

            // Configure localized responses
            TemplateManager = LocaleTemplateManagerWrapper.CreateLocaleTemplateManager("en-us");
            Services.AddSingleton(TemplateManager);
            Templates = LocaleTemplateManagerWrapper.CreateTemplates();

            Services.AddSingleton <IBackgroundTaskQueue, BackgroundTaskQueue>();
            Services.AddSingleton <IServiceManager>(ServiceManager);
            Services.AddSingleton <TestAdapter, DefaultTestAdapter>();
            Services.AddTransient <MainDialog>();
            Services.AddTransient <OutgoingCallDialog>();
            Services.AddTransient <IBot, DefaultActivityHandler <MainDialog> >();
        }