Exemplo n.º 1
0
        // Skill Mode Constructor
        public CalendarSkill(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 ServiceManager();

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

            // Initialise dialogs
            _dialogs = new DialogSet(_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);

                    _services = new CalendarSkillServices
                    {
                        LuisRecognizer = new LuisRecognizer(luisApplication),
                    };
                }
            }

            _dialogs.Add(new RootDialog(_skillMode, _services, _accessors, _serviceManager));
        }
Exemplo n.º 2
0
        public SummaryDialog(CalendarSkillServices services, CalendarSkillAccessors accessors, IServiceManager serviceManager)
            : base(Name, services, accessors, serviceManager)
        {
            var showSummary = new WaterfallStep[]
            {
                IfClearContextStep,
                GetAuthToken,
                AfterGetAuthToken,
                ShowEventsSummary,
                PromptToRead,
                CallReadEventDialog,
            };

            var readEvent = new WaterfallStep[]
            {
                ReadEvent,
                AfterReadOutEvent,
            };

            // Define the conversation flow using a waterfall model.
            AddDialog(new WaterfallDialog(Action.ShowEventsSummary, showSummary));
            AddDialog(new WaterfallDialog(Action.Read, readEvent));

            // Set starting dialog for component
            InitialDialogId = Action.ShowEventsSummary;
        }
Exemplo n.º 3
0
        public UpdateEventDialog(CalendarSkillServices services, CalendarSkillAccessors accessors, IServiceManager serviceManager)
            : base(Name, services, accessors, serviceManager)
        {
            var updateEvent = new WaterfallStep[]
            {
                GetAuthToken,
                AfterGetAuthToken,
                FromTokenToStartTime,
                FromEventsToNewDate,
                ConfirmBeforeUpdate,
                UpdateEventTime,
            };

            var updateStartTime = new WaterfallStep[]
            {
                UpdateStartTime,
                AfterUpdateStartTime,
            };

            var updateNewStartTime = new WaterfallStep[]
            {
                GetNewEventTime,
                AfterGetNewEventTime,
            };

            // Define the conversation flow using a waterfall model.
            AddDialog(new WaterfallDialog(Action.UpdateEventTime, updateEvent));
            AddDialog(new WaterfallDialog(Action.UpdateStartTime, updateStartTime));
            AddDialog(new WaterfallDialog(Action.UpdateNewStartTime, updateNewStartTime));

            // Set starting dialog for component
            InitialDialogId = Action.UpdateEventTime;
        }
Exemplo n.º 4
0
        // Local Mode Constructor
        public CalendarSkill(CalendarSkillServices services, CalendarSkillAccessors calendarBotAccessors, IServiceManager serviceManager)
        {
            _accessors      = calendarBotAccessors;
            _serviceManager = serviceManager;
            _dialogs        = new DialogSet(_accessors.ConversationDialogState);
            _services       = services;

            _dialogs.Add(new RootDialog(_skillMode, _services, _accessors, _serviceManager));
        }
Exemplo n.º 5
0
        public RootDialog(bool skillMode, CalendarSkillServices services, CalendarSkillAccessors calendarBotAccessors, IServiceManager serviceManager)
            : base(nameof(RootDialog))
        {
            _skillMode      = skillMode;
            _accessors      = calendarBotAccessors;
            _serviceManager = serviceManager;
            _responder      = new CalendarSkillResponses();
            _services       = services;

            // Initialise dialogs
            RegisterDialogs();
        }
Exemplo n.º 6
0
        public GreetingDialog(CalendarSkillServices services, CalendarSkillAccessors accessors, IServiceManager serviceManager)
            : base(Name, services, accessors, serviceManager)
        {
            var greeting = new WaterfallStep[]
            {
                Greeting,
            };

            // Define the conversation flow using a waterfall model.
            AddDialog(new WaterfallDialog(Action.Greeting, greeting));

            // Set starting dialog for component
            InitialDialogId = Action.Greeting;
        }
