public void Construct()
        {
            var telemetryClient = new TelemetryClient();
            var client          = new BotTelemetryClient(telemetryClient);

            Assert.IsNotNull(client);
        }
        /// <summary>
        /// Adds and configures services for Application Insights to the <see cref="IServiceCollection" />.
        /// </summary>
        /// <param name="services">The <see cref="IServiceCollection"/> which specifies the contract for a collection of service descriptors.</param>
        /// <param name="config">Represents a set of key/value application configuration properties.</param>
        /// <returns>A reference to this instance after the operation has completed.</returns>
        public static IServiceCollection AddBotApplicationInsights(this IServiceCollection services, IConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            string instrumentationKey = config.GetValue <string>("ApplicationInsights:instrumentationKey");

            CreateBotTelemetry(services);

            IBotTelemetryClient telemetryClient = null;

            if (!string.IsNullOrWhiteSpace(instrumentationKey))
            {
                services.AddApplicationInsightsTelemetry(instrumentationKey);
                telemetryClient = new BotTelemetryClient(new TelemetryClient());
            }
            else
            {
                telemetryClient = NullBotTelemetryClient.Instance;
            }

            services.AddSingleton(telemetryClient);

            return(services);
        }
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_1);

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

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

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

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

            // Configure bot state
            services.AddSingleton <IStorage>(new CosmosDbStorage(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
            var telemetryClient = new BotTelemetryClient(new TelemetryClient(settings.AppInsights));

            services.AddSingleton <IBotTelemetryClient>(telemetryClient);
            services.AddBotApplicationInsights(telemetryClient);

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

            // Configure responses
            services.AddSingleton(sp => new ResponseManager(
                                      settings.CognitiveModels.Select(l => l.Key).ToArray(),
                                      new AutomotiveSkillMainResponses(),
                                      new AutomotiveSkillSharedResponses(),
                                      new VehicleSettingsResponses()));

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

            // Configure adapters
            services.AddTransient <IBotFrameworkHttpAdapter, DefaultAdapter>();
            services.AddTransient <SkillWebSocketBotAdapter, AutomotiveSkillWebSocketBotAdapter>();
            services.AddTransient <SkillWebSocketAdapter>();
            services.AddTransient <SkillHttpBotAdapter, AutomotiveSkillHttpBotAdapter>();
            services.AddTransient <SkillHttpAdapter>();

            // Configure bot
            services.AddTransient <MainDialog>();
            services.AddTransient <IBot, DialogBot <MainDialog> >();
        }
Beispiel #4
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_2);
            var provider = services.BuildServiceProvider();

            // 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
            services.AddSingleton <IStorage>(new CosmosDbStorage(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();
            var telemetryClient = new BotTelemetryClient(new TelemetryClient());

            services.AddSingleton <IBotTelemetryClient>(telemetryClient);
            services.AddBotApplicationInsights(telemetryClient);

            // 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>();

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

            // Configure adapters
            services.AddTransient <IBotFrameworkHttpAdapter, DefaultAdapter>();
            services.AddTransient <SkillWebSocketBotAdapter, NewsSkillWebSocketBotAdapter>();
            services.AddTransient <SkillWebSocketAdapter>();
            services.AddTransient <SkillHttpBotAdapter, NewsSkillHttpBotAdapter>();
            services.AddTransient <SkillHttpAdapter>();

            // Configure bot
            services.AddTransient <MainDialog>();
            services.AddTransient <IBot, DialogBot <MainDialog> >();
        }
Beispiel #5
0
        public void TrackTraceTest()
        {
            var telemetryClient = new TelemetryClient();
            var client          = new BotTelemetryClient(telemetryClient);
            var telemetry       = new TraceTelemetry();

            client.TrackTrace(telemetry);
        }
Beispiel #6
0
        public void TrackExceptionTest()
        {
            var telemetryClient = new TelemetryClient();
            var client          = new BotTelemetryClient(telemetryClient);
            var telemetry       = new ExceptionTelemetry();

            client.TrackException(telemetry);
        }
Beispiel #7
0
        public void TrackDependencyTest()
        {
            var telemetryClient = new TelemetryClient();
            var client          = new BotTelemetryClient(telemetryClient);
            var telemetry       = new DependencyTelemetry("my dependency", "my target", "foo", "data");

            client.TrackDependency(telemetry);
        }
Beispiel #8
0
        public void TrackEventTest()
        {
            var telemetryClient = new TelemetryClient();
            var client          = new BotTelemetryClient(telemetryClient);
            var eventTelemetry  = new EventTelemetry();

            client.TrackEvent(eventTelemetry);
        }
Beispiel #9
0
            public void TestInitialize()
            {
                _mockTelemetryChannel = new Mock <ITelemetryChannel>();

                var telemetryConfiguration = new TelemetryConfiguration("UNITTEST-INSTRUMENTATION-KEY", _mockTelemetryChannel.Object);
                var telemetryClient        = new TelemetryClient(telemetryConfiguration);

                _botTelemetryClient = new BotTelemetryClient(telemetryClient);
            }
        public void TrackDependencyTest()
        {
            // Just invoke underlying TelemetryClient.  Not configured, just tests if it can be invoked.
            // Class is sealed, so nothing to mock here.
            var telemetryClient = new TelemetryClient();
            var client          = new BotTelemetryClient(telemetryClient);

            client.TrackDependency("test", "target", "dependencyname", "data", DateTimeOffset.Now, new TimeSpan(10000), "result", false);
        }
        public void TrackTraceTest()
        {
            // Just invoke underlying TelemetryClient.  Not configured, just tests if it can be invoked.
            // Class is sealed, so nothing to mock here.
            var telemetryClient = new TelemetryClient();
            var client          = new BotTelemetryClient(telemetryClient);

            client.TrackTrace("hello", Severity.Critical, new Dictionary <string, string>()
            {
                { "foo", "bar" }
            });
        }
        public void TrackExceptionTest()
        {
            // Just invoke underlying TelemetryClient.  Not configured, just tests if it can be invoked.
            // Class is sealed, so nothing to mock here.
            var telemetryClient = new TelemetryClient();
            var client          = new BotTelemetryClient(telemetryClient);

            client.TrackException(new Exception(), new Dictionary <string, string>()
            {
                { "foo", "bar" }
            }, new Dictionary <string, double>()
            {
                { "metric", 0.6 }
            });
        }
        public void TrackAvailabilityTest()
        {
            // Just invoke underlying TelemetryClient.  Not configured, just tests if it can be invoked.
            // Class is sealed, so nothing to mock here.
            var telemetryClient = new TelemetryClient();
            var client          = new BotTelemetryClient(telemetryClient);

            client.TrackAvailability("test", DateTimeOffset.Now, new TimeSpan(1000), "run location", true,
                                     "message", new Dictionary <string, string>()
            {
                { "hello", "value" }
            }, new Dictionary <string, double>()
            {
                { "metric", 0.6 }
            });
        }
Beispiel #14
0
        /// <summary>
        /// Adds and configures services for Application Insights to the <see cref="IServiceCollection" />.
        /// </summary>
        /// <param name="services">The <see cref="IServiceCollection"/> which specifies the contract for a collection of service descriptors.</param>
        /// <param name="botConfiguration">Bot configuration that contains the Application Insights configuration information.</param>
        /// <param name="appInsightsServiceInstanceName">(OPTIONAL) Specifies a Application Insights instance name in the Bot configuration.</param>
        /// <returns>A reference to this instance after the operation has completed.</returns>
        public static IServiceCollection AddBotApplicationInsights(this IServiceCollection services, BotConfiguration botConfiguration, string appInsightsServiceInstanceName = null)
        {
            if (botConfiguration == null)
            {
                throw new ArgumentNullException(nameof(botConfiguration));
            }

            var appInsightsServices = botConfiguration.Services.OfType <AppInsightsService>();

            AppInsightsService appInsightService = null;

            // Validate the bot file is correct.
            var instanceNameSpecified = appInsightsServiceInstanceName != null;

            if (instanceNameSpecified)
            {
                appInsightService = appInsightsServices.Where(ais => ais.Name == appInsightsServiceInstanceName).FirstOrDefault();
                if (appInsightService == null)
                {
                    throw new ArgumentException($"No Application Insights Service instance with the specified name \"{appInsightsServiceInstanceName}\" was found in the {nameof(BotConfiguration)}");
                }
            }
            else
            {
                appInsightService = appInsightsServices.FirstOrDefault();
            }

            CreateBotTelemetry(services);

            IBotTelemetryClient telemetryClient = null;

            if (appInsightService != null)
            {
                services.AddApplicationInsightsTelemetry(appInsightService.InstrumentationKey);
                telemetryClient = new BotTelemetryClient(new TelemetryClient());
            }
            else
            {
                telemetryClient = NullBotTelemetryClient.Instance;
            }

            services.AddSingleton(telemetryClient);

            return(services);
        }
Beispiel #15
0
        public BotServices(BotSettings settings)
        {
            foreach (var pair in settings.CognitiveModels)
            {
                var set      = new CognitiveModelSet();
                var language = pair.Key;
                var config   = pair.Value;

                var telemetryClient = new BotTelemetryClient(new TelemetryClient(settings.AppInsights));
                var luisOptions     = new LuisPredictionOptions()
                {
                    TelemetryClient        = telemetryClient,
                    LogPersonalInformation = true,
                };

                var dispatchApp = new LuisApplication(config.DispatchModel.AppId, config.DispatchModel.SubscriptionKey, config.DispatchModel.GetEndpoint());

                set.DispatchService = new LuisRecognizer(dispatchApp, luisOptions);

                if (config.LanguageModels != null)
                {
                    foreach (var model in config.LanguageModels)
                    {
                        var luisApp = new LuisApplication(model.AppId, model.SubscriptionKey, model.GetEndpoint());
                        set.LuisServices.Add(model.Id, new LuisRecognizer(luisApp, luisOptions));
                    }
                }

                foreach (var kb in config.Knowledgebases)
                {
                    var qnaEndpoint = new QnAMakerEndpoint()
                    {
                        KnowledgeBaseId = kb.KbId,
                        EndpointKey     = kb.EndpointKey,
                        Host            = kb.Hostname,
                    };

                    var qnaMaker = new QnAMaker(qnaEndpoint, null, null, telemetryClient: telemetryClient, logPersonalInformation: true);
                    set.QnAServices.Add(kb.Id, qnaMaker);
                }

                CognitiveModelSets.Add(language, set);
            }
        }
Beispiel #16
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            var provider = services.BuildServiceProvider();

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

            Configuration.Bind(settings);
            services.AddSingleton(settings);

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

            var appCredentials = new MicrosoftAppCredentials(settings.MicrosoftAppId, settings.MicrosoftAppPassword);

            services.AddSingleton(appCredentials);

            // Configure telemetry
            services.AddApplicationInsightsTelemetry();
            var telemetryClient = new BotTelemetryClient(new TelemetryClient());

            services.AddSingleton <IBotTelemetryClient>(telemetryClient);
            services.AddBotApplicationInsights(telemetryClient);

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

            // Configure storage
            services.AddSingleton <IStorage>(new CosmosDbStorage(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));
            });

            // Register dialogs
            services.AddTransient <CancelDialog>();
            services.AddTransient <EscalateDialog>();
            services.AddTransient <MainDialog>();
            services.AddTransient <OnboardingDialog>();

            // Register skill dialogs
            services.AddTransient(sp =>
            {
                var userState    = sp.GetService <UserState>();
                var skillDialogs = new List <SkillDialog>();

                foreach (var skill in settings.Skills)
                {
                    var authDialog  = BuildAuthDialog(skill, settings, appCredentials);
                    var credentials = new MicrosoftAppCredentialsEx(settings.MicrosoftAppId, settings.MicrosoftAppPassword, skill.MSAappId);
                    skillDialogs.Add(new SkillDialog(skill, credentials, telemetryClient, userState, authDialog));
                }

                return(skillDialogs);
            });

            // Configure adapters
            // DefaultAdapter is for all regular channels that use Http transport
            services.AddSingleton <IBotFrameworkHttpAdapter, DefaultAdapter>();

            // DefaultWebSocketAdapter is for directline speech channel
            // This adapter implementation is currently a workaround as
            // later on we'll have a WebSocketEnabledHttpAdapter implementation that handles
            // both Http for regular channels and websocket for directline speech channel
            services.AddSingleton <WebSocketEnabledHttpAdapter, DefaultWebSocketAdapter>();

            // Configure bot
            services.AddTransient <IBot, DialogBot <MainDialog> >();
        }
