コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EmailSkill"/> 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">Services configuration.</param>
        public EmailSkill(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._serviceManager = new MailSkillServiceManager();

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

            // Initialise dialogs.
            this._dialogs = new DialogSet(this._accessors.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._services = new EmailSkillServices()
                    {
                        LuisRecognizer = new LuisRecognizer(luisApplication),
                    };
                }
            }

            this._dialogs.Add(new RootDialog(this._skillMode, this._services, this._accessors, this._serviceManager));
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ForwardEmailDialog"/> class.
        /// </summary>
        /// <param name="services">Email skill services.</param>
        /// <param name="accessors">Email skill accessors.</param>
        /// <param name="serviceManager">Email skill service manager.</param>
        public ForwardEmailDialog(EmailSkillServices services, EmailSkillAccessors accessors, IMailSkillServiceManager serviceManager)
            : base(Name, services, accessors, serviceManager)
        {
            var forwardEmail = new WaterfallStep[]
            {
                this.GetAuthToken,
                this.AfterGetAuthToken,
                this.CollectNameList,
                this.CollectRecipients,
                this.CollectSelectedEmail,
                this.CollectAdditionalText,
                this.ConfirmBeforeSending,
                this.ForwardEmail,
            };

            var showEmail = new WaterfallStep[]
            {
                this.ShowEmails,
            };

            var updateSelectMessage = new WaterfallStep[]
            {
                this.UpdateMessage,
                this.PromptUpdateMessage,
                this.AfterUpdateMessage,
            };

            // Define the conversation flow using a waterfall model.
            this.AddDialog(new WaterfallDialog(Action.Forward, forwardEmail));
            this.AddDialog(new WaterfallDialog(Action.Show, showEmail));
            this.AddDialog(new WaterfallDialog(Action.UpdateSelectMessage, updateSelectMessage));
            this.AddDialog(new ConfirmRecipientDialog(services, accessors, serviceManager));
            this.InitialDialogId = Action.Forward;
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EmailSkill"/> class.
        /// Initializes new instance of EnterpriseBot class - standard constructor for normal Bot invocation.
        /// </summary>
        /// <param name="services">The email skill services.</param>
        /// <param name="emailSkillStateAccessors">The email bot state object.</param>
        /// <param name="serviceManager">The service manager inject into flow to search user and email, etc.</param>
        public EmailSkill(EmailSkillServices services, EmailSkillAccessors emailSkillStateAccessors, IMailSkillServiceManager serviceManager)
        {
            _accessors      = emailSkillStateAccessors;
            _serviceManager = serviceManager;
            _dialogs        = new DialogSet(_accessors.ConversationDialogState);
            _services       = services;

            _dialogs.Add(new RootDialog(_skillMode, _services, _accessors, _serviceManager));
        }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EmailSkill"/> class.
        /// Initializes new instance of EnterpriseBot class - standard constructor for normal Bot invocation.
        /// </summary>
        /// <param name="services">The email skill services.</param>
        /// <param name="emailSkillStateAccessors">The email bot state object.</param>
        /// <param name="serviceManager">The service manager inject into flow to search user and email, etc.</param>
        public EmailSkill(EmailSkillServices services, EmailSkillAccessors emailSkillStateAccessors, IMailSkillServiceManager serviceManager)
        {
            this._accessors      = emailSkillStateAccessors;
            this._serviceManager = serviceManager;
            this._dialogs        = new DialogSet(this._accessors.ConversationDialogState);
            this._services       = services;

            this._dialogs.Add(new RootDialog(this._skillMode, this._services, this._accessors, this._serviceManager));
        }
コード例 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RootDialog"/> class.
        /// </summary>
        /// <param name="skillMode">Skill mode.</param>
        /// <param name="services">Email skill service.</param>
        /// <param name="emailSkillAccessors">Email skill accessors.</param>
        /// <param name="serviceManager">Email provider service.</param>
        public RootDialog(bool skillMode, EmailSkillServices services, EmailSkillAccessors emailSkillAccessors, IMailSkillServiceManager serviceManager)
            : base(nameof(RootDialog))
        {
            this._skillMode      = skillMode;
            this._accessors      = emailSkillAccessors;
            this._serviceManager = serviceManager;
            this._responder      = new EmailSkillResponses();
            this._services       = services;

            // Initialise dialogs
            this.RegisterDialogs();
        }
コード例 #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EmailSkill"/> 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">Services configuration.</param>
        public EmailSkill(BotState botState, string stateName = null, Dictionary <string, string> configuration = null)
        {
            // Flag that can be used for Skill specific behaviour (if needed)
            _skillMode      = true;
            _serviceManager = new MailSkillServiceManager();
            _services       = new EmailSkillServices();

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

            // Initialise dialogs.
            _dialogs = new DialogSet(_accessors.ConversationDialogState);
            _dialogs.Add(new RootDialog(_skillMode, _services, _accessors, _serviceManager));
        }
コード例 #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConfirmRecipientDialog"/> class.
        /// </summary>
        /// <param name="services">Email skill services.</param>
        /// <param name="accessors">Email skill accessors.</param>
        /// <param name="serviceManager">Email skill service manager.</param>
        public ConfirmRecipientDialog(EmailSkillServices services, EmailSkillAccessors accessors, IMailSkillServiceManager serviceManager)
            : base(Name, services, accessors, serviceManager)
        {
            var confirmRecipient = new WaterfallStep[]
            {
                this.ConfirmRecipient,
                this.AfterConfirmRecipient,
            };

            var updateRecipientName = new WaterfallStep[]
            {
                this.UpdateUserName,
                this.AfterUpdateUserName,
            };

            // Define the conversation flow using a waterfall model.
            this.AddDialog(new WaterfallDialog(Action.ConfirmRecipient, confirmRecipient));
            this.AddDialog(new WaterfallDialog(Action.UpdateRecipientName, updateRecipientName));
            this.InitialDialogId = Action.ConfirmRecipient;
        }
コード例 #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SendEmailDialog"/> class.
        /// </summary>
        /// <param name="services">Email skill services.</param>
        /// <param name="accessors">Email skill accessors.</param>
        /// <param name="serviceManager">Email skill service manager.</param>
        public SendEmailDialog(EmailSkillServices services, EmailSkillAccessors accessors, IMailSkillServiceManager serviceManager)
            : base(Name, services, accessors, serviceManager)
        {
            var sendEmail = new WaterfallStep[]
            {
                this.GetAuthToken,
                this.AfterGetAuthToken,
                this.CollectNameList,
                this.CollectRecipients,
                this.CollectSubject,
                this.CollectText,
                this.ConfirmBeforeSending,
                this.SendEmail,
            };

            // Define the conversation flow using a waterfall model.
            this.AddDialog(new WaterfallDialog(Action.Send, sendEmail));
            this.AddDialog(new ConfirmRecipientDialog(services, accessors, serviceManager));
            this.InitialDialogId = Action.Send;
        }
コード例 #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShowEmailDialog"/> class.
        /// </summary>
        /// <param name="services">Email skill services.</param>
        /// <param name="accessors">Email skill accessors.</param>
        /// <param name="serviceManager">Email skill service manager.</param>
        public ShowEmailDialog(EmailSkillServices services, EmailSkillAccessors accessors, IMailSkillServiceManager serviceManager)
            : base(Name, services, accessors, serviceManager)
        {
            var showEmail = new WaterfallStep[]
            {
                this.IfClearContextStep,
                this.GetAuthToken,
                this.AfterGetAuthToken,
                this.ShowEmailsWithOutEnd,
                this.PromptToRead,
                this.CallReadEmailDialog,
            };

            var readEmail = new WaterfallStep[]
            {
                this.ReadEmail,
                this.AfterReadOutEmail,
            };

            // Define the conversation flow using a waterfall model.
            this.AddDialog(new WaterfallDialog(Action.Show, showEmail));
            this.AddDialog(new WaterfallDialog(Action.Read, readEmail));
            this.InitialDialogId = Action.Show;
        }
コード例 #10
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)
        {
            // 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);
            var luisModels = this.Configuration.GetSection("services").Get <LanguageModel[]>();

            var luis = luisModels[0];
            var emailSkillServices = new EmailSkillServices();

            {
                var luisApp        = new LuisApplication(luis.Id, luis.SubscriptionKey, "https://westus.api.cognitive.microsoft.com");
                var luisRecognizer = new LuisRecognizer(luisApp);

                emailSkillServices.LuisRecognizer = luisRecognizer;
            }

            services.AddSingleton(sp => emailSkillServices);

            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 EmailSkillAccessors
                {
                    ConversationDialogState = conversationState.CreateProperty <DialogState>("EmailSkillDialogState"),
                    EmailSkillState         = conversationState.CreateProperty <EmailSkillState>("EmailSkillState"),
                };

                return(accessors);
            });

            services.AddSingleton <IMailSkillServiceManager, MailSkillServiceManager>();

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

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