Exemplo n.º 7
0
        public NextMeetingDialog(CalendarSkillServices services, CalendarSkillAccessors accessors, IServiceManager serviceManager)
            : base(Name, services, accessors, serviceManager)
        {
            var nextMeeting = new WaterfallStep[]
            {
                GetAuthToken,
                AfterGetAuthToken,
                ShowNextEvent,
            };

            // Define the conversation flow using a waterfall model.
            AddDialog(new WaterfallDialog(Action.ShowEventsSummary, nextMeeting));

            // Set starting dialog for component
            InitialDialogId = Action.ShowEventsSummary;
        }
Exemplo n.º 8
0
        // Skill Mode Constructor
        public CalendarSkill(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 ServiceManager();
            _services       = new CalendarSkillServices();

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

            // Initialise dialogs
            _dialogs = new DialogSet(_accessors.ConversationDialogState);
            _dialogs.Add(new RootDialog(_skillMode, _services, _accessors, _serviceManager));
        }
Exemplo n.º 9
0
        public static async Task <Calendar> GetLuisResult(ITurnContext context, CalendarSkillAccessors accessors, CalendarSkillServices services, CancellationToken cancellationToken)
        {
            var state = await accessors.CalendarSkillState.GetAsync(context);

            Calendar luisResult = null;

            if (state.LuisResultPassedFromSkill != null)
            {
                luisResult = (Calendar)state.LuisResultPassedFromSkill;
            }
            else
            {
                luisResult = await services.LuisRecognizer.RecognizeAsync <Calendar>(context, cancellationToken);
            }

            await DigestCalendarLuisResult(context, accessors, luisResult);

            return(luisResult);
        }
Exemplo n.º 10
0
        public DeleteEventDialog(CalendarSkillServices services, CalendarSkillAccessors accessors, IServiceManager serviceManager)
            : base(Name, services, accessors, serviceManager)
        {
            var deleteEvent = new WaterfallStep[]
            {
                GetAuthToken,
                AfterGetAuthToken,
                FromTokenToStartTime,
                ConfirmBeforeDelete,
                DeleteEventByStartTime,
            };

            var updateStartTime = new WaterfallStep[]
            {
                UpdateStartTime,
                AfterUpdateStartTime,
            };

            AddDialog(new WaterfallDialog(Action.DeleteEvent, deleteEvent));
            AddDialog(new WaterfallDialog(Action.UpdateStartTime, updateStartTime));

            // Set starting dialog for component
            InitialDialogId = Action.DeleteEvent;
        }
Exemplo n.º 11
0
        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 CalendarSkillAccessors
                {
                    ConversationDialogState = conversationState.CreateProperty <DialogState>("CalendarSkillDialogState"),
                    CalendarSkillState      = conversationState.CreateProperty <CalendarSkillState>("CalendarSkillState"),
                };

                return(accessors);
            });

            services.AddSingleton <IServiceManager, ServiceManager>();

            services.AddSingleton <CalendarSkillServices>(sp =>
            {
                var luisModels = this.Configuration.GetSection("services").Get <LanguageModel[]>();

                var luis = luisModels[0];
                var calendarSkillService = new CalendarSkillServices();
                {
                    var luisApp        = new LuisApplication(luis.Id, luis.SubscriptionKey, "https://westus.api.cognitive.microsoft.com");
                    var luisRecognizer = new LuisRecognizer(luisApp);
                    calendarSkillService.LuisRecognizer = luisRecognizer;
                    var authConnectionName = this.Configuration.GetSection("authConnectionName")?.Value;
                    calendarSkillService.AuthConnectionName = authConnectionName;
                }

                return(calendarSkillService);
            });

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

                // Catches any errors that occur during a conversation turn and logs them to AppInsights.
                options.OnTurnError = async(context, exception) =>
                {
                    await context.SendActivityAsync($"CalendarSkill: {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 dataStore = new MemoryStorage();
                options.State.Add(new ConversationState(dataStore));
                options.Middleware.Add(new AutoSaveStateMiddleware(options.State.ToArray()));
            });
        }
Exemplo n.º 12
0
        public CreateEventDialog(CalendarSkillServices services, CalendarSkillAccessors accessors, IServiceManager serviceManager)
            : base(Name, services, accessors, serviceManager)
        {
            var createEvent = new WaterfallStep[]
            {
                GetAuthToken,
                AfterGetAuthToken,
                CollectAttendees,
                CollectTitle,
                CollectContent,
                CollectStartDate,
                CollectStartTime,
                CollectDuration,
                CollectLocation,
                ConfirmBeforeCreate,
                CreateEvent,
            };

            var updateAddress = new WaterfallStep[]
            {
                UpdateAddress,
                AfterUpdateAddress,
            };

            var confirmAttendee = new WaterfallStep[]
            {
                ConfirmAttendee,
                AfterConfirmAttendee,
            };

            var updateName = new WaterfallStep[]
            {
                UpdateUserName,
                AfterUpdateUserName,
            };

            var updateStartDate = new WaterfallStep[]
            {
                UpdateStartDateForCreate,
                AfterUpdateStartDateForCreate,
            };

            var updateStartTime = new WaterfallStep[]
            {
                UpdateStartTimeForCreate,
                AfterUpdateStartTimeForCreate,
            };

            var updateDuration = new WaterfallStep[]
            {
                UpdateDurationForCreate,
                AfterUpdateDurationForCreate,
            };

            // Define the conversation flow using a waterfall model.
            AddDialog(new WaterfallDialog(Action.CreateEvent, createEvent));
            AddDialog(new WaterfallDialog(Action.UpdateAddress, updateAddress));
            AddDialog(new WaterfallDialog(Action.ConfirmAttendee, confirmAttendee));
            AddDialog(new WaterfallDialog(Action.UpdateName, updateName));
            AddDialog(new WaterfallDialog(Action.UpdateStartDateForCreate, updateStartDate));
            AddDialog(new WaterfallDialog(Action.UpdateStartTimeForCreate, updateStartTime));
            AddDialog(new WaterfallDialog(Action.UpdateDurationForCreate, updateDuration));

            // Set starting dialog for component
            InitialDialogId = Action.CreateEvent;
        }
Exemplo n.º 13
0
        /// <summary>
        /// set luis result to conversation state.
        /// </summary>
        /// <param name="context">context.</param>
        /// <param name="accessors">accessors.</param>
        /// <param name="luisResult">LUIS result.</param>
        /// <returns>representing the asynchronous operation.</returns>
        public static async Task DigestCalendarLuisResult(ITurnContext context, CalendarSkillAccessors accessors, Calendar luisResult)
        {
            try
            {
                var state = await accessors.CalendarSkillState.GetAsync(context);

                var entity = luisResult.Entities;

                if (entity.Subject != null)
                {
                    state.Title = entity.Subject[0];
                }

                if (entity.ContactName != null)
                {
                    foreach (var name in entity.ContactName)
                    {
                        if (!state.AttendeesNameList.Contains(name))
                        {
                            state.AttendeesNameList.Add(name);
                        }
                    }
                }

                if (entity.ordinal != null)
                {
                    try
                    {
                        var eventList = state.SummaryEvents;
                        var value     = entity.ordinal[0];
                        var num       = int.Parse(value.ToString());
                        if (eventList != null && num > 0)
                        {
                            var currentList = eventList.GetRange(0, Math.Min(CalendarSkillState.PageSize, eventList.Count));
                            if (num <= currentList.Count)
                            {
                                state.ReadOutEvents.Clear();
                                state.ReadOutEvents.Add(currentList[num - 1]);
                            }
                        }
                    }
                    catch
                    {
                        // ignored
                    }
                }

                if (entity.number != null && entity.ordinal.Length == 0)
                {
                    try
                    {
                        var eventList = state.SummaryEvents;
                        var value     = entity.ordinal[0];
                        var num       = int.Parse(value.ToString());
                        if (eventList != null && num > 0)
                        {
                            var currentList = eventList.GetRange(0, Math.Min(CalendarSkillState.PageSize, eventList.Count));
                            if (num <= currentList.Count)
                            {
                                state.ReadOutEvents.Clear();
                                state.ReadOutEvents.Add(currentList[num - 1]);
                            }
                        }
                    }
                    catch
                    {
                        // ignored
                    }
                }
            }
            catch
            {
                // put log here
            }
        }