Example #1
0
        public DemoSkill(DemoSkillServices services, DemoSkillAccessors accessors)
        {
            _accessors = accessors;
            _dialogs   = new DialogSet(accessors.ConversationDialogState);
            _responder = new DemoSkillResponses();
            _services  = services;

            RegisterDialogs();
        }
Example #2
0
        public void ConfigureServices(IServiceCollection services)
        {
            var botFilePath   = Configuration.GetSection("botFilePath").Value;
            var botFileSecret = Configuration.GetSection("botFileSecret").Value;

            // Loads .bot configuration file and adds a singleton that your Bot can access through dependency injection.
            var botConfig = BotConfiguration.LoadAsync(botFilePath).GetAwaiter().GetResult();

            services.AddSingleton(sp => botConfig);

            // Initializes your bot service clients and adds a singleton that your Bot can access through dependency injection.
            var connectedServices = InitBotServices(botConfig);

            services.AddSingleton(sp => connectedServices);

            // Initializes bot conversation and user state accessors
            services.AddSingleton(sp =>
            {
                var options = sp.GetRequiredService <IOptions <BotFrameworkOptions> >().Value;

                var conversationState = options.State.OfType <ConversationState>().FirstOrDefault();

                var accessors = new DemoSkillAccessors
                {
                    ConversationDialogState = conversationState.CreateProperty <DialogState>("DemoSkillDialogState"),
                    DemoSkillState          = conversationState.CreateProperty <DemoSkillState>("DemoSkillState"),
                };

                return(accessors);
            });

            // Initialize your MainDialog. This prevents your dialogs from being initialized on every turn.
            // services.AddSingleton(sp => new MainDialog(connectedServices, ) as Dialog);
            services.AddBot <DemoSkill>(options =>
            {
                options.CredentialProvider = new ConfigurationCredentialProvider(Configuration);

                IStorage datastore = new CosmosDbStorage(connectedServices.CosmosDbOptions);
                options.State.Add(new ConversationState(datastore));
                options.Middleware.Add(new AutoSaveStateMiddleware(options.State.ToArray()));
                options.Middleware.Add(new EventDebuggerMiddleware());
            });
        }
Example #3
0
        // Skill Mode Constructor
        public DemoSkill(BotState botState, string stateName = null, Dictionary <string, string> configuration = null)
        {
            // Flag that can be used for Skill specific behaviour (if needed)
            _skillMode = true;

            // Create the properties and populate the Accessors. It's OK to call it DialogState as Skill mode creates an isolated area for this Skill so it doesn't conflict with Parent or other skills
            _accessors = new DemoSkillAccessors
            {
                DemoSkillState          = botState.CreateProperty <DemoSkillState>(stateName ?? nameof(DemoSkillState)),
                ConversationDialogState = botState.CreateProperty <DialogState>("DialogState"),
            };

            if (configuration != null)
            {
                // If LUIS configuration data is passed then this Skill needs to have LUIS available for use internally
                string luisAppId;
                string luisSubscriptionKey;
                string luisEndpoint;

                configuration.TryGetValue("LuisAppId", out luisAppId);
                configuration.TryGetValue("LuisSubscriptionKey", out luisSubscriptionKey);
                configuration.TryGetValue("LuisEndpoint", out luisEndpoint);

                ////if (!string.IsNullOrEmpty(luisAppId) && !string.IsNullOrEmpty(luisSubscriptionKey) && !string.IsNullOrEmpty(luisEndpoint))
                ////{
                ////    LuisApplication luisApplication = new LuisApplication(luisAppId, luisSubscriptionKey, luisEndpoint);

                ////    _services = new DemoSkillServices();
                ////    _services.LuisRecognizer = new Microsoft.Bot.Builder.AI.Luis.LuisRecognizer(luisApplication);
                ////}
            }

            _dialogs   = new DialogSet(_accessors.ConversationDialogState);
            _responder = new DemoSkillResponses();

            RegisterDialogs();
        }