Exemple #1
0
        // Skill Mode Constructor
        public PointOfInterestSkill(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();
            _configuration  = configuration;
            _services       = new PointOfInterestSkillServices();

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

            // Initialise dialogs
            _dialogs = new DialogSet(_accessors.ConversationDialogState);

            if (configuration != null)
            {
                configuration.TryGetValue("AzureMapsKey", out var azureMapsKey);

                if (!string.IsNullOrEmpty(azureMapsKey))
                {
                    _services.AzureMapsKey = azureMapsKey;
                }
            }

            _dialogs.Add(new RootDialog(_skillMode, _services, _accessors, _serviceManager));
        }
Exemple #2
0
        public PointOfInterestSkillDialog(string dialogId, PointOfInterestSkillServices services, PointOfInterestSkillAccessors accessors, IServiceManager serviceManager)
            : base(dialogId)
        {
            _services       = services;
            _accessors      = accessors;
            _serviceManager = serviceManager;

            AddDialog(new TextPrompt(Action.Prompt, CustomPromptValidatorAsync));
        }
Exemple #3
0
        // Local Mode Constructor
        public PointOfInterestSkill(PointOfInterestSkillServices services, PointOfInterestSkillAccessors pointOfInterestSkillAccessors, IServiceManager serviceManager)
        {
            _accessors      = pointOfInterestSkillAccessors;
            _serviceManager = serviceManager;
            _dialogs        = new DialogSet(_accessors.ConversationDialogState);
            _services       = services;

            _dialogs.Add(new RootDialog(_skillMode, _services, _accessors, _serviceManager));
        }
Exemple #4
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 PointOfInterestSkillAccessors
                {
                    ConversationDialogState   = conversationState.CreateProperty <DialogState>("PointOfInterestSkillDialogState"),
                    PointOfInterestSkillState = conversationState.CreateProperty <PointOfInterestSkillState>("PointOfInterestSkillState"),
                };

                return(accessors);
            });

            services.AddSingleton <PointOfInterestSkillServices>(sp =>
            {
                var pointOfInterestSkillService = new PointOfInterestSkillServices();
                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");
                pointOfInterestSkillService.LuisRecognizer = new LuisRecognizer(luisApp, null, true);
                return(pointOfInterestSkillService);
            });

            services.AddSingleton <IServiceManager, ServiceManager>();

            services.AddBot <PointOfInterestSkill>(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($"PointOfInterestSkill: {exception.Message}");
                    await context.SendActivityAsync(exception.StackTrace);
                };

                IStorage dataStore = new MemoryStorage();
                options.State.Add(new ConversationState(dataStore));
                options.Middleware.Add(new EventDebuggerMiddleware());
                options.Middleware.Add(new AutoSaveStateMiddleware(options.State.ToArray()));
            });
        }
Exemple #5
0
        public RootDialog(bool skillMode, PointOfInterestSkillServices services, PointOfInterestSkillAccessors pointOfInterestSkillAccessors, IServiceManager serviceManager)
            : base(nameof(RootDialog))
        {
            _skillMode      = skillMode;
            _accessors      = pointOfInterestSkillAccessors;
            _serviceManager = serviceManager;
            _responder      = new PointOfInterestSkillResponses();
            _services       = services;

            // Initialize dialogs
            RegisterDialogs();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FindPointOfInterestDialog"/> class.
        /// </summary>
        /// <param name="accessors">Steps used in dialog.</param>
        /// <param name="serviceManager">Service manager.</param>
        public FindPointOfInterestDialog(PointOfInterestSkillServices services, PointOfInterestSkillAccessors accessors, IServiceManager serviceManager)
            : base(nameof(FindPointOfInterestDialog), services, accessors, serviceManager)
        {
            _accessors      = accessors;
            _serviceManager = serviceManager;

            var findPointOfInterest = new WaterfallStep[]
            {
                GetPointOfInterestLocations,
            };

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

            // Set starting dialog for component
            InitialDialogId = Action.FindPointOfInterest;
        }
Exemple #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CancelRouteDialog"/> class.
        /// </summary>
        /// <param name="accessors">Steps used in dialog.</param>
        /// <param name="serviceManager">Service manager.</param>
        public CancelRouteDialog(PointOfInterestSkillServices services, PointOfInterestSkillAccessors accessors, IServiceManager serviceManager)
            : base(nameof(CancelRouteDialog), services, accessors, serviceManager)
        {
            _accessors      = accessors;
            _serviceManager = serviceManager;

            var cancelRoute = new WaterfallStep[]
            {
                CancelActiveRoute,
            };

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

            // Set starting dialog for component
            InitialDialogId = Action.CancelActiveRoute;
        }
Exemple #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RouteDialog"/> class.
        /// </summary>
        /// <param name="accessors">Steps used in dialog.</param>
        /// <param name="serviceManager">Service manager.</param>
        public RouteDialog(PointOfInterestSkillServices services, PointOfInterestSkillAccessors accessors, IServiceManager serviceManager)
            : base(nameof(RouteDialog), services, accessors, serviceManager)
        {
            _accessors      = accessors;
            _serviceManager = serviceManager;

            var checkForActiveRouteAndLocation = new WaterfallStep[]
            {
                CheckIfActiveRouteExists,
                CheckIfFoundLocationExists,
                CheckIfActiveLocationExists,
            };

            var findRouteToActiveLocation = new WaterfallStep[]
            {
                GetRoutesToActiveLocation,
                ResponseToStartRoutePrompt,
            };

            var findAlongRoute = new WaterfallStep[]
            {
                GetPointOfInterestLocations,
                ResponseToGetRoutePrompt
            };

            var findPointOfInterest = new WaterfallStep[]
            {
                GetPointOfInterestLocations,
            };

            // Define the conversation flow using a waterfall model.
            AddDialog(new WaterfallDialog(Action.GetActiveRoute, checkForActiveRouteAndLocation));
            AddDialog(new WaterfallDialog(Action.FindAlongRoute, findAlongRoute));
            AddDialog(new WaterfallDialog(Action.FindRouteToActiveLocation, findRouteToActiveLocation));
            AddDialog(new WaterfallDialog(Action.FindPointOfInterest, findPointOfInterest));

            // Set starting dialog for component
            InitialDialogId = Action.GetActiveRoute;
        }