示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ToDoSkill"/> class.
        /// This constructor is used for Skill Activation, the parent Bot shouldn't have knowledge of the internal state workings so we fix this up here (rather than in startup.cs) in normal operation.
        /// </summary>
        /// <param name="botState">The Bot state.</param>
        /// <param name="stateName">The bot state name.</param>
        /// <param name="configuration">The configuration for the bot.</param>
        public ToDoSkill(BotState botState, string stateName = null, Dictionary <string, string> configuration = null)
        {
            // Flag that can be used for Skill specific behaviour (if needed)
            this.skillMode   = true;
            this.toDoService = new ToDoService();

            // 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
            this.toDoSkillAccessors = new ToDoSkillAccessors
            {
                ToDoSkillState          = botState.CreateProperty <ToDoSkillState>(stateName ?? nameof(ToDoSkillState)),
                ConversationDialogState = botState.CreateProperty <DialogState>("DialogState"),
            };

            // Initialise dialogs
            this.dialogs = new DialogSet(this.toDoSkillAccessors.ConversationDialogState);

            if (configuration != null)
            {
                configuration.TryGetValue("LuisAppId", out var luisAppId);
                configuration.TryGetValue("LuisSubscriptionKey", out var luisSubscriptionKey);
                configuration.TryGetValue("LuisEndpoint", out var luisEndpoint);

                if (!string.IsNullOrEmpty(luisAppId) && !string.IsNullOrEmpty(luisSubscriptionKey) && !string.IsNullOrEmpty(luisEndpoint))
                {
                    var luisApplication = new LuisApplication(luisAppId, luisSubscriptionKey, luisEndpoint);
                    this.toDoSkillServices = new ToDoSkillServices
                    {
                        LuisRecognizer = new LuisRecognizer(luisApplication),
                    };
                }
            }

            this.dialogs.Add(new RootDialog(this.skillMode, this.toDoSkillServices, this.toDoSkillAccessors, this.toDoService));
        }
示例#2
0
        /// <summary>
        /// This method gets called by the runtime. Use this method to add services to the container.
        /// </summary>
        /// <param name="services">Service Collection.</param>
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton(sp =>
            {
                var options = sp.GetRequiredService <IOptions <BotFrameworkOptions> >().Value;
                if (options == null)
                {
                    throw new InvalidOperationException("BotFrameworkOptions must be configured prior to setting up the State Accessors");
                }

                var conversationState = options.State.OfType <ConversationState>().FirstOrDefault();
                if (conversationState == null)
                {
                    throw new InvalidOperationException("ConversationState must be defined and added before adding conversation-scoped state accessors.");
                }

                var accessors = new ToDoSkillAccessors
                {
                    ConversationDialogState = conversationState.CreateProperty <DialogState>("ToDoSkillDialogState"),
                    ToDoSkillState          = conversationState.CreateProperty <ToDoSkillState>("ToDoSkillState"),
                };

                return(accessors);
            });

            services.AddSingleton <ToDoSkillServices>(sp =>
            {
                var toDoSkillService                = new ToDoSkillServices();
                var luisModels                      = this.Configuration.GetSection("services").Get <LanguageModel[]>();
                var luis                            = luisModels[0];
                var luisApp                         = new LuisApplication(luis.Id, luis.SubscriptionKey, "https://westus.api.cognitive.microsoft.com");
                toDoSkillService.LuisRecognizer     = new LuisRecognizer(luisApp, null, true);
                var authConnectionNmae              = this.Configuration.GetSection("authConnectionName")?.Value;
                toDoSkillService.AuthConnectionName = authConnectionNmae;
                return(toDoSkillService);
            });

            services.AddTransient <IToDoService, ToDoService>();

            services.AddBot <ToDoSkill>(options =>
            {
                options.CredentialProvider = new ConfigurationCredentialProvider(this.Configuration);

                // Catches any errors that occur during a conversation turn and logs them to AppInsights.
                options.OnTurnError = async(context, exception) =>
                {
                    await context.SendActivityAsync($"ToDoSkill: {exception.Message}");
                    await context.SendActivityAsync(exception.StackTrace);
                };

                var transcriptStore = new AzureBlobTranscriptStore(this.Configuration.GetSection("AzureBlobConnectionString")?.Value, this.Configuration.GetSection("transcriptContainer")?.Value);
                options.Middleware.Add(new TranscriptLoggerMiddleware(transcriptStore));

                IStorage memoryDataStore = new MemoryStorage();
                options.State.Add(new ConversationState(memoryDataStore));
                options.Middleware.Add(new AutoSaveStateMiddleware(options.State.ToArray()));
            });
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ToDoSkill"/> class.
        /// </summary>
        /// <param name="toDoSkillServices">To Do skill service.</param>
        /// <param name="toDoService">To Do provider service.</param>
        /// <param name="toDoSkillAccessors">To Do skill accessors.</param>
        public ToDoSkill(ToDoSkillServices toDoSkillServices, IToDoService toDoService, ToDoSkillAccessors toDoSkillAccessors)
        {
            this.toDoSkillAccessors = toDoSkillAccessors;
            this.toDoService        = toDoService;
            dialogs = new DialogSet(this.toDoSkillAccessors.ConversationDialogState);
            this.toDoSkillServices = toDoSkillServices;

            // Initialise dialogs
            dialogs.Add(new RootDialog(skillMode, this.toDoSkillServices, this.toDoSkillAccessors, this.toDoService));
        }
示例#4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ToDoSkill"/> class.
        /// This constructor is used for Skill Activation, the parent Bot shouldn't have knowledge of the internal state workings so we fix this up here (rather than in startup.cs) in normal operation.
        /// </summary>
        /// <param name="botState">The Bot state.</param>
        /// <param name="stateName">The bot state name.</param>
        /// <param name="configuration">The configuration for the bot.</param>
        public ToDoSkill(BotState botState, string stateName = null, Dictionary <string, string> configuration = null)
        {
            // Flag that can be used for Skill specific behaviour (if needed)
            skillMode         = true;
            toDoService       = new ToDoService();
            toDoSkillServices = new ToDoSkillServices();

            // 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
            toDoSkillAccessors = new ToDoSkillAccessors
            {
                ToDoSkillState          = botState.CreateProperty <ToDoSkillState>(stateName ?? nameof(ToDoSkillState)),
                ConversationDialogState = botState.CreateProperty <DialogState>("DialogState"),
            };

            // Initialise dialogs
            dialogs = new DialogSet(toDoSkillAccessors.ConversationDialogState);
            dialogs.Add(new RootDialog(skillMode, toDoSkillServices, toDoSkillAccessors, toDoService));
        }