Ejemplo n.º 1
0
        /// <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.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;

                        if (!string.IsNullOrEmpty(authentication.Configuration["Azure Active Directory v2"]))
                        {
                            AuthConnectionName = authentication.Configuration["Azure Active Directory v2"];
                        }
                    }

                    break;
                }
                }
            }
        }
Ejemplo n.º 2
0
        /// <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;
                }
                }
            }
        }
Ejemplo n.º 3
0
        public SkillConfiguration(BotConfiguration botConfiguration, Dictionary <string, Dictionary <string, string> > languageModels, string[] supportedProviders = null, string[] parameters = null, Dictionary <string, object> configuration = null)
        {
            if (supportedProviders != null && supportedProviders.Count() > 0)
            {
                IsAuthenticatedSkill = true;
            }

            foreach (var service in botConfiguration.Services)
            {
                switch (service.Type)
                {
                case ServiceTypes.Generic:
                {
                    if (service.Name == "Authentication")
                    {
                        var auth = service as GenericService;

                        foreach (var provider in supportedProviders)
                        {
                            var matches = auth.Configuration.Where(x => x.Value == provider);

                            foreach (var match in matches)
                            {
                                AuthenticationConnections.Add(match.Key, match.Value);
                            }
                        }
                    }

                    break;
                }
                }
            }

            foreach (var language in languageModels)
            {
                var localeConfig = new LocaleConfiguration
                {
                    Locale = language.Key
                };

                var path   = language.Value["botFilePath"];
                var secret = language.Value["botFileSecret"];
                var config = BotConfiguration.Load(path, !string.IsNullOrEmpty(secret) ? secret : null);

                foreach (var service in config.Services)
                {
                    switch (service.Type)
                    {
                    case ServiceTypes.Dispatch:
                    {
                        var dispatch    = service as DispatchService;
                        var dispatchApp = new LuisApplication(dispatch.AppId, dispatch.SubscriptionKey, dispatch.GetEndpoint());
                        localeConfig.DispatchRecognizer = new TelemetryLuisRecognizer(dispatchApp);
                        break;
                    }

                    case ServiceTypes.Luis:
                    {
                        var luis    = service as LuisService;
                        var luisApp = new LuisApplication(luis.AppId, luis.SubscriptionKey, luis.GetEndpoint());
                        localeConfig.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);
                        localeConfig.QnAServices.Add(qna.Id, qnaMaker);
                        break;
                    }
                    }
                }

                LocaleConfigurations.Add(language.Key, localeConfig);
            }

            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);
                }
            }
        }
Ejemplo n.º 4
0
        /// <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;
                }
                }
            }
        }