/// <summary> /// Initializes a new instance of the <see cref="BotServices"/> class. /// <param name="botConfiguration">A dictionary of named <see cref="BotConfiguration"/> instances for usage within the bot.</param> /// </summary> public BotServices(BotConfiguration botConfiguration) { foreach (var service in botConfiguration.Services) { switch (service.Type) { case ServiceTypes.Luis: { var luis = (LuisService)service; EnsureNotNull(luis, ServiceTypes.Luis); var app = new LuisApplication(luis.AppId, luis.AuthoringKey, luis.GetEndpoint()); var recognizer = new LuisRecognizer(app); LuisServices.Add(luis.Name, recognizer); break; } case ServiceTypes.Endpoint: { var endPoint = (EndpointService)service; EnsureNotNull(endPoint, ServiceTypes.Endpoint); EndpointServices.Add(endPoint.Name, endPoint); break; } } } if (EndpointServices.Count == 0) { throw new InvalidOperationException($"The .bot file does not contain an endpoint."); } }
/// <summary> /// Initializes a new instance of the <see cref="BotServices"/> class. /// </summary> /// <param name="botConfiguration">The <see cref="BotConfiguration"/> instance for the bot.</param> public BotServices(BotConfiguration botConfiguration) { foreach (var service in botConfiguration.Services) { switch (service.Type) { case ServiceTypes.AppInsights: { var appInsights = service as AppInsightsService; TelemetryClient = new TelemetryClient(); break; } case ServiceTypes.Dispatch: { var dispatch = service as DispatchService; var dispatchApp = new LuisApplication(dispatch.AppId, dispatch.SubscriptionKey, dispatch.GetEndpoint()); DispatchRecognizer = new TelemetryLuisRecognizer(dispatchApp); break; } case ServiceTypes.Luis: { var luis = service as LuisService; var luisApp = new LuisApplication(luis.AppId, luis.SubscriptionKey, luis.GetEndpoint()); LuisServices.Add(service.Name, new TelemetryLuisRecognizer(luisApp)); break; } case ServiceTypes.QnA: { var qna = service as QnAMakerService; var qnaEndpoint = new QnAMakerEndpoint() { KnowledgeBaseId = qna.KbId, EndpointKey = qna.EndpointKey, Host = qna.Hostname, }; var qnaMaker = new TelemetryQnAMaker(qnaEndpoint); QnAServices.Add(qna.Name, qnaMaker); break; } case ServiceTypes.Generic: { if (service.Name == "Authentication") { var authentication = service as GenericService; if (!string.IsNullOrEmpty(authentication.Configuration["Azure Active Directory v2"])) { AuthConnectionName = authentication.Configuration["Azure Active Directory v2"]; } } break; } } } }
public BotServices(BotConfiguration botConfiguration) { foreach (var service in botConfiguration.Services) { switch (service.Type) { case ServiceTypes.Luis: { var luis = (LuisService)service; if (luis == null) { throw new InvalidOperationException("The LUIS service is not configured correctly in your '.bot' file."); } var app = new LuisApplication(luis.AppId, luis.AuthoringKey, luis.GetEndpoint()); var recognizer = new LuisRecognizer(app); LuisServices.Add(luis.Name, recognizer); break; } case ServiceTypes.QnA: { // Create a QnA Maker that is initialized and suitable for passing // into the IBot-derived class (QnABot). var qna = (QnAMakerService)service; if (qna == null) { throw new InvalidOperationException("The QnA service is not configured correctly in your '.bot' file."); } if (string.IsNullOrWhiteSpace(qna.KbId)) { throw new InvalidOperationException("The QnA KnowledgeBaseId ('kbId') is required to run this sample. Please update your '.bot' file."); } if (string.IsNullOrWhiteSpace(qna.EndpointKey)) { throw new InvalidOperationException("The QnA EndpointKey ('endpointKey') is required to run this sample. Please update your '.bot' file."); } if (string.IsNullOrWhiteSpace(qna.Hostname)) { throw new InvalidOperationException("The QnA Host ('hostname') is required to run this sample. Please update your '.bot' file."); } var qnaEndpoint = new QnAMakerEndpoint() { KnowledgeBaseId = qna.KbId, EndpointKey = qna.EndpointKey, Host = qna.Hostname, }; var qnaMaker = new QnAMaker(qnaEndpoint); QnaServices.Add(qna.Name, qnaMaker); break; } } } }
public SkillConfiguration(BotConfiguration botConfiguration, string[] parameters, Dictionary <string, object> configuration) { foreach (var service in botConfiguration.Services) { switch (service.Type) { case ServiceTypes.AppInsights: { var appInsights = service as AppInsightsService; var telemetryConfig = new TelemetryConfiguration(appInsights.InstrumentationKey); TelemetryClient = new TelemetryClient(telemetryConfig); break; } case ServiceTypes.Luis: { var luis = service as LuisService; var luisApp = new LuisApplication(luis.AppId, luis.SubscriptionKey, luis.GetEndpoint()); LuisServices.Add(service.Id, new LuisRecognizer(luisApp)); break; } case ServiceTypes.Generic: { if (service.Name == "Authentication") { var authentication = service as GenericService; if (!string.IsNullOrEmpty(authentication.Configuration["Azure Active Directory v2"])) { AuthConnectionName = authentication.Configuration["Azure Active Directory v2"]; } } break; } } } if (parameters != null) { // add the parameters the skill needs foreach (var parameter in parameters) { // Initialize each parameter to null. Needs to be set later by the bot. Properties.Add(parameter, null); } } if (configuration != null) { // add the additional keys the skill needs foreach (var set in configuration) { Properties.Add(set.Key, set.Value); } } }
/// <summary> /// Initializes a new instance of the <see cref="BotServices"/> class. /// <param name="botConfiguration">A dictionary of named <see cref="BotConfiguration"/> instances for usage within the bot.</param> /// </summary> public BotServices(IOptions <LuisConfig> config) { LuisConfig = config.Value; foreach (var luisApplication in LuisConfig.LuisApplications) { var app = new LuisApplication(luisApplication.AppId, LuisConfig.ApiKey, LuisConfig.Hostname); var recognizer = new LuisRecognizer(app); LuisServices.Add(luisApplication.Name, recognizer); } }
public BotServices(BotConfiguration botConfiguration) { foreach (var service in botConfiguration.Services) { switch (service.Type) { case ServiceTypes.Luis: { var luis = (LuisService)service; var app = new LuisApplication(luis.AppId, luis.AuthoringKey, luis.GetEndpoint()); var recognizer = new LuisRecognizer(app); LuisServices.Add(luis.Name, recognizer); break; } } } }
public BotServices(BotConfiguration botConfiguration) { foreach (var service in botConfiguration.Services) { switch (service.Type) { case ServiceTypes.Luis: { var luis = (LuisService)service ?? throw new InvalidOperationException("The LUIS service is not configured correctly in your '.bot' file."); var app = new LuisApplication(luis.AppId, luis.AuthoringKey, luis.GetEndpoint()); var recognizer = new LuisRecognizer(app); LuisServices.Add(luis.Name, recognizer); break; } case ServiceTypes.QnA: { var qna = (QnAMakerService)service ?? throw new InvalidOperationException("The Qna service is not configured correctly in your '.bot' file."); var qnaMaker = new QnAMaker( new QnAMakerEndpoint { EndpointKey = qna.EndpointKey, Host = qna.Hostname, KnowledgeBaseId = qna.KbId }, new QnAMakerOptions { Top = 1, ScoreThreshold = 0.5f }); QnAServices.Add(qna.Name, qnaMaker); break; } } } }
/// <summary> /// Initializes a new instance of the <see cref="BotServices"/> class. /// </summary> /// <param name="luisServices">A dictionary of named <see cref="LuisRecognizer"/> instances for usage within the bot.</param> public BotServices(BotConfiguration botConfiguration) { foreach (var service in botConfiguration.Services) { switch (service.Type) { case ServiceTypes.Luis: { var luis = (LuisService)service; if (luis == null) { throw new InvalidOperationException("The LUIS service is not configured correctly in your '.bot' file."); } var app = new LuisApplication(luis.AppId, luis.AuthoringKey, luis.GetEndpoint()); var recognizer = new LuisRecognizer(app); LuisServices.Add(luis.Name, recognizer); break; } } } }
/// <summary> /// Initializes a new instance of the <see cref="BotServices"/> class. /// </summary> /// <param name="botConfiguration">The <see cref="BotConfiguration"/> instance for the bot.</param> public BotServices(BotConfiguration botConfiguration, List <SkillDefinition> skills) { foreach (var service in botConfiguration.Services) { switch (service.Type) { case ServiceTypes.AppInsights: { var appInsights = service as AppInsightsService; var telemetryConfig = new TelemetryConfiguration(appInsights.InstrumentationKey); TelemetryClient = new TelemetryClient(telemetryConfig); break; } case ServiceTypes.Dispatch: { var dispatch = service as DispatchService; var dispatchApp = new LuisApplication(dispatch.AppId, dispatch.SubscriptionKey, dispatch.GetEndpoint()); DispatchRecognizer = new TelemetryLuisRecognizer(dispatchApp); break; } case ServiceTypes.Luis: { var luis = service as LuisService; var luisApp = new LuisApplication(luis.AppId, luis.SubscriptionKey, luis.GetEndpoint()); LuisServices.Add(service.Id, new TelemetryLuisRecognizer(luisApp)); break; } case ServiceTypes.QnA: { var qna = service as QnAMakerService; var qnaEndpoint = new QnAMakerEndpoint() { KnowledgeBaseId = qna.KbId, EndpointKey = qna.EndpointKey, Host = qna.Hostname, }; var qnaMaker = new TelemetryQnAMaker(qnaEndpoint); QnAServices.Add(qna.Id, qnaMaker); break; } case ServiceTypes.Generic: { if (service.Name == "Authentication") { var authentication = service as GenericService; AuthenticationConnections = authentication.Configuration; } break; } case ServiceTypes.CosmosDB: { var cosmos = service as CosmosDbService; CosmosDbOptions = new CosmosDbStorageOptions { AuthKey = cosmos.Key, CollectionId = cosmos.Collection, DatabaseId = cosmos.Database, CosmosDBEndpoint = new Uri(cosmos.Endpoint), }; break; } } } foreach (var skill in skills) { var skillConfig = new SkillConfiguration() { CosmosDbOptions = CosmosDbOptions, TelemetryClient = TelemetryClient, LuisServices = LuisServices.Where(l => skill.LuisServiceIds.Contains(l.Key) == true).ToDictionary(l => l.Key, l => l.Value as IRecognizer), }; if (skill.SupportedProviders != null) { foreach (var provider in skill.SupportedProviders) { var matches = AuthenticationConnections.Where(x => x.Value == provider); foreach (var match in matches) { skillConfig.AuthenticationConnections.Add(match.Key, match.Value); } } } foreach (var set in skill.Configuration) { skillConfig.Properties.Add(set.Key, set.Value); } SkillDefinitions.Add(skill); SkillConfigurations.Add(skill.Id, skillConfig); } }
/// <summary> /// Initializes a new instance of the <see cref="BotServices"/> class. /// </summary> /// <param name="botConfiguration">The <see cref="BotConfiguration"/> instance for the bot.</param> public BotServices(BotConfiguration botConfiguration) { foreach (var service in botConfiguration.Services) { switch (service.Type) { case ServiceTypes.AppInsights: { var appInsights = (AppInsightsService)service; if (appInsights == null) { throw new InvalidOperationException("The Application Insights is not configured correctly in your '.bot' file."); } if (string.IsNullOrWhiteSpace(appInsights.InstrumentationKey)) { throw new InvalidOperationException("The Application Insights Instrumentation Key ('instrumentationKey') is required to run this sample. Please update your '.bot' file."); } var telemetryConfig = new TelemetryConfiguration(appInsights.InstrumentationKey); TelemetryClient = new TelemetryClient(telemetryConfig) { InstrumentationKey = appInsights.InstrumentationKey, }; break; } case ServiceTypes.Dispatch: { var dispatch = service as DispatchService; if (dispatch == null) { throw new InvalidOperationException("The Dispatch service is not configured correctly in your '.bot' file."); } if (string.IsNullOrWhiteSpace(dispatch.AppId)) { throw new InvalidOperationException("The Dispatch Luis Model Application Id ('appId') is required to run this sample. Please update your '.bot' file."); } if (string.IsNullOrWhiteSpace(dispatch.SubscriptionKey)) { throw new InvalidOperationException("The Subscription Key ('subscriptionKey') is required to run this sample. Please update your '.bot' file."); } var dispatchApp = new LuisApplication(dispatch.AppId, dispatch.SubscriptionKey, dispatch.GetEndpoint()); DispatchRecognizer = new TelemetryLuisRecognizer(dispatchApp); break; } case ServiceTypes.Luis: { var luis = service as LuisService; if (luis == null) { throw new InvalidOperationException("The Luis service is not configured correctly in your '.bot' file."); } if (string.IsNullOrWhiteSpace(luis.AppId)) { throw new InvalidOperationException("The Luis Model Application Id ('appId') is required to run this sample. Please update your '.bot' file."); } if (string.IsNullOrWhiteSpace(luis.AuthoringKey)) { throw new InvalidOperationException("The Luis Authoring Key ('authoringKey') is required to run this sample. Please update your '.bot' file."); } if (string.IsNullOrWhiteSpace(luis.SubscriptionKey)) { throw new InvalidOperationException("The Subscription Key ('subscriptionKey') is required to run this sample. Please update your '.bot' file."); } if (string.IsNullOrWhiteSpace(luis.Region)) { throw new InvalidOperationException("The Region ('region') is required to run this sample. Please update your '.bot' file."); } var luisApp = new LuisApplication(luis.AppId, luis.SubscriptionKey, luis.GetEndpoint()); var recognizer = new TelemetryLuisRecognizer(luisApp); LuisServices.Add(service.Id, recognizer); break; } case ServiceTypes.QnA: { var qna = service as QnAMakerService; var qnaEndpoint = new QnAMakerEndpoint() { KnowledgeBaseId = qna.KbId, EndpointKey = qna.EndpointKey, Host = qna.Hostname, }; var qnaMaker = new TelemetryQnAMaker(qnaEndpoint); QnAServices.Add(qna.Id, qnaMaker); break; } case ServiceTypes.Generic: { if (service.Name == "Authentication") { var authentication = service as GenericService; if (!string.IsNullOrEmpty(authentication.Configuration["Azure Active Directory v2"])) { AuthConnectionName = authentication.Configuration["Azure Active Directory v2"]; } } break; } } } }
/// <summary> /// Initializes a new instance of the <see cref="BotServices"/> class. /// </summary> /// <param name="botConfiguration">A dictionary of named <see cref="LuisRecognizer"/> instances for usage within the bot.</param> public BotServices(BotConfiguration botConfiguration) { foreach (var service in botConfiguration.Services) { switch (service.Type) { case ServiceTypes.Luis: { var luis = (LuisService)service; if (luis == null) { throw new InvalidOperationException("The LUIS service is not configured correctly in your '.bot' file."); } var app = new LuisApplication(luis.AppId, luis.SubscriptionKey, luis.GetEndpoint()); // Specify LUIS options. These may vary for your bot. var luisPredictionOptions = new LuisPredictionOptions { IncludeAllIntents = true, }; var recognizer = new LuisRecognizer(app, luisPredictionOptions, true); LuisServices.Add(luis.Name, recognizer); break; } //case ServiceTypes.QnA: // { // // Create a QnA Maker that is initialized and suitable for passing // // into the IBot-derived class (QnABot). // var qna = (QnAMakerService)service; // if (qna == null) // { // throw new InvalidOperationException("The QnA service is not configured correctly in your '.bot' file."); // } // if (string.IsNullOrWhiteSpace(qna.KbId)) // { // throw new InvalidOperationException("The QnA KnowledgeBaseId ('kbId') is required to run this sample. Please update your '.bot' file."); // } // if (string.IsNullOrWhiteSpace(qna.EndpointKey)) // { // throw new InvalidOperationException("The QnA EndpointKey ('endpointKey') is required to run this sample. Please update your '.bot' file."); // } // if (string.IsNullOrWhiteSpace(qna.Hostname)) // { // throw new InvalidOperationException("The QnA Host ('hostname') is required to run this sample. Please update your '.bot' file."); // } // var qnaEndpoint = new QnAMakerEndpoint() // { // KnowledgeBaseId = qna.KbId, // EndpointKey = qna.EndpointKey, // Host = qna.Hostname, // }; // var qnaMaker = new QnAMaker(qnaEndpoint); // QnaServices.Add(qna.Name, qnaMaker); // break; // } } } }
/// <summary> /// Initializes a new instance of the <see cref="BotServices"/> class. /// </summary> /// <param name="botConfiguration">The <see cref="BotConfiguration"/> instance for the bot.</param> public BotServices(BotConfiguration botConfiguration) { foreach (var service in botConfiguration.Services) { switch (service.Type) { case ServiceTypes.Dispatch: { var dispatch = service as DispatchService; if (dispatch == null) { throw new InvalidOperationException("The Dispatch service is not configured correctly in your '.bot' file."); } if (string.IsNullOrWhiteSpace(dispatch.AppId)) { throw new InvalidOperationException("The Dispatch Luis Model Application Id ('appId') is required to run this sample. Please update your '.bot' file."); } if (string.IsNullOrWhiteSpace(dispatch.SubscriptionKey)) { throw new InvalidOperationException("The Subscription Key ('subscriptionKey') is required to run this sample. Please update your '.bot' file."); } var dispatchApp = new LuisApplication(dispatch.AppId, dispatch.SubscriptionKey, dispatch.GetEndpoint()); DispatchRecognizer = new TelemetryLuisRecognizer(dispatchApp); break; } case ServiceTypes.Luis: { var luis = service as LuisService; if (luis == null) { throw new InvalidOperationException("The Luis service is not configured correctly in your '.bot' file."); } if (string.IsNullOrWhiteSpace(luis.AppId)) { throw new InvalidOperationException("The Luis Model Application Id ('appId') is required to run this sample. Please update your '.bot' file."); } if (string.IsNullOrWhiteSpace(luis.AuthoringKey)) { throw new InvalidOperationException("The Luis Authoring Key ('authoringKey') is required to run this sample. Please update your '.bot' file."); } if (string.IsNullOrWhiteSpace(luis.SubscriptionKey)) { throw new InvalidOperationException("The Subscription Key ('subscriptionKey') is required to run this sample. Please update your '.bot' file."); } if (string.IsNullOrWhiteSpace(luis.Region)) { throw new InvalidOperationException("The Region ('region') is required to run this sample. Please update your '.bot' file."); } var luisApp = new LuisApplication(luis.AppId, luis.SubscriptionKey, luis.GetEndpoint()); var recognizer = new TelemetryLuisRecognizer(luisApp); LuisServices.Add(service.Id, recognizer); break; } case ServiceTypes.QnA: { var qna = service as QnAMakerService; var qnaEndpoint = new QnAMakerEndpoint() { KnowledgeBaseId = qna.KbId, EndpointKey = qna.EndpointKey, Host = qna.Hostname, }; var qnaMaker = new TelemetryQnAMaker(qnaEndpoint); QnAServices.Add(qna.Id, qnaMaker); break; } } } }
/// <summary> /// Initializes a new instance of the <see cref="BotServices"/> class. /// </summary> /// <param name="botConfiguration">Parsed .bot configuration file.</param> public BotServices(BotConfiguration botConfiguration) { foreach (var service in botConfiguration.Services) { switch (service.Type) { case ServiceTypes.Endpoint: { var endpoint = (EndpointService)service; EndpointServices.Add(endpoint.Name, endpoint); break; } case ServiceTypes.BlobStorage: { // Create a Storage client. var storage = (BlobStorageService)service; if (string.IsNullOrWhiteSpace(storage.ConnectionString)) { throw new InvalidOperationException("The Storage ConnectionString ('connectionString') is required. Please update your '.bot' file."); } var storageAccount = CloudStorageAccount.Parse(storage.ConnectionString); StorageServices.Add(storage.Name, storageAccount); break; } case ServiceTypes.QnA: { // Create a QnA Maker that is initialized and suitable for passing // into the IBot-derived class (QnABot). var qna = (QnAMakerService)service; if (string.IsNullOrWhiteSpace(qna.KbId)) { throw new InvalidOperationException("The QnA KnowledgeBaseId ('kbId') is required. Please update your '.bot' file."); } if (string.IsNullOrWhiteSpace(qna.EndpointKey)) { throw new InvalidOperationException("The QnA EndpointKey ('endpointKey') is required. Please update your '.bot' file."); } if (string.IsNullOrWhiteSpace(qna.Hostname)) { throw new InvalidOperationException("The QnA Host ('hostname') is required. Please update your '.bot' file."); } var qnaEndpoint = new QnAMakerEndpoint() { KnowledgeBaseId = qna.KbId, EndpointKey = qna.EndpointKey, Host = qna.Hostname, }; var qnaMaker = new QnAMaker(qnaEndpoint); QnAServices.Add(qna.Name, qnaMaker); break; } case ServiceTypes.Luis: { var luis = (LuisService)service; if (string.IsNullOrWhiteSpace(luis.AppId)) { throw new InvalidOperationException("The LUIS AppId ('appId') is required. Please update your '.bot' file."); } if (string.IsNullOrWhiteSpace(luis.AuthoringKey)) { throw new InvalidOperationException("The LUIS AuthoringKey ('authoringKey') is required. Please update your '.bot' file."); } if (string.IsNullOrWhiteSpace(luis.Region)) { throw new InvalidOperationException("The LUIS Region ('region') is required. Please update your '.bot' file."); } var app = new LuisApplication(luis.AppId, luis.AuthoringKey, luis.GetEndpoint()); var recognizer = new LuisRecognizer(app); LuisServices.Add(luis.Name, recognizer); break; } case ServiceTypes.Generic: { var genericService = (GenericService)service; if (genericService.Name == "carwashuservicebus") { if (string.IsNullOrWhiteSpace(genericService.Configuration["connectionString"])) { throw new InvalidOperationException("The ServiceBus ConnectionString ('connectionString') is required. Please update your '.bot' file."); } var serviceBusConnection = new ServiceBusConnection(genericService.Configuration["connectionString"]); ServiceBusServices.Add(genericService.Name, serviceBusConnection); } break; } } } }
public SkillConfiguration(BotConfiguration botConfiguration, string[] supportedProviders, string[] parameters, Dictionary <string, object> configuration) { if (supportedProviders != null && supportedProviders.Count() > 0) { IsAuthenticatedSkill = true; } foreach (var service in botConfiguration.Services) { switch (service.Type) { case ServiceTypes.AppInsights: { var appInsights = service as AppInsightsService; var telemetryConfig = new TelemetryConfiguration(appInsights.InstrumentationKey); TelemetryClient = new TelemetryClient(telemetryConfig); break; } case ServiceTypes.Luis: { var luis = service as LuisService; var luisApp = new LuisApplication(luis.AppId, luis.SubscriptionKey, luis.GetEndpoint()); LuisServices.Add(service.Id, new TelemetryLuisRecognizer(luisApp)); break; } case ServiceTypes.Generic: { if (service.Name == "Authentication") { var auth = service as GenericService; foreach (var provider in supportedProviders) { auth.Configuration.TryGetValue(provider, out var connectionName); if (connectionName != null) { AuthenticationConnections.Add(provider, connectionName); } } } break; } } } if (parameters != null) { // add the parameters the skill needs foreach (var parameter in parameters) { // Initialize each parameter to null. Needs to be set later by the bot. Properties.Add(parameter, null); } } if (configuration != null) { // add the additional keys the skill needs foreach (var set in configuration) { Properties.Add(set.Key, set.Value); } } }