Beispiel #17
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            var provider = services.BuildServiceProvider();

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

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

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

            // Configure storage
            services.AddSingleton <IStorage>(new CosmosDbStorage(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();
            var telemetryClient = new BotTelemetryClient(new TelemetryClient());

            services.AddSingleton <IBotTelemetryClient>(telemetryClient);
            services.AddBotApplicationInsights(telemetryClient);

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

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

            // Configure responses
            services.AddSingleton(sp => new ResponseManager(
                                      settings.CognitiveModels.Select(l => l.Key).ToArray(),
                                      new MainResponses(),
                                      new SharedResponses(),
                                      new SampleResponses()));

            // Register dialogs
            services.AddTransient <SampleDialog>();
            services.AddTransient <MainDialog>();

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

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

            // Register WhiteListAuthProvider
            services.AddSingleton <IWhitelistAuthenticationProvider, WhitelistAuthenticationProvider>();

            // Configure bot
            services.AddTransient <MainDialog>();
            services.AddTransient <IBot, DialogBot <MainDialog> >();
        }
Beispiel #18
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_2);
            var provider = services.BuildServiceProvider();

            // 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
            services.AddSingleton <IStorage>(new CosmosDbStorage(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();
            var telemetryClient = new BotTelemetryClient(new TelemetryClient());

            services.AddSingleton <IBotTelemetryClient>(telemetryClient);
            services.AddBotApplicationInsights(telemetryClient);

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

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

            // Configure service manager
            services.AddTransient <IServiceManager, ServiceManager>();

            // Configure responses
            services.AddSingleton(sp => new ResponseManager(
                                      settings.CognitiveModels.Select(l => l.Key).ToArray(),
                                      new FindContactResponses(),
                                      new DeleteEmailResponses(),
                                      new ForwardEmailResponses(),
                                      new EmailMainResponses(),
                                      new ReplyEmailResponses(),
                                      new SendEmailResponses(),
                                      new EmailSharedResponses(),
                                      new ShowEmailResponses()));

            // register dialogs
            services.AddTransient <MainDialog>();
            services.AddTransient <DeleteEmailDialog>();
            services.AddTransient <FindContactDialog>();
            services.AddTransient <ForwardEmailDialog>();
            services.AddTransient <ReplyEmailDialog>();
            services.AddTransient <SendEmailDialog>();
            services.AddTransient <ShowEmailDialog>();

            // Configure adapters
            services.AddTransient <IBotFrameworkHttpAdapter, DefaultAdapter>();
            services.AddTransient <SkillWebSocketBotAdapter, EmailSkillWebSocketBotAdapter>();
            services.AddTransient <SkillWebSocketAdapter>();
            services.AddTransient <SkillHttpBotAdapter, EmailSkillHttpBotAdapter>();
            services.AddTransient <SkillHttpAdapter>();

            // Configure bot
            services.AddTransient <MainDialog>();
            services.AddTransient <IBot, DialogBot <MainDialog> >();
        }
Beispiel #19
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

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

            // Create the credential provider to be used with the Bot Framework Adapter.
            services.AddSingleton <ICredentialProvider, ConfigurationCredentialProvider>();

            services.AddSingleton <InspectionMiddleware>();

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

            Configuration.Bind(settings);

            IStorage storage = null;

            // Configure storage for deployment
            if (!string.IsNullOrEmpty(settings.CosmosDb.AuthKey))
            {
                storage = new CosmosDbStorage(settings.CosmosDb);
            }
            else
            {
                Console.WriteLine("The settings of CosmosDbStorage is incomplete, please check following settings: settings.CosmosDb");
                storage = new MemoryStorage();
            }

            services.AddSingleton(storage);
            var userState         = new UserState(storage);
            var conversationState = new ConversationState(storage);
            var inspectionState   = new InspectionState(storage);

            // Configure telemetry
            services.AddApplicationInsightsTelemetry();
            var telemetryClient = new BotTelemetryClient(new TelemetryClient());

            services.AddSingleton <IBotTelemetryClient>(telemetryClient);
            services.AddBotApplicationInsights(telemetryClient);

            var botFile = Configuration.GetSection("bot").Get <string>();

            TypeFactory.Configuration = this.Configuration;

            // manage all bot resources
            var resourceExplorer = new ResourceExplorer().AddFolder(botFile);

            var credentials = new MicrosoftAppCredentials(this.Configuration["MicrosoftAppId"], this.Configuration["MicrosoftAppPassword"]);

            services.AddSingleton <IBotFrameworkHttpAdapter, BotFrameworkHttpAdapter>((s) =>
            {
                var adapter = new BotFrameworkHttpAdapter(new ConfigurationCredentialProvider(this.Configuration));
                adapter
                .UseStorage(storage)
                .UseState(userState, conversationState)
                .UseAdaptiveDialogs()
                .UseResourceExplorer(resourceExplorer)
                .UseLanguageGeneration(resourceExplorer, "common.lg")
                .Use(new RegisterClassMiddleware <IConfiguration>(Configuration))
                .Use(new InspectionMiddleware(inspectionState, userState, conversationState, credentials));

                if (!string.IsNullOrEmpty(settings.BlobStorage.ConnectionString) && !string.IsNullOrEmpty(settings.BlobStorage.Container))
                {
                    adapter.Use(new TranscriptLoggerMiddleware(new AzureBlobTranscriptStore(settings.BlobStorage.ConnectionString, settings.BlobStorage.Container)));
                }
                else
                {
                    Console.WriteLine("The settings of TranscriptLoggerMiddleware is incomplete, please check following settings: settings.BlobStorage.ConnectionString, settings.BlobStorage.Container");
                }

                adapter.OnTurnError = async(turnContext, exception) =>
                {
                    await turnContext.SendActivityAsync(exception.Message).ConfigureAwait(false);
                    telemetryClient.TrackException(new Exception("Exceptions: " + exception.Message));
                    await conversationState.ClearStateAsync(turnContext).ConfigureAwait(false);
                    await conversationState.SaveChangesAsync(turnContext).ConfigureAwait(false);
                };
                return(adapter);
            });

            services.AddSingleton <IBot, ComposerBot>((sp) => new ComposerBot("Main.dialog", conversationState, userState, resourceExplorer, DebugSupport.SourceMap, telemetryClient));
        }
Beispiel #20
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_1);

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

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

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

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

            // Configure bot state
            services.AddSingleton <IStorage>(new CosmosDbStorage(settings.CosmosDb));
            services.AddSingleton <UserState>();
            services.AddSingleton <ConversationState>();
            services.AddSingleton <ProactiveState>();
            services.AddSingleton(sp =>
            {
                var userState         = sp.GetService <UserState>();
                var conversationState = sp.GetService <ConversationState>();
                var proactiveState    = sp.GetService <ProactiveState>();
                return(new BotStateSet(userState, conversationState, proactiveState));
            });

            // Configure telemetry
            var telemetryClient = new BotTelemetryClient(new TelemetryClient(settings.AppInsights));

            services.AddSingleton <IBotTelemetryClient>(telemetryClient);
            services.AddBotApplicationInsights(telemetryClient);

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

            // Configure service manager
            services.AddTransient <IServiceManager, ServiceManager>();

            // Configure responses
            services.AddSingleton(sp => new ResponseManager(
                                      settings.CognitiveModels.Select(l => l.Key).ToArray(),
                                      new FindContactResponses(),
                                      new ChangeEventStatusResponses(),
                                      new CreateEventResponses(),
                                      new JoinEventResponses(),
                                      new CalendarMainResponses(),
                                      new CalendarSharedResponses(),
                                      new SummaryResponses(),
                                      new TimeRemainingResponses(),
                                      new UpdateEventResponses()));

            // register dialogs
            services.AddTransient <MainDialog>();
            services.AddTransient <ChangeEventStatusDialog>();
            services.AddTransient <ConnectToMeetingDialog>();
            services.AddTransient <CreateEventDialog>();
            services.AddTransient <FindContactDialog>();
            services.AddTransient <SummaryDialog>();
            services.AddTransient <TimeRemainingDialog>();
            services.AddTransient <UpcomingEventDialog>();
            services.AddTransient <UpdateEventDialog>();
            services.AddTransient <FindContactDialog>();

            // Configure adapters
            services.AddTransient <IBotFrameworkHttpAdapter, DefaultAdapter>();
            services.AddTransient <SkillWebSocketBotAdapter, CalendarSkillWebSocketBotAdapter>();
            services.AddTransient <SkillWebSocketAdapter>();
            services.AddTransient <SkillHttpBotAdapter, CalendarSkillHttpBotAdapter>();
            services.AddTransient <SkillHttpAdapter>();

            // Configure bot
            services.AddTransient <IBot, DialogBot <MainDialog> >();
        }
Beispiel #21
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();

            // 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 credentials
            services.AddSingleton <ICredentialProvider, ConfigurationCredentialProvider>();
            services.AddSingleton(new MicrosoftAppCredentials(settings.MicrosoftAppId, settings.MicrosoftAppPassword));

            // Configure storage
            services.AddSingleton <IStorage>(new CosmosDbStorage(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();
            var telemetryClient = new BotTelemetryClient(new TelemetryClient());

            services.AddSingleton <IBotTelemetryClient>(telemetryClient);
            services.AddBotApplicationInsights(telemetryClient);

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

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

            // Configure responses
            services.AddSingleton(sp => new ResponseManager(
                                      settings.CognitiveModels.Select(l => l.Key).ToArray(),
                                      new MainResponses(),
                                      new SharedResponses()));

            // Register dialogs
            services.AddTransient <MainDialog>();

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

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

            // Configure bot
            services.AddTransient <MainDialog>();
            services.AddTransient <IBot, DialogBot <MainDialog> >();
        }
Beispiel #22
0
            public void NonNullTelemtryClientSucceeds()
            {
                var telemetryClient = new TelemetryClient();

                var botTelemetryClient = new BotTelemetryClient(telemetryClient);
            }
Beispiel #23
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            var provider = services.BuildServiceProvider();

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

            Configuration.Bind(settings);
            services.AddSingleton(settings);

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

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

            // Configure telemetry
            var telemetryClient = new BotTelemetryClient(new TelemetryClient(settings.AppInsights));

            services.AddSingleton <IBotTelemetryClient>(telemetryClient);
            services.AddBotApplicationInsights(telemetryClient);

            // Configure storage
            services.AddSingleton <IStorage>(new CosmosDbStorage(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));
            });

            // Register dialogs
            services.AddTransient <CancelDialog>();
            services.AddTransient <EscalateDialog>();
            services.AddTransient <MainDialog>();
            services.AddTransient <OnboardingDialog>();

            // Register skill dialogs
            services.AddTransient(sp =>
            {
                var userState    = sp.GetService <UserState>();
                var skillDialogs = new List <SkillDialog>();

                foreach (var skill in settings.Skills)
                {
                    var authDialog  = BuildAuthDialog(skill, settings);
                    var credentials = new MicrosoftAppCredentialsEx(settings.MicrosoftAppId, settings.MicrosoftAppPassword, skill.MSAappId);
                    skillDialogs.Add(new SkillDialog(skill, credentials, telemetryClient, userState, authDialog));
                }

                return(skillDialogs);
            });

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

            // Configure bot
            services.AddTransient <IBot, DialogBot <MainDialog> >();
        }
Beispiel #24
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 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(settings);
            services.AddSingleton <BotSettingsBase>(settings);

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

            // Configure storage
            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();
            var telemetryClient = new BotTelemetryClient(new TelemetryClient());

            services.AddSingleton <IBotTelemetryClient>(telemetryClient);
            services.AddBotApplicationInsights(telemetryClient);

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

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

            // Configure service manager
            services.AddTransient <IServiceManager, ServiceManager>();

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

            // Register dialogs
            services.AddTransient <MainDialog>();
            services.AddTransient <ForecastDialog>();

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

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

            // Configure bot
            services.AddTransient <MainDialog>();
            services.AddTransient <IBot, DefaultActivityHandler <MainDialog> >();
        }
Beispiel #25
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_2);

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

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

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

            // Configure bot state
            services.AddSingleton <IStorage>(new CosmosDbStorage(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();
            var telemetryClient = new BotTelemetryClient(new TelemetryClient());

            services.AddSingleton <IBotTelemetryClient>(telemetryClient);
            services.AddBotApplicationInsights(telemetryClient);

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

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

            // Configure service manager
            services.AddTransient <IServiceManager, ServiceManager>();

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

            // Configure responses
            services.AddSingleton(sp => new ResponseManager(
                                      settings.CognitiveModels.Select(l => l.Key).ToArray(),
                                      new CancelRouteResponses(),
                                      new FindPointOfInterestResponses(),
                                      new POIMainResponses(),
                                      new RouteResponses(),
                                      new POISharedResponses()));

            // register dialogs
            services.AddTransient <MainDialog>();
            services.AddTransient <CancelRouteDialog>();
            services.AddTransient <FindParkingDialog>();
            services.AddTransient <FindPointOfInterestDialog>();
            services.AddTransient <RouteDialog>();

            // Configure adapters
            services.AddTransient <IBotFrameworkHttpAdapter, DefaultAdapter>();
            services.AddTransient <SkillWebSocketBotAdapter, POISkillWebSocketBotAdapter>();
            services.AddTransient <SkillWebSocketAdapter>();
            services.AddTransient <SkillHttpBotAdapter, POISkillHttpBotAdapter>();
            services.AddTransient <SkillHttpAdapter>();

            // Configure bot
            services.AddTransient <MainDialog>();
            services.AddTransient <IBot, DialogBot <MainDialog> >();
        }