예제 #1
0
        /// <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);
            }
        }
예제 #2
0
        public LuisService(string environmentName, string contentRootPath, IBotTelemetryClient botTelemetryClient = null, HttpClientHandler httpClientHandler = 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 LuisConfig();
            configuration.GetSection("LuisConfig").Bind(config);

            this.botTelemetryClient = botTelemetryClient;
            this.httpClientHandler  = httpClientHandler;
            this.LuisServices       = BuildDictionary();
        }
예제 #3
0
        public async void GetConfigurationTest()
        {
            // arrage
            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
                    ILuisService luisService = new LuisService(EnvironmentName, ContentRootPath, null, null);
                    LuisConfig   config      = luisService.GetConfiguration();

                    // assert
                    Assert.Equal(configuration.BingSpellCheckSubscriptionKey, config.BingSpellCheckSubscriptionKey);
                    Assert.Collection <LuisApp>(configuration.LuisApplications, x => Xunit.Assert.Contains("name", x.Name));
                    Assert.Equal(configuration.LuisRouterUrl, config.LuisRouterUrl);

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