public QnAMakerHelper(string environmentName, string contentRootPath)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(contentRootPath)
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                          .AddJsonFile($"appsettings.{environmentName}.json", optional: true)
                          .AddEnvironmentVariables();

            var configuration = builder.Build();

            config = new QnAMakerConfig();
            configuration.GetSection("QnAMakerConfig").Bind(config);

            if (string.IsNullOrEmpty(config.Name))
            {
                throw new Exception("Missing value in QnAMakerConfig -> Name");
            }

            if (string.IsNullOrEmpty(config.KbId))
            {
                throw new Exception("Missing value in QnAMakerConfig -> KbId");
            }

            if (string.IsNullOrEmpty(config.Hostname))
            {
                throw new Exception("Missing value in QnAMakerConfig -> Hostname");
            }

            if (string.IsNullOrEmpty(config.EndpointKey))
            {
                throw new Exception("Missing value in QnAMakerConfig -> EndpointKey");
            }
        }
Beispiel #2
0
        public async void GetConfigurationTest()
        {
            // arrage
            HttpClient httpClient        = new HttpClient();
            var        storage           = new MemoryStorage();
            var        userState         = new UserState(storage);
            var        conversationState = new ConversationState(storage);
            var        adapter           = new TestAdapter().Use(new AutoSaveStateMiddleware(conversationState));
            var        dialogState       = conversationState.CreateProperty <DialogState>("dialogState");
            var        dialogs           = new DialogSet(dialogState);
            var        steps             = new WaterfallStep[]
            {
                async(step, cancellationToken) =>
                {
                    await step.Context.SendActivityAsync("response");

                    // act
                    IQnAMakerService qnAMakerService = new QnAMakerService(httpClient, EnvironmentName, ContentRootPath);
                    QnAMakerConfig   config          = qnAMakerService.GetConfiguration();

                    // assert
                    Assert.Equal(configuration.KbId, config.KbId);
                    Assert.Equal(configuration.Name, config.Name);
                    Assert.Equal(configuration.EndpointKey, config.EndpointKey);
                    Assert.Equal(configuration.Hostname, config.Hostname);

                    return(Dialog.EndOfTurn);
                }
            };

            dialogs.Add(new WaterfallDialog(
                            "test",
                            steps));

            await new TestFlow(adapter, async(turnContext, cancellationToken) =>
            {
                var dc = await dialogs.CreateContextAsync(turnContext, cancellationToken);
                await dc.ContinueDialogAsync(cancellationToken);
                if (!turnContext.Responded)
                {
                    await dc.BeginDialogAsync("test", null, cancellationToken);
                }
            })
            .Send("ask")
            .AssertReply("response")
            .StartTestAsync();
        }
        public QnAMakerService(HttpClient httpClient, string environmentName, string contentRootPath, IBotTelemetryClient botTelemetryClient = null)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(contentRootPath)
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                          .AddJsonFile($"appsettings.{environmentName}.json", optional: true)
                          .AddEnvironmentVariables();

            var configuration = builder.Build();

            config = new QnAMakerConfig();
            configuration.GetSection("QnAMakerConfig").Bind(config);

            if (string.IsNullOrEmpty(config.Name))
            {
                throw new ArgumentException("Missing value in QnAMakerConfig -> Name");
            }

            if (string.IsNullOrEmpty(config.KbId))
            {
                throw new ArgumentException("Missing value in QnAMakerConfig -> KbId");
            }

            if (string.IsNullOrEmpty(config.Hostname))
            {
                throw new ArgumentException("Missing value in QnAMakerConfig -> Hostname");
            }

            if (string.IsNullOrEmpty(config.EndpointKey))
            {
                throw new ArgumentException("Missing value in QnAMakerConfig -> EndpointKey");
            }

            this.httpClient         = httpClient ?? throw new ArgumentException("Missing value in HttpClient");
            this.botTelemetryClient = botTelemetryClient;
            this.QnAMakerServices   = BuildDictionary();
        }