Exemplo n.º 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddHttpClient().AddControllers().AddNewtonsoftJson();

            // Create the Bot Framework Adapter with error handling enabled.
            services.AddSingleton<IBotFrameworkHttpAdapter, AdapterWithErrorHandler>();

            // Create the bot services(QnA) as a singleton.
            services.AddSingleton<IBotServices, BotServices>();

            // Create the storage we'll be using for User and Conversation state. (Memory is great for testing purposes.)
            services.AddSingleton<IStorage, MemoryStorage>();

            // Create the User state. (Used in this bot's Dialog implementation.)
            services.AddSingleton<UserState>();

            // Create the Conversation state. (Used by the Dialog system itself.)
            services.AddSingleton<ConversationState>();

            // The Dialog that will be run by the bot.
            services.AddSingleton<RootDialog>();

            // Create the bot as a transient. In this case the ASP Controller is expecting an IBot.
            services.AddTransient<IBot, QnABot<RootDialog>>();

            ComponentRegistration.Add(new DialogsComponentRegistration());
        }
        /// <summary>
        /// from instructions: https://microsoft.github.io/botframework-solutions/skills/handbook/experimental-add-composer/
        /// </summary>
        /// <param name="services"></param>
        private void ConfigureComposerDialogServices(IServiceCollection services)
        {
            // Configure Adaptive
            ComponentRegistration.Add(new DialogsComponentRegistration());
            ComponentRegistration.Add(new AdaptiveComponentRegistration());
            ComponentRegistration.Add(new DeclarativeComponentRegistration());
            ComponentRegistration.Add(new LanguageGenerationComponentRegistration());
            ComponentRegistration.Add(new LuisComponentRegistration());

            // Resource explorer to manage declarative resources for adaptive dialog
            var resourceExplorer = new ResourceExplorer().LoadProject(this.HostingEnvironment.ContentRootPath);

            services.AddSingleton(resourceExplorer);

            services.AddSingleton <SkillConversationIdFactoryBase, SkillConversationIdFactory>();
            //to support SkillController.cs
            //from: https://github.com/microsoft/botbuilder-dotnet/blob/main/tests/Microsoft.Bot.Builder.TestBot.Json/Startup.cs
            services.AddSingleton <ChannelServiceHandler, SkillHandler>();
            services.AddSingleton <BotAdapter>(sp => (BotFrameworkHttpAdapter)sp.GetService <IBotFrameworkHttpAdapter>());

            //to support the needed parameters on the BotFrameworkClient constructor
            //services.AddHttpClient<SkillHttpClient>();
            services.AddSingleton <HttpClient>(new HttpClient());
            services.AddSingleton <BotFrameworkClient, BotFrameworkHttpClient>();
        }
Exemplo n.º 3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            // Register dialog. This sets up memory paths for adaptive.
            ComponentRegistration.Add(new DialogsComponentRegistration());

            // Register adaptive component
            ComponentRegistration.Add(new AdaptiveComponentRegistration());

            // Register to use language generation.
            ComponentRegistration.Add(new LanguageGenerationComponentRegistration());

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

            // Create the Bot Framework Adapter with error handling enabled.
            services.AddSingleton <IBotFrameworkHttpAdapter, AdapterWithErrorHandler>();

            // Create the storage we'll be using for User and Conversation state. (Memory is great for testing purposes.)
            services.AddSingleton <IStorage, MemoryStorage>();

            // Create the User state. (Used in this bot's Dialog implementation.)
            services.AddSingleton <UserState>();

            // Create the Conversation state. (Used by the Dialog system itself.)
            services.AddSingleton <ConversationState>();

            // The adaptive dialog that will be run by the bot.
            services.AddSingleton <RootDialog>();

            // Create the bot. the ASP Controller is expecting an IBot.
            services.AddSingleton <IBot, DialogBot <RootDialog> >();
        }
Exemplo n.º 4
0
        static async Task Main(string[] args)
        {
            var configuration = new ConfigurationBuilder().AddEnvironmentVariables().AddCommandLine(args).Build();

            ComponentRegistration.Add(new DialogsComponentRegistration());
            ComponentRegistration.Add(new DeclarativeComponentRegistration());
            ComponentRegistration.Add(new AdaptiveComponentRegistration());
            ComponentRegistration.Add(new LanguageGenerationComponentRegistration());
            ComponentRegistration.Add(new LucyComponentRegistration());
            ComponentRegistration.Add(new ConsoleComponentRegistration());

            var appName         = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
            var userStoragePath = Path.Combine(Path.GetTempPath(), appName);

            Directory.CreateDirectory(userStoragePath);
            var adapter = new ConsoleAdapter()
                          .Use(new RegisterClassMiddleware <IConfiguration>(configuration))
                          .UseStorage(new MemoryStorage())
                          .UseBotState(new ConversationState(new MemoryStorage()), new UserState(new FileStorage(userStoragePath)));

            var resourceExplorer = new ResourceExplorer()
                                   .AddFolder(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "ConsoleBot"));

            var bot = new DialogManager()
            {
                RootDialog = resourceExplorer.LoadType <AdaptiveDialog>(resourceExplorer.GetResource("ConsoleBot.dialog"))
            }
            .UseResourceExplorer(resourceExplorer)
            .UseLanguageGeneration();

            await((ConsoleAdapter)adapter).StartConversation(bot.OnTurnAsync, String.Join(" ", args));
        }
Exemplo n.º 5
0
 public LGGeneratorTests()
 {
     ComponentRegistration.Add(new DeclarativeComponentRegistration());
     ComponentRegistration.Add(new AdaptiveComponentRegistration());
     ComponentRegistration.Add(new AdaptiveTestingComponentRegistration());
     ComponentRegistration.Add(new LanguageGenerationComponentRegistration());
 }
Exemplo n.º 6
0
        public DialogStateManager(DialogContext dc, DialogStateManagerConfiguration configuration = null)
        {
            ComponentRegistration.Add(new DialogsComponentRegistration());

            dialogContext      = dc ?? throw new ArgumentNullException(nameof(dc));
            this.Configuration = configuration ?? dc.Context.TurnState.Get <DialogStateManagerConfiguration>();
            if (this.Configuration == null)
            {
                this.Configuration = new DialogStateManagerConfiguration();

                // get all of the component memory scopes
                foreach (var component in ComponentRegistration.Components.OfType <IComponentMemoryScopes>())
                {
                    foreach (var memoryScope in component.GetMemoryScopes())
                    {
                        this.Configuration.MemoryScopes.Add(memoryScope);
                    }
                }

                // get all of the component path resolvers
                foreach (var component in ComponentRegistration.Components.OfType <IComponentPathResolvers>())
                {
                    foreach (var pathResolver in component.GetPathResolvers())
                    {
                        this.Configuration.PathResolvers.Add(pathResolver);
                    }
                }
            }

            // cache for any other new dialogStatemanager instances in this turn.
            dc.Context.TurnState.Set <DialogStateManagerConfiguration>(this.Configuration);
        }
 public ActivityFactoryTests()
 {
     ComponentRegistration.Add(new DeclarativeComponentRegistration());
     ComponentRegistration.Add(new AdaptiveComponentRegistration());
     ComponentRegistration.Add(new AdaptiveTestingComponentRegistration());
     ComponentRegistration.Add(new LanguageGenerationComponentRegistration());
 }
Exemplo n.º 8
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers().AddNewtonsoftJson();

            ComponentRegistration.Add(new DialogsComponentRegistration());

            ComponentRegistration.Add(new AdaptiveComponentRegistration());

            ComponentRegistration.Add(new LanguageGenerationComponentRegistration());

            services.AddSingleton <ICredentialProvider, ConfigurationCredentialProvider>();

            services.AddSingleton <IBotFrameworkHttpAdapter, AdapterWithErrorHandler>();

            services.AddSingleton <IStorage, MemoryStorage>();

            services.AddSingleton <UserState>();

            services.AddSingleton <ConversationState>();

            services.AddSingleton <SettingProvider>();

            services.AddSingleton <RootDialog>();

            services.AddSingleton <IIssueTrackingIntegrationService, JiraIntegrationService>();

            services.AddTransient <IBot, DialogBot <RootDialog> >();

            AddJiraService(services);
        }
Exemplo n.º 9
0
        public Startup(IMessageSink messageSink)
            : base(messageSink)
        {
            var builder = new ConfigurationBuilder()
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: false);

            Configuration = builder.Build();

            /* TODO: This does not work until TestAdapter is updated
             * Services = new ServiceCollection();
             * Services.AddSingleton(Configuration);
             * new DialogsBotComponent().ConfigureServices(Services, Configuration);
             * new AdaptiveBotComponent().ConfigureServices(Services, Configuration);
             * new LanguageGenerationBotComponent().ConfigureServices(Services, Configuration);
             * new LuisBotComponent().ConfigureServices(Services, Configuration);
             * new QnAMakerBotComponent().ConfigureServices(Services, Configuration);
             * new FormExtensionsBotComponent().ConfigureServices(Services, Configuration);
             */
            ComponentRegistration.Add(new DialogsComponentRegistration());
            ComponentRegistration.Add(new DeclarativeComponentRegistration());
            ComponentRegistration.Add(new AdaptiveComponentRegistration());
            ComponentRegistration.Add(new LanguageGenerationComponentRegistration());
            ComponentRegistration.Add(new AdaptiveTestingComponentRegistration());
            ComponentRegistration.Add(new LuisComponentRegistration());
            ComponentRegistration.Add(new QnAMakerComponentRegistration());
            ComponentRegistration.Add(new DeclarativeComponentRegistrationBridge <FormExtensionsBotComponent>());
        }
Exemplo n.º 10
0
        public static async Task Main(string[] args)
        {
            var root        = ".";
            var region      = "westus";
            var environment = Environment.UserName;

            for (var i = 0; i < args.Length; ++i)
            {
                var arg = args[i];
                switch (arg)
                {
                case "--root": root = NextArg(ref i, args); break;

                case "--region": region = NextArg(ref i, args); break;

                case "--environment": environment = NextArg(ref i, args); break;

                default: Usage(); break;
                }
            }

            ComponentRegistration.Add(new DeclarativeComponentRegistration());
            ComponentRegistration.Add(new AdaptiveComponentRegistration());
            ComponentRegistration.Add(new LanguageGenerationComponentRegistration());
            ComponentRegistration.Add(new AdaptiveTestingComponentRegistration());
            ComponentRegistration.Add(new LuisComponentRegistration());
            ComponentRegistration.Add(new QnAMakerComponentRegistration());

            var config = new ConfigurationBuilder()
                         .AddInMemoryCollection(new Dictionary <string, string> {
                { "root", root }, { "region", region }, { "environment", environment }
            })
                         .UseMockLuisSettings(root, root)
                         .AddUserSecrets("RunBot")
                         .Build();
            var resourceExplorer = new ResourceExplorer().AddFolder(root, monitorChanges: false);

            resourceExplorer.RegisterType(LuisAdaptiveRecognizer.Kind, typeof(MockLuisRecognizer), new MockLuisLoader(config));

            var dialogs = resourceExplorer.GetResources(".dialog").ToList();

            foreach (var test in resourceExplorer.GetResources(".dialog").Where(r => r.Id.EndsWith(".test.dialog")))
            {
                try
                {
                    Console.WriteLine($"Running test {test.Id}");
                    var script = resourceExplorer.LoadType <TestScript>(test.Id);
                    script.Configuration = config;
                    script.Description ??= test.Id;
                    await script.ExecuteAsync(resourceExplorer, test.Id).ConfigureAwait(false);

                    Console.WriteLine("Passed\n");
                }
                catch (Exception e)
                {
                    Console.WriteLine($"*** Failed: {e.Message}\n");
                }
            }
        }
Exemplo n.º 11
0
 public static void Initialize(TestContext testContext)
 {
     ComponentRegistration.Add(new DeclarativeComponentRegistration());
     ComponentRegistration.Add(new AdaptiveComponentRegistration());
     ComponentRegistration.Add(new LanguageGenerationComponentRegistration());
     ComponentRegistration.Add(new AdaptiveTestingComponentRegistration());
     ComponentRegistration.Add(new LuisComponentRegistration());
 }
Exemplo n.º 12
0
 /// <summary>
 /// Add standard component registrations to the bot runtime.
 /// </summary>
 internal static void Add()
 {
     ComponentRegistration.Add(new DialogsComponentRegistration());
     ComponentRegistration.Add(new DeclarativeComponentRegistration());
     ComponentRegistration.Add(new AdaptiveComponentRegistration());
     ComponentRegistration.Add(new LanguageGenerationComponentRegistration());
     ComponentRegistration.Add(new QnAMakerComponentRegistration());
     ComponentRegistration.Add(new LuisComponentRegistration());
     ComponentRegistration.Add(new TeamsComponentRegistration());
 }
Exemplo n.º 13
0
 public static void Initialize(TestContext testContext)
 {
     ComponentRegistration.Add(new DeclarativeComponentRegistration());
     ComponentRegistration.Add(new AdaptiveComponentRegistration());
     ComponentRegistration.Add(new LanguageGenerationComponentRegistration());
     ComponentRegistration.Add(new AdaptiveTestingComponentRegistration());
     ComponentRegistration.Add(new AzureStorageComponentRegistration());
     ComponentRegistration.Add(new CosmosComponentRegistration());
     ComponentRegistration.Add(new SqlClientComponentRegistration());
 }
        public static void ClassInitialize(TestContext context)
        {
            string path = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, samplesDirectory));

            // register components.
            ComponentRegistration.Add(new DialogsComponentRegistration());
            ComponentRegistration.Add(new DeclarativeComponentRegistration());
            ComponentRegistration.Add(new AdaptiveComponentRegistration());
            ComponentRegistration.Add(new LanguageGenerationComponentRegistration());
        }
Exemplo n.º 15
0
        public static void Initialize(TestContext testContext)
        {
#pragma warning disable CS0618 // Type or member is obsolete
            ComponentRegistration.Add(new DialogsComponentRegistration());
            ComponentRegistration.Add(new DeclarativeComponentRegistration());
            ComponentRegistration.Add(new AdaptiveComponentRegistration());
            ComponentRegistration.Add(new LanguageGenerationComponentRegistration());
            ComponentRegistration.Add(new AdaptiveTestingComponentRegistration());
            ComponentRegistration.Add(new DeclarativeComponentRegistrationBridge <GithubBotComponent>());
#pragma warning restore CS0618 // Type or member is obsolete
        }
Exemplo n.º 16
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers().AddNewtonsoftJson();

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

            // Register AuthConfiguration to enable custom claim validation.
            services.AddSingleton <AuthenticationConfiguration>();

            // register components.
            ComponentRegistration.Add(new DeclarativeComponentRegistrationBridge <DialogsBotComponent>());
            ComponentRegistration.Add(new DeclarativeComponentRegistrationBridge <DeclarativeBotComponent>());
            ComponentRegistration.Add(new DeclarativeComponentRegistrationBridge <AdaptiveBotComponent>());
            ComponentRegistration.Add(new DeclarativeComponentRegistrationBridge <LanguageGenerationBotComponent>());
            ComponentRegistration.Add(new DeclarativeComponentRegistrationBridge <QnAMakerBotComponent>());
            ComponentRegistration.Add(new DeclarativeComponentRegistrationBridge <LuisBotComponent>());
            ComponentRegistration.Add(new DeclarativeComponentRegistrationBridge <DynamicListBotComponent>());

/*
 *          new DialogsBotComponent().ConfigureServices(services, this._configuration);
 *          new DeclarativeBotComponent().ConfigureServices(services, this._configuration);
 *          new AdaptiveBotComponent().ConfigureServices(services, this._configuration);
 *          new LanguageGenerationBotComponent().ConfigureServices(services, this._configuration);
 *          new QnAMakerBotComponent().ConfigureServices(services, this._configuration);
 *          new LuisBotComponent().ConfigureServices(services, this._configuration);
 *          new DynamicListBotComponent().ConfigureServices(services, this._configuration);*/

            // Create the Bot Framework Adapter with error handling enabled.
            // Note: some classes use the base BotAdapter so we add an extra registration that pulls the same instance.
            services.AddSingleton <IBotFrameworkHttpAdapter, TestBotHttpAdapter>();
            services.AddSingleton <BotAdapter>(sp => (BotFrameworkHttpAdapter)sp.GetService <IBotFrameworkHttpAdapter>());

            // Create the storage we'll be using for User and Conversation state. (Memory is great for testing purposes.)
            services.AddSingleton <IStorage, MemoryStorage>();

            // Create the User state. (Used in this bot's Dialog implementation.)
            services.AddSingleton <UserState>();

            // Create the Conversation state. (Used by the Dialog system itself.)
            services.AddSingleton <ConversationState>();

            // Register the skills client and skills request handler.
            services.AddSingleton <SkillConversationIdFactoryBase, SkillConversationIdFactory>();
            services.AddHttpClient <BotFrameworkClient, SkillHttpClient>();
            services.AddSingleton <ChannelServiceHandler, SkillHandler>();

            var resourceExplorer = new ResourceExplorer().AddFolder(_configuration.GetValue <string>("BotRoot"));

            services.AddSingleton(resourceExplorer);

            // Create the bot  In this case the ASP Controller is expecting an IBot.
            services.AddSingleton <IBot, RunBot>();
        }
        public IntegrationTestsBase(ResourceExplorerFixture resourceExplorerFixture)
        {
            ComponentRegistration.Add(new DeclarativeComponentRegistration());
            ComponentRegistration.Add(new DialogsComponentRegistration());
            ComponentRegistration.Add(new AdaptiveComponentRegistration());
            ComponentRegistration.Add(new LanguageGenerationComponentRegistration());
            ComponentRegistration.Add(new AdaptiveTestingComponentRegistration());
            ComponentRegistration.Add(new DeclarativeComponentRegistrationBridge <TelephonyBotComponent>());

            _resourceExplorerFixture = resourceExplorerFixture.Initialize(this.GetType().Name);
        }
        public ActivityFactoryTests()
        {
            ComponentRegistration.Add(new DeclarativeComponentRegistration());
            ComponentRegistration.Add(new AdaptiveComponentRegistration());
            ComponentRegistration.Add(new AdaptiveTestingComponentRegistration());
            ComponentRegistration.Add(new LanguageGenerationComponentRegistration());

            var path = Path.Combine(AppContext.BaseDirectory, "lg", "NormalStructuredLG.lg");

            templates = Templates.ParseFile(path);
        }
Exemplo n.º 19
0
        public ActionTests(ResourceExplorerFixture resourceExplorerFixture)
        {
            ComponentRegistration.Add(new DeclarativeComponentRegistration());
            ComponentRegistration.Add(new DialogsComponentRegistration());
            ComponentRegistration.Add(new AdaptiveComponentRegistration());
            ComponentRegistration.Add(new LanguageGenerationComponentRegistration());
            ComponentRegistration.Add(new AdaptiveTestingComponentRegistration());
            ComponentRegistration.Add(new TeamsComponentRegistration());

            _resourceExplorerFixture = resourceExplorerFixture.Initialize(nameof(ActionTests));
        }
        public static void ClassInitialize(TestContext context)
        {
            ComponentRegistration.Add(new DeclarativeComponentRegistration());
            ComponentRegistration.Add(new DialogsComponentRegistration());
            ComponentRegistration.Add(new AdaptiveComponentRegistration());
            ComponentRegistration.Add(new LanguageGenerationComponentRegistration());
            ComponentRegistration.Add(new DeclarativeComponentRegistrationBridge <LucyBotComponent>());

            ResourceExplorer = new ResourceExplorer()
                               .AddFolder(@"..\..\..\TestBot");
            ResourceExplorer.AddResourceType("yaml");
        }
        public static void ClassInitialize(TestContext context)
        {
            string path = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, samplesDirectory, "RespondingWithTextSample"));

            resourceExplorer.AddFolder(path);

            // register components.
            ComponentRegistration.Add(new DialogsComponentRegistration());
            ComponentRegistration.Add(new DeclarativeComponentRegistration());
            ComponentRegistration.Add(new AdaptiveComponentRegistration());
            ComponentRegistration.Add(new LanguageGenerationComponentRegistration());
        }
        public ConditionalTests()
        {
            ComponentRegistration.Add(new DeclarativeComponentRegistration());
            ComponentRegistration.Add(new DialogsComponentRegistration());
            ComponentRegistration.Add(new AdaptiveComponentRegistration());
            ComponentRegistration.Add(new LanguageGenerationComponentRegistration());
            ComponentRegistration.Add(new AdaptiveTestingComponentRegistration());
            ComponentRegistration.Add(new TeamsComponentRegistration());

            ResourceExplorer = new ResourceExplorer()
                               .AddFolder(Path.Combine(TestUtils.GetProjectPath(), "Tests", nameof(ConditionalTests)), monitorChanges: false);
        }
Exemplo n.º 23
0
        public Startup(IMessageSink messageSink)
            : base(messageSink)
        {
            var builder = new ConfigurationBuilder()
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: false);

            Configuration = builder.Build();

            ComponentRegistration.Add(new DeclarativeComponentRegistration());
            ComponentRegistration.Add(new AdaptiveComponentRegistration());
            ComponentRegistration.Add(new LanguageGenerationComponentRegistration());
            ComponentRegistration.Add(new AdaptiveTestingComponentRegistration());
            ComponentRegistration.Add(new LuisComponentRegistration());
            ComponentRegistration.Add(new QnAMakerComponentRegistration());
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DialogStateManager"/> class.
        /// </summary>
        /// <param name="dc">The dialog context for the current turn of the conversation.</param>
        /// <param name="configuration">Configuration for the dialog state manager. Default is <c>null</c>.</param>
        public DialogStateManager(DialogContext dc, DialogStateManagerConfiguration configuration = null)
        {
            ComponentRegistration.Add(new DialogsComponentRegistration());

            _dialogContext = dc ?? throw new ArgumentNullException(nameof(dc));
            Configuration  = configuration ?? dc.Context.TurnState.Get <DialogStateManagerConfiguration>();
            if (Configuration == null)
            {
                Configuration = new DialogStateManagerConfiguration();

                // Legacy memory scopes from static ComponentRegistration which is now obsolete.
                var memoryScopes = ComponentRegistration.Components
                                   .OfType <IComponentMemoryScopes>()
                                   .SelectMany(c => c.GetMemoryScopes())
                                   .ToList();

                // Merge new registrations from turn state
                memoryScopes.AddRange(dc.Context.TurnState.Get <IEnumerable <MemoryScope> >() ?? Enumerable.Empty <MemoryScope>());

                // Get all of the component memory scopes.
                foreach (var scope in memoryScopes)
                {
                    Configuration.MemoryScopes.Add(scope);
                }

                // Legacy memory scopes from static ComponentRegistration which is now obsolete.
                var pathResolvers = ComponentRegistration.Components
                                    .OfType <IComponentPathResolvers>()
                                    .SelectMany(c => c.GetPathResolvers())
                                    .ToList();

                // Merge new registrations from turn state
                pathResolvers.AddRange(dc.Context.TurnState.Get <IEnumerable <IPathResolver> >() ?? Enumerable.Empty <IPathResolver>());

                // Get all of the component path resolvers.
                foreach (var pathResolver in pathResolvers)
                {
                    Configuration.PathResolvers.Add(pathResolver);
                }
            }

            // cache for any other new dialogStatemanager instances in this turn.
            dc.Context.TurnState.Set(Configuration);
        }
Exemplo n.º 25
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            services.AddHttpClient().AddControllers().AddNewtonsoftJson();

            // Required for memory paths introduced by adaptive dialogs.
            ComponentRegistration.Add(new DialogsComponentRegistration());

            // Register declarative components
            ComponentRegistration.Add(new DeclarativeComponentRegistration());

            // Register adapive dialog components
            ComponentRegistration.Add(new AdaptiveComponentRegistration());

            // Add Language generation
            ComponentRegistration.Add(new LanguageGenerationComponentRegistration());

            // Add LUIS component
            ComponentRegistration.Add(new LuisComponentRegistration());

            // Create the Bot Framework Adapter with error handling enabled.
            services.AddSingleton <IBotFrameworkHttpAdapter, AdapterWithErrorHandler>();

            // Create the storage we'll be using for User and Conversation state. (Memory is great for testing purposes.)
            services.AddSingleton <IStorage, MemoryStorage>();

            // Create the User state. (Used in this bot's Dialog implementation.)
            services.AddSingleton <UserState>();

            // Create the Conversation state. (Used by the Dialog system itself.)
            services.AddSingleton <ConversationState>();

            // The Dialog that will be run by the bot.
            services.AddSingleton <RootDialog>();

            // Resource explorer to manage declarative resources for adaptive dialog
            var resourceExplorer = new ResourceExplorer().LoadProject(this.HostingEnvironment.ContentRootPath);

            services.AddSingleton(resourceExplorer);

            // Create the bot as a transient. In this case the ASP Controller is expecting an IBot.
            services.AddSingleton <IBot, DialogBot <RootDialog> >();
        }
Exemplo n.º 26
0
        public static void ClassInitialize(TestContext context)
        {
            // IMPROTANT!!! Order matter here. The component registration has to happen before
            // the ResourceExplorer's RegisterType because internally it registers all the type
            // only once. Since ComponentRegistration is a static/singleton, if the RegisterType
            // happens before this, it would cause either the first test to fail in a set or test
            // to fail if run individually.

            // Include the base set of components
            // Individual test classes should add its own set of custom actions
            // and other components required for testing
#pragma warning disable CS0618 // Type or member is obsolete
            ComponentRegistration.Add(new DeclarativeComponentRegistration());
            ComponentRegistration.Add(new AdaptiveComponentRegistration());
            ComponentRegistration.Add(new LanguageGenerationComponentRegistration());
            ComponentRegistration.Add(new AdaptiveTestingComponentRegistration());
            ComponentRegistration.Add(new LuisComponentRegistration());
            ComponentRegistration.Add(new QnAMakerComponentRegistration());
            ComponentRegistration.Add(new DialogsComponentRegistration());
#pragma warning restore CS0618 // Type or member is obsolete

            IHaveComponentsToInitialize testClass = new T();
            testClass.InitializeComponents();

            Debug.WriteLine("Testing" + typeof(T).Name);

            Configuration = new ConfigurationBuilder()
                            .AddInMemoryCollection(new Dictionary <string, string>
            {
                { "root", Path.Combine(Environment.CurrentDirectory, "BotProject") },
                { "luis:resources", Path.Combine(Environment.CurrentDirectory, "TestAssets", typeof(T).Name) },
            })
                            .UseLuisSettings()
                            .AddJsonFile("testsettings.json", optional: true, reloadOnChange: false)
                            .Build();


            ResourceExplorer = new ResourceExplorer()
                               // Add the dialog assets
                               .AddFolder(Path.Combine(Environment.CurrentDirectory, "BotProject"), monitorChanges: false)
                               .AddFolder(Path.Combine(Environment.CurrentDirectory, "TestAssets", typeof(T).Name), monitorChanges: false)
                               .RegisterType(LuisAdaptiveRecognizer.Kind, typeof(MockLuisRecognizer), new MockLuisLoader(Configuration));
        }
Exemplo n.º 27
0
        public void TestResourceExplorerRegistration(ResourceExplorerOptions options, ComponentRegistration legacyRegistration)
        {
            // Arrange
            // Build resourceExplorer
            using (var explorer = new ResourceExplorer(options))
            {
                // Clear component registration
                if (legacyRegistration != null)
                {
                    ComponentRegistration.Add(legacyRegistration);
                }

                // Test
                var declarativeType = explorer.LoadType <TestDeclarativeType>(new MemoryResource());

                // Assert
                Assert.NotNull(declarativeType);
                Assert.Equal("fromConverter", declarativeType.Data);
            }
        }
Exemplo n.º 28
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            // Register dialog. This sets up memory paths for adaptive.
            ComponentRegistration.Add(new DialogsComponentRegistration());

            // Register adaptive component
            ComponentRegistration.Add(new AdaptiveComponentRegistration());

            // Register to use language generation.
            ComponentRegistration.Add(new LanguageGenerationComponentRegistration());

            // Register declarative components for adaptive dialogs.
            ComponentRegistration.Add(new DeclarativeComponentRegistration());

            ComponentRegistration.Add(new OrchestratorComponentRegistration());

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

            // Create the Bot Framework Adapter with error handling enabled.
            services.AddSingleton <IBotFrameworkHttpAdapter, DeclarativeBotAdapter>();

            // Create the storage we'll be using for User and Conversation state. (Memory is great for testing purposes.)
            services.AddSingleton <IStorage, MemoryStorage>();

            // Create the User state. (Used in this bot's Dialog implementation.)
            services.AddSingleton <UserState>();

            // Create the Conversation state. (Used by the Dialog system itself.)
            services.AddSingleton <ConversationState>();

            var resourceExplorer = new ResourceExplorer().LoadProject(this.HostingEnvironment.ContentRootPath);

            services.AddSingleton(resourceExplorer);

            // Create the bot  In this case the ASP Controller is expecting an IBot.
            services.AddSingleton <IBot, DeclarativeBot>();
        }
Exemplo n.º 29
0
        public override void Configure(IFunctionsHostBuilder builder)
        {
            // Get assets directory.
            var assetsDirectory = GetAssetsDirectory();

            // Build configuration with assets.
            var config = BuildConfiguration(assetsDirectory);

            var settings = new BotSettings();

            config.Bind(settings);

            var services = builder.Services;

            services.AddSingleton <IConfiguration>(config);

            services.AddLogging();

            // Create the credential provider to be used with the Bot Framework Adapter.
            services.AddSingleton <ICredentialProvider, ConfigurationCredentialProvider>();
            services.AddSingleton <BotAdapter>(sp => (BotFrameworkHttpAdapter)sp.GetService <IBotFrameworkHttpAdapter>());

            // Register AuthConfiguration to enable custom claim validation.
            services.AddSingleton <AuthenticationConfiguration>();

            // Adaptive component registration
            ComponentRegistration.Add(new DialogsComponentRegistration());
            ComponentRegistration.Add(new DeclarativeComponentRegistration());
            ComponentRegistration.Add(new AdaptiveComponentRegistration());
            ComponentRegistration.Add(new LanguageGenerationComponentRegistration());
            ComponentRegistration.Add(new QnAMakerComponentRegistration());
            ComponentRegistration.Add(new LuisComponentRegistration());

            // This is for custom action component registration.
            //ComponentRegistration.Add(new CustomActionComponentRegistration());

            // Register the skills client and skills request handler.
            services.AddSingleton <SkillConversationIdFactoryBase, SkillConversationIdFactory>();
            services.AddHttpClient <BotFrameworkClient, SkillHttpClient>();
            services.AddSingleton <ChannelServiceHandler, SkillHandler>();

            // Register telemetry client, initializers and middleware
            services.AddApplicationInsightsTelemetry(settings?.ApplicationInsights?.InstrumentationKey ?? string.Empty);

            services.AddSingleton <ITelemetryInitializer, OperationCorrelationTelemetryInitializer>();
            services.AddSingleton <ITelemetryInitializer, TelemetryBotIdInitializer>();
            services.AddSingleton <IBotTelemetryClient, BotTelemetryClient>();
            services.AddSingleton <TelemetryLoggerMiddleware>(sp =>
            {
                var telemetryClient = sp.GetService <IBotTelemetryClient>();
                return(new TelemetryLoggerMiddleware(telemetryClient, logPersonalInformation: settings?.Telemetry?.LogPersonalInformation ?? false));
            });
            services.AddSingleton <TelemetryInitializerMiddleware>(sp =>
            {
                var httpContextAccessor       = sp.GetService <IHttpContextAccessor>();
                var telemetryLoggerMiddleware = sp.GetService <TelemetryLoggerMiddleware>();
                return(new TelemetryInitializerMiddleware(httpContextAccessor, telemetryLoggerMiddleware, settings?.Telemetry?.LogActivities ?? false));
            });

            // Storage
            IStorage storage;

            if (ConfigSectionValid(settings?.CosmosDb?.AuthKey))
            {
                storage = new CosmosDbPartitionedStorage(settings?.CosmosDb);
            }
            else
            {
                storage = new MemoryStorage();
            }

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

            services.AddSingleton(userState);
            services.AddSingleton(conversationState);

            // Resource explorer to track declarative assets
            var resourceExplorer = new ResourceExplorer().AddFolder(assetsDirectory.FullName);

            services.AddSingleton(resourceExplorer);

            // Adapter
            services.AddSingleton <IBotFrameworkHttpAdapter, BotFrameworkHttpAdapter>(s =>
            {
                // Retrieve required dependencies
                IStorage storage    = s.GetService <IStorage>();
                UserState userState = s.GetService <UserState>();
                ConversationState conversationState = s.GetService <ConversationState>();
                TelemetryInitializerMiddleware telemetryInitializerMiddleware = s.GetService <TelemetryInitializerMiddleware>();

                var adapter = new BotFrameworkHttpAdapter(new ConfigurationCredentialProvider(config));

                adapter
                .UseStorage(storage)
                .UseBotState(userState, conversationState)
                .Use(new RegisterClassMiddleware <IConfiguration>(config))
                .Use(telemetryInitializerMiddleware);

                // Configure Middlewares
                ConfigureTranscriptLoggerMiddleware(adapter, settings);
                ConfigureInspectionMiddleWare(adapter, settings, s);
                ConfigureShowTypingMiddleWare(adapter, settings);

                adapter.OnTurnError = async(turnContext, exception) =>
                {
                    await turnContext.SendActivityAsync(exception.Message).ConfigureAwait(false);
                    await conversationState.ClearStateAsync(turnContext).ConfigureAwait(false);
                    await conversationState.SaveChangesAsync(turnContext).ConfigureAwait(false);
                };

                return(adapter);
            });

            var defaultLocale = config.GetValue <string>(DefaultLanguageSetting) ?? EnglishLocale;

            var removeRecipientMention = settings?.Feature?.RemoveRecipientMention ?? false;

            // Bot
            services.AddSingleton <IBot>(s =>
                                         new ComposerBot(
                                             s.GetService <ConversationState>(),
                                             s.GetService <UserState>(),
                                             s.GetService <ResourceExplorer>(),
                                             s.GetService <BotFrameworkClient>(),
                                             s.GetService <SkillConversationIdFactoryBase>(),
                                             s.GetService <IBotTelemetryClient>(),
                                             GetRootDialog(assetsDirectory.FullName),
                                             defaultLocale,
                                             removeRecipientMention));
        }
Exemplo n.º 30
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers().AddNewtonsoftJson();

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

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

            Configuration.Bind(settings);

            // Create the credential provider to be used with the Bot Framework Adapter.
            services.AddSingleton <ICredentialProvider, ConfigurationCredentialProvider>();
            services.AddSingleton <BotAdapter>(sp => (BotFrameworkHttpAdapter)sp.GetService <IBotFrameworkHttpAdapter>());

            // Register AuthConfiguration to enable custom claim validation for skills.
            services.AddSingleton(sp => new AuthenticationConfiguration {
                ClaimsValidator = new AllowedCallersClaimsValidator(settings.SkillConfiguration)
            });

            // register components.
            ComponentRegistration.Add(new DialogsComponentRegistration());
            ComponentRegistration.Add(new DeclarativeComponentRegistration());
            ComponentRegistration.Add(new AdaptiveComponentRegistration());
            ComponentRegistration.Add(new LanguageGenerationComponentRegistration());
            ComponentRegistration.Add(new QnAMakerComponentRegistration());
            ComponentRegistration.Add(new LuisComponentRegistration());

            // This is for custom action component registration.
            //ComponentRegistration.Add(new CustomActionComponentRegistration());

            // Register the skills client and skills request handler.
            services.AddSingleton <SkillConversationIdFactoryBase, SkillConversationIdFactory>();
            services.AddHttpClient <BotFrameworkClient, SkillHttpClient>();
            services.AddSingleton <ChannelServiceHandler, SkillHandler>();

            // Register telemetry client, initializers and middleware
            services.AddApplicationInsightsTelemetry(settings?.ApplicationInsights?.InstrumentationKey ?? string.Empty);

            services.AddSingleton <ITelemetryInitializer, OperationCorrelationTelemetryInitializer>();
            services.AddSingleton <ITelemetryInitializer, TelemetryBotIdInitializer>();
            services.AddSingleton <IBotTelemetryClient, BotTelemetryClient>();
            services.AddSingleton <TelemetryLoggerMiddleware>(sp =>
            {
                var telemetryClient = sp.GetService <IBotTelemetryClient>();
                return(new TelemetryLoggerMiddleware(telemetryClient, logPersonalInformation: settings?.Telemetry?.LogPersonalInformation ?? false));
            });
            services.AddSingleton <TelemetryInitializerMiddleware>(sp =>
            {
                var httpContextAccessor       = sp.GetService <IHttpContextAccessor>();
                var telemetryLoggerMiddleware = sp.GetService <TelemetryLoggerMiddleware>();
                return(new TelemetryInitializerMiddleware(httpContextAccessor, telemetryLoggerMiddleware, settings?.Telemetry?.LogActivities ?? false));
            });

            var storage = ConfigureStorage(settings);

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

            services.AddSingleton(userState);
            services.AddSingleton(conversationState);

            // Configure bot loading path
            var botDir           = settings.Bot;
            var resourceExplorer = new ResourceExplorer().AddFolder(botDir);
            var rootDialog       = GetRootDialog(botDir);

            var defaultLocale = Configuration.GetValue <string>("defaultLanguage") ?? "en-us";

            services.AddSingleton(resourceExplorer);

            resourceExplorer.RegisterType <OnQnAMatch>("Microsoft.OnQnAMatch");

            services.AddSingleton <IBotFrameworkHttpAdapter, BotFrameworkHttpAdapter>(s =>
                                                                                      GetBotAdapter(storage, settings, userState, conversationState, s));

            var removeRecipientMention = settings?.Feature?.RemoveRecipientMention ?? false;

            services.AddSingleton <IBot>(s =>
                                         new ComposerBot(
                                             s.GetService <ConversationState>(),
                                             s.GetService <UserState>(),
                                             s.GetService <ResourceExplorer>(),
                                             s.GetService <BotFrameworkClient>(),
                                             s.GetService <SkillConversationIdFactoryBase>(),
                                             s.GetService <IBotTelemetryClient>(),
                                             rootDialog,
                                             defaultLocale,
                                             removeRecipientMention));
        }