예제 #1
0
        protected override async Task <DialogTurnResult> OnBeginDialogAsync(DialogContext innerDc, object options, CancellationToken cancellationToken = default)
        {
            if (innerDc.Context.Activity.Type == ActivityTypes.Message)
            {
                // Get cognitive models for the current locale.
                var localizedServices = _services.GetCognitiveModels();

                // Run LUIS recognition and store result in turn state.
                var dispatchResult = await localizedServices.DispatchService.RecognizeAsync <DispatchLuis>(innerDc.Context, cancellationToken);

                innerDc.Context.TurnState.Add(StateProperties.DispatchResult, dispatchResult);

                if (dispatchResult.TopIntent().intent == DispatchLuis.Intent.l_General)
                {
                    // Run LUIS recognition on General model and store result in turn state.
                    var generalResult = await localizedServices.LuisServices["General"].RecognizeAsync <GeneralLuis>(innerDc.Context, cancellationToken);
                    innerDc.Context.TurnState.Add(StateProperties.GeneralResult, generalResult);
                }

                // Check for any interruptions
                var interrupted = await InterruptDialogAsync(innerDc, cancellationToken);

                if (interrupted)
                {
                    // If dialog was interrupted, return EndOfTurn
                    return(EndOfTurn);
                }
            }

            // Set up response caching for "repeat" functionality.
            innerDc.Context.OnSendActivities(StoreOutgoingActivities);
            return(await base.OnBeginDialogAsync(innerDc, options, cancellationToken));
        }
예제 #2
0
        // Runs when the dialog is started.
        protected override async Task <DialogTurnResult> OnBeginDialogAsync(DialogContext innerDc, object options, CancellationToken cancellationToken = default)
        {
            if (innerDc.Context.Activity.Type == ActivityTypes.Message && !string.IsNullOrEmpty(innerDc.Context.Activity.Text))
            {
                // Get cognitive models for the current locale.
                var localizedServices = _services.GetCognitiveModels();

                // Run LUIS recognition on Skill model and store result in turn state.
                var skillResult = await localizedServices.LuisServices["Hospitality"].RecognizeAsync <HospitalityLuis>(innerDc.Context, cancellationToken);
                innerDc.Context.TurnState.Add(StateProperties.SkillLuisResult, skillResult);

                // Run LUIS recognition on General model and store result in turn state.
                var generalResult = await localizedServices.LuisServices["General"].RecognizeAsync <GeneralLuis>(innerDc.Context, cancellationToken);
                innerDc.Context.TurnState.Add(StateProperties.GeneralLuisResult, generalResult);

                // Check for any interruptions
                var interrupted = await InterruptDialogAsync(innerDc, cancellationToken);

                if (interrupted != null)
                {
                    // If dialog was interrupted, return interrupted result
                    return(interrupted);
                }
            }

            return(await base.OnBeginDialogAsync(innerDc, options, cancellationToken));
        }
예제 #3
0
        protected override async Task OnMessageActivityAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
        {
            var state = await _stateAccessor.GetAsync(dc.Context, () => new AutomotiveSkillState());

            // get current activity locale
            var localeConfig = _services.GetCognitiveModels();

            // If dispatch result is general luis model
            localeConfig.LuisServices.TryGetValue("Settings", out var luisService);

            if (luisService == null)
            {
                throw new Exception("The specified LUIS Model could not be found in your Bot Services configuration.");
            }
            else
            {
                var result = await luisService.RecognizeAsync <Luis.SettingsLuis>(dc.Context, CancellationToken.None);

                var intent = result?.TopIntent().intent;

                // Update state with vehicle settings luis result and entities
                state.AddRecognizerResult(result);

                // switch on general intents
                switch (intent)
                {
                case SettingsLuis.Intent.VEHICLE_SETTINGS_CHANGE:
                case SettingsLuis.Intent.VEHICLE_SETTINGS_DECLARATIVE:
                case SettingsLuis.Intent.VEHICLE_SETTINGS_CHECK:
                {
                    await dc.BeginDialogAsync(nameof(VehicleSettingsDialog));

                    break;
                }

                case SettingsLuis.Intent.None:
                {
                    await dc.Context.SendActivityAsync(_responseManager.GetResponse(AutomotiveSkillSharedResponses.DidntUnderstandMessage));

                    break;
                }

                default:
                {
                    await dc.Context.SendActivityAsync(_responseManager.GetResponse(AutomotiveSkillMainResponses.FeatureNotAvailable));

                    break;
                }
                }
            }
        }
예제 #4
0
        // Runs when the dialog is started.
        protected override async Task <DialogTurnResult> OnBeginDialogAsync(DialogContext innerDc, object options, CancellationToken cancellationToken = default)
        {
            // Initialize the PageSize and ReadSize parameters in state from configuration
            var state = await _stateAccessor.GetAsync(innerDc.Context, () => new ToDoSkillState());

            InitializeConfig(state);

            if (innerDc.Context.Activity.Type == ActivityTypes.Message)
            {
                // Get cognitive models for the current locale.
                var localizedServices = _services.GetCognitiveModels();

                // Run LUIS recognition on Skill model and store result in turn state.
                localizedServices.LuisServices.TryGetValue("ToDo", out var skillLuisService);
                if (skillLuisService != null)
                {
                    var skillResult = await skillLuisService.RecognizeAsync <ToDoLuis>(innerDc.Context, cancellationToken);

                    innerDc.Context.TurnState.Add(StateProperties.ToDoLuisResultKey, skillResult);
                }
                else
                {
                    throw new Exception("The skill LUIS Model could not be found in your Bot Services configuration.");
                }

                // Run LUIS recognition on General model and store result in turn state.
                localizedServices.LuisServices.TryGetValue("General", out var generalLuisService);
                if (generalLuisService != null)
                {
                    var generalResult = await generalLuisService.RecognizeAsync <General>(innerDc.Context, cancellationToken);

                    innerDc.Context.TurnState.Add(StateProperties.GeneralLuisResultKey, generalResult);
                }
                else
                {
                    throw new Exception("The general LUIS Model could not be found in your Bot Services configuration.");
                }

                // Check for any interruptions
                var interrupted = await InterruptDialogAsync(innerDc, cancellationToken);

                if (interrupted)
                {
                    // If dialog was interrupted, return EndOfTurn
                    return(EndOfTurn);
                }
            }

            return(await base.OnBeginDialogAsync(innerDc, options, cancellationToken));
        }
        protected override async Task OnMessageActivityAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
        {
            // get current activity locale
            var localeConfig = _services.GetCognitiveModels();

            // Populate state from SemanticAction as required
            await PopulateStateFromSemanticAction(dc.Context);

            // Get skill LUIS model from configuration
            localeConfig.LuisServices.TryGetValue("Event", out var luisService);

            if (luisService == null)
            {
                throw new Exception("The specified LUIS Model could not be found in your Bot Services configuration.");
            }
            else
            {
                var result = await luisService.RecognizeAsync <EventLuis>(dc.Context, CancellationToken.None);

                var intent = result?.TopIntent().intent;

                switch (intent)
                {
                case EventLuis.Intent.FindEvents:
                {
                    // searching for local events
                    await dc.BeginDialogAsync(nameof(FindEventsDialog));

                    break;
                }

                case EventLuis.Intent.None:
                {
                    // No intent was identified, send confused message
                    await dc.Context.SendActivityAsync(_responseManager.GetResponse(SharedResponses.DidntUnderstandMessage));

                    break;
                }

                default:
                {
                    // intent was identified but not yet implemented
                    await dc.Context.SendActivityAsync(_responseManager.GetResponse(MainResponses.FeatureNotAvailable));

                    break;
                }
                }
            }
        }
예제 #6
0
        protected override async Task OnMessageActivityAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
        {
            var state = await _conversationStateAccessor.GetAsync(dc.Context, () => new RestaurantBookingState());

            // get current activity locale
            var localeConfig = _services.GetCognitiveModels();

            // Get skill LUIS model from configuration
            localeConfig.LuisServices.TryGetValue("Restaurant", out var luisService);

            if (luisService == null)
            {
                throw new Exception("The specified LUIS Model could not be found in your Bot Services configuration.");
            }
            else
            {
                var result = await luisService.RecognizeAsync <ReservationLuis>(dc.Context, CancellationToken.None);

                var intent = result?.TopIntent().intent;

                switch (intent)
                {
                case ReservationLuis.Intent.Reservation:
                {
                    await dc.BeginDialogAsync(nameof(BookingDialog));

                    break;
                }

                case ReservationLuis.Intent.None:
                {
                    // No intent was identified, send confused message
                    await dc.Context.SendActivityAsync(_responseManager.GetResponse(RestaurantBookingSharedResponses.DidntUnderstandMessage));

                    break;
                }

                default:
                {
                    // intent was identified but not yet implemented
                    await dc.Context.SendActivityAsync(_responseManager.GetResponse(RestaurantBookingSharedResponses.DidntUnderstandMessage));

                    break;
                }
                }
            }
        }
예제 #7
0
        // Runs when the dialog is started.
        protected override async Task <DialogTurnResult> OnBeginDialogAsync(DialogContext innerDc, object options, CancellationToken cancellationToken = default)
        {
            var activity = innerDc.Context.Activity;

            if (activity.Type == ActivityTypes.Message && !string.IsNullOrEmpty(activity.Text))
            {
                // Get cognitive models for the current locale.
                var localizedServices = _services.GetCognitiveModels();

                // Run LUIS recognition on Skill model and store result in turn state.
                localizedServices.LuisServices.TryGetValue("Event", out var skillLuisService);
                if (skillLuisService != null)
                {
                    var skillResult = await skillLuisService.RecognizeAsync <EventLuis>(innerDc.Context, cancellationToken);

                    innerDc.Context.TurnState.Add(StateProperties.EventLuisResultKey, skillResult);
                }
                else
                {
                    throw new Exception("The skill LUIS Model could not be found in your Bot Services configuration.");
                }

                // Run LUIS recognition on General model and store result in turn state.
                localizedServices.LuisServices.TryGetValue("General", out var generalLuisService);
                if (generalLuisService != null)
                {
                    var generalResult = await generalLuisService.RecognizeAsync <GeneralLuis>(innerDc.Context, cancellationToken);

                    innerDc.Context.TurnState.Add(StateProperties.GeneralLuisResultKey, generalResult);
                }
                else
                {
                    throw new Exception("The general LUIS Model could not be found in your Bot Services configuration.");
                }

                // Check for any interruptions
                var interrupted = await InterruptDialogAsync(innerDc, cancellationToken);

                if (interrupted != null)
                {
                    // If dialog was interrupted, return interrupted result
                    return(interrupted);
                }
            }

            return(await base.OnBeginDialogAsync(innerDc, options, cancellationToken));
        }
예제 #8
0
        protected override async Task <DialogTurnResult> OnBeginDialogAsync(DialogContext innerDc, object options, CancellationToken cancellationToken = default)
        {
            if (innerDc.Context.Activity.Type == ActivityTypes.Message)
            {
                if (innerDc.Context.Activity.Conversation?.IsGroup == true)
                {
                    // Remove bot atmentions for teams/groupchat scope
                    innerDc.Context.Activity.RemoveRecipientMention();

                    // If bot is invoked without any text, reply with FirstPromptMessage
                    if (string.IsNullOrWhiteSpace(innerDc.Context.Activity.Text))
                    {
                        await innerDc.Context.SendActivityAsync(_templateEngine.GenerateActivityForLocale("FirstPromptMessage"));

                        return(EndOfTurn);
                    }
                }

                // Get cognitive models for the current locale.
                var localizedServices = _services.GetCognitiveModels();

                // Run LUIS recognition and store result in turn state.
                var dispatchResult = await localizedServices.DispatchService.RecognizeAsync <DispatchLuis>(innerDc.Context, cancellationToken);

                innerDc.Context.TurnState.Add(StateProperties.DispatchResult, dispatchResult);

                if (dispatchResult.TopIntent().intent == DispatchLuis.Intent.l_General)
                {
                    // Run LUIS recognition on General model and store result in turn state.
                    var generalResult = await localizedServices.LuisServices["General"].RecognizeAsync <GeneralLuis>(innerDc.Context, cancellationToken);
                    innerDc.Context.TurnState.Add(StateProperties.GeneralResult, generalResult);
                }

                // Check for any interruptions
                var interrupted = await InterruptDialogAsync(innerDc, cancellationToken);

                if (interrupted)
                {
                    // If dialog was interrupted, return EndOfTurn
                    return(EndOfTurn);
                }
            }

            // Set up response caching for "repeat" functionality.
            innerDc.Context.OnSendActivities(StoreOutgoingActivities);
            return(await base.OnBeginDialogAsync(innerDc, options, cancellationToken));
        }
예제 #9
0
        public MainDialog(
            IServiceProvider serviceProvider,
            IBotTelemetryClient telemetryClient,
            MicrosoftAppCredentials appCredentials,
            ProactiveState proactiveState)
            : base(nameof(MainDialog), telemetryClient)
        {
            _services       = serviceProvider.GetService <BotServices>();
            _settings       = serviceProvider.GetService <BotSettings>();
            _templateEngine = serviceProvider.GetService <LocaleTemplateEngineManager>();
            TelemetryClient = telemetryClient;

            // Create user state properties
            var userState = serviceProvider.GetService <UserState>();

            _userProfileState = userState.CreateProperty <UserProfileState>(nameof(UserProfileState));
            _skillContext     = userState.CreateProperty <SkillContext>(nameof(SkillContext));

            // Create conversation state properties
            var conversationState = serviceProvider.GetService <ConversationState>();

            _previousResponseAccessor = conversationState.CreateProperty <List <Activity> >(StateProperties.PreviousBotResponse);

            // SAMPLE: Create proactive state properties
            _appCredentials         = appCredentials;
            _proactiveStateAccessor = proactiveState.CreateProperty <ProactiveModel>(nameof(ProactiveModel));

            // Register dialogs
            _onboardingDialog  = serviceProvider.GetService <OnboardingDialog>();
            _switchSkillDialog = serviceProvider.GetService <SwitchSkillDialog>();
            AddDialog(_onboardingDialog);
            AddDialog(_switchSkillDialog);

            // Register a QnAMakerDialog for each registered knowledgebase and ensure localised responses are provided.
            var localizedServices = _services.GetCognitiveModels();

            foreach (var knowledgebase in localizedServices.QnAConfiguration)
            {
                var qnaDialog = new QnAMakerDialog(
                    knowledgeBaseId: knowledgebase.Value.KnowledgeBaseId,
                    endpointKey: knowledgebase.Value.EndpointKey,
                    hostName: knowledgebase.Value.Host,
                    noAnswer: _templateEngine.GenerateActivityForLocale("UnsupportedMessage"),
                    activeLearningCardTitle: _templateEngine.GenerateActivityForLocale("QnaMakerAdaptiveLearningCardTitle").Text,
                    cardNoMatchText: _templateEngine.GenerateActivityForLocale("QnaMakerNoMatchText").Text)
                {
                    Id = knowledgebase.Key
                };
                AddDialog(qnaDialog);
            }

            // Register skill dialogs
            var skillDialogs = serviceProvider.GetServices <SkillDialog>();

            foreach (var dialog in skillDialogs)
            {
                AddDialog(dialog);
            }
        }
예제 #10
0
        protected override async Task <DialogTurnResult> OnContinueDialogAsync(DialogContext innerDc, CancellationToken cancellationToken = default)
        {
            if (innerDc.Context.Activity.Type == ActivityTypes.Message)
            {
                // Get cognitive models for the current locale.
                var localizedServices = _services.GetCognitiveModels();

                // Run LUIS recognition on Skill model and store result in turn state.
                var skillResult = await localizedServices.LuisServices["Hospitality"].RecognizeAsync <HospitalityLuis>(innerDc.Context, cancellationToken);
                innerDc.Context.TurnState.Add(StateProperties.SkillLuisResult, skillResult);

                // Run LUIS recognition on General model and store result in turn state.
                var generalResult = await localizedServices.LuisServices["General"].RecognizeAsync <GeneralLuis>(innerDc.Context, cancellationToken);
                innerDc.Context.TurnState.Add(StateProperties.GeneralLuisResult, generalResult);
            }

            return(await base.OnContinueDialogAsync(innerDc, cancellationToken));
        }
예제 #11
0
        private async Task <DialogTurnResult> TriggerQNA(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var activity = stepContext.Context.Activity.AsMessageActivity();

            //    var userProfile = await _userProfileState.GetAsync(stepContext.Context, () => new VirtualWorkFriendBot.Models.UserProfileState());

            if (!string.IsNullOrEmpty(activity.Text))
            {
                // Get current cognitive models for the current locale.
                var localizedServices = _services.GetCognitiveModels();

                // Get dispatch result from turn state.
                var dispatchResult = stepContext.Context.TurnState.Get <Luis.DispatchLuis>(StateProperties.DispatchResult);
                (var dispatchIntent, var dispatchScore) = dispatchResult.TopIntent();

                if (IsSkillIntent(dispatchIntent))
                {
                    var dispatchIntentSkill = dispatchIntent.ToString();
                    var skillDialogArgs     = new Microsoft.Bot.Solutions.Skills.SkillDialogArgs {
                        SkillId = dispatchIntentSkill
                    };

                    // Start the skill dialog.
                    return(await stepContext.BeginDialogAsync(dispatchIntentSkill, skillDialogArgs));
                }
                else if (dispatchIntent == DispatchLuis.Intent.q_Faq)
                {
                    stepContext.SuppressCompletionMessage(true);

                    return(await stepContext.BeginDialogAsync("Faq"));
                }
                else if (dispatchIntent == DispatchLuis.Intent.q_Chitchat)
                {
                    stepContext.SuppressCompletionMessage(true);

                    return(await stepContext.BeginDialogAsync("Chitchat"));
                }
                else if (dispatchIntent == DispatchLuis.Intent.q_COVID19)
                {
                    stepContext.SuppressCompletionMessage(true);

                    return(await stepContext.BeginDialogAsync("COVID19"));
                }
                else
                {
                    stepContext.SuppressCompletionMessage(true);

                    return(await stepContext.BeginDialogAsync("Faq"));
                }
            }
            else
            {
                return(await stepContext.NextAsync());
            }
        }
예제 #12
0
        public MainDialog(
            IServiceProvider serviceProvider,
            IBotTelemetryClient telemetryClient)
            : base(nameof(MainDialog))
        {
            _services       = serviceProvider.GetService <BotServices>();
            _settings       = serviceProvider.GetService <BotSettings>();
            _templateEngine = serviceProvider.GetService <LocaleTemplateEngineManager>();
            _skillsConfig   = serviceProvider.GetService <SkillsConfiguration>();
            TelemetryClient = telemetryClient;

            var conversationState = serviceProvider.GetService <ConversationState>();

            _previousResponseAccessor = conversationState.CreateProperty <List <Activity> >(StateProperties.PreviousBotResponse);

            var steps = new WaterfallStep[]
            {
                RouteStepAsync,
            };

            AddDialog(new WaterfallDialog(nameof(MainDialog), steps));
            AddDialog(new TextPrompt(nameof(TextPrompt)));
            InitialDialogId = nameof(MainDialog);

            // Register dialogs
            _switchSkillDialog = serviceProvider.GetService <TeamsSwitchSkillDialog>();
            AddDialog(_switchSkillDialog);

            // Register a QnAMakerDialog for each registered knowledgebase and ensure localised responses are provided.
            var localizedServices = _services.GetCognitiveModels();

            foreach (var knowledgebase in localizedServices.QnAConfiguration)
            {
                var qnaDialog = new QnAMakerDialog(
                    knowledgeBaseId: knowledgebase.Value.KnowledgeBaseId,
                    endpointKey: knowledgebase.Value.EndpointKey,
                    hostName: knowledgebase.Value.Host,
                    noAnswer: _templateEngine.GenerateActivityForLocale("UnsupportedMessage"),
                    activeLearningCardTitle: _templateEngine.GenerateActivityForLocale("QnaMakerAdaptiveLearningCardTitle").Text,
                    cardNoMatchText: _templateEngine.GenerateActivityForLocale("QnaMakerNoMatchText").Text)
                {
                    Id = knowledgebase.Key
                };
                AddDialog(qnaDialog);
            }

            // Register skill dialogs
            var skillDialogs = serviceProvider.GetServices <TeamsSkillDialog>();

            foreach (var dialog in skillDialogs)
            {
                AddDialog(dialog);
            }
        }
예제 #13
0
        // Runs on every turn of the conversation to check if the conversation should be interrupted.
        protected async Task <DialogTurnResult> InterruptDialogAsync(DialogContext innerDc, CancellationToken cancellationToken)
        {
            DialogTurnResult interrupted = null;
            var activity = innerDc.Context.Activity;

            if (activity.Type == ActivityTypes.Message && !string.IsNullOrEmpty(activity.Text))
            {
                // Get connected LUIS result from turn state.
                // Get cognitive models for the current locale.
                var localizedServices = _services.GetCognitiveModels();

                // Run LUIS recognition on General model and store result in turn state.
                localizedServices.LuisServices.TryGetValue("General", out var generalLuisService);
                if (generalLuisService == null)
                {
                    throw new Exception("The general LUIS Model could not be found in your Bot Services configuration.");
                }

                var generalResult = await generalLuisService.RecognizeAsync <General>(innerDc.Context, cancellationToken);

                (var generalIntent, var generalScore) = generalResult.TopIntent();

                if (generalScore > 0.5)
                {
                    switch (generalIntent)
                    {
                    case General.Intent.Cancel:
                    {
                        await innerDc.Context.SendActivityAsync(_templateManager.GenerateActivity(MainResponses.CancelMessage), cancellationToken);

                        await innerDc.CancelAllDialogsAsync(cancellationToken);

                        if (innerDc.Context.IsSkill())
                        {
                            var state = await _stateAccessor.GetAsync(innerDc.Context, () => new SkillState(), cancellationToken : cancellationToken);

                            interrupted = await innerDc.EndDialogAsync(state.IsAction?new ActionResult(false) : null, cancellationToken : cancellationToken);
                        }
                        else
                        {
                            interrupted = await innerDc.BeginDialogAsync(InitialDialogId, cancellationToken : cancellationToken);
                        }

                        break;
                    }

                    case General.Intent.Help:
                    {
                        await innerDc.Context.SendActivityAsync(_templateManager.GenerateActivity(MainResponses.HelpMessage), cancellationToken);

                        await innerDc.RepromptDialogAsync(cancellationToken);

                        interrupted = EndOfTurn;
                        break;
                    }
                    }
                }
            }

            return(interrupted);
        }
        protected override async Task OnMessageActivityAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
        {
            var state = await _toDoStateAccessor.GetAsync(dc.Context, () => new ToDoSkillState());

            // get current activity locale
            var localeConfig = _services.GetCognitiveModels();

            // Initialize the PageSize and ReadSize parameters in state from configuration
            InitializeConfig(state);

            // If dispatch result is general luis model
            localeConfig.LuisServices.TryGetValue("ToDo", out var luisService);

            if (luisService == null)
            {
                throw new Exception("The specified LUIS Model could not be found in your Bot Services configuration.");
            }
            else
            {
                var intent           = state.LuisResult?.TopIntent().intent;
                var generalTopIntent = state.GeneralLuisResult?.TopIntent().intent;

                // switch on general intents
                switch (intent)
                {
                case ToDoLuis.Intent.AddToDo:
                {
                    await dc.BeginDialogAsync(nameof(AddToDoItemDialog));

                    break;
                }

                case ToDoLuis.Intent.MarkToDo:
                {
                    await dc.BeginDialogAsync(nameof(MarkToDoItemDialog));

                    break;
                }

                case ToDoLuis.Intent.DeleteToDo:
                {
                    await dc.BeginDialogAsync(nameof(DeleteToDoItemDialog));

                    break;
                }

                case ToDoLuis.Intent.ShowNextPage:
                case ToDoLuis.Intent.ShowPreviousPage:
                case ToDoLuis.Intent.ShowToDo:
                {
                    await dc.BeginDialogAsync(nameof(ShowToDoItemDialog));

                    break;
                }

                case ToDoLuis.Intent.None:
                {
                    if (generalTopIntent == General.Intent.ShowNext ||
                        generalTopIntent == General.Intent.ShowPrevious)
                    {
                        await dc.BeginDialogAsync(nameof(ShowToDoItemDialog));
                    }
                    else
                    {
                        // No intent was identified, send confused message
                        await dc.Context.SendActivityAsync(_responseManager.GetResponse(ToDoMainResponses.DidntUnderstandMessage));
                    }

                    break;
                }

                default:
                {
                    // intent was identified but not yet implemented
                    await dc.Context.SendActivityAsync(_responseManager.GetResponse(ToDoMainResponses.FeatureNotAvailable));

                    break;
                }
                }
            }
        }
예제 #15
0
        public MainDialog(
            IServiceProvider serviceProvider,
            IBotTelemetryClient telemetryClient
            )
            : base(nameof(MainDialog))
        {
            _services        = serviceProvider.GetService <BotServices>();
            _settings        = serviceProvider.GetService <BotSettings>();
            _templateManager = serviceProvider.GetService <LocaleTemplateManager>();
            _skillsConfig    = serviceProvider.GetService <SkillsConfiguration>();
            _feedbackOptions = serviceProvider.GetService <FeedbackOptions>();
            TelemetryClient  = telemetryClient;

            var userState = serviceProvider.GetService <UserState>();

            _userProfileState = userState.CreateProperty <UserProfileState>(nameof(UserProfileState));

            var conversationState = serviceProvider.GetService <ConversationState>();

            _previousResponseAccessor = conversationState.CreateProperty <List <Activity> >(StateProperties.PreviousBotResponse);
            _feedbackAccessor         = conversationState.CreateProperty <FeedbackRecord>(nameof(FeedbackRecord));

            var steps = new List <WaterfallStep>()
            {
                OnboardingStepAsync,
                IntroStepAsync,
                RouteStepAsync,
            };

            if (_feedbackOptions.FeedbackEnabled)
            {
                steps.Add(RequestFeedback);
                steps.Add(RequestFeedbackComment);
                steps.Add(ProcessFeedback);
                AddDialog(new TextPrompt(DialogIds.FeedbackPrompt));
                AddDialog(new TextPrompt(DialogIds.FeedbackCommentPrompt));
            }
            steps.Add(FinalStepAsync);

            AddDialog(new WaterfallDialog(nameof(MainDialog), steps));
            AddDialog(new TextPrompt(DialogIds.NextActionPrompt));
            InitialDialogId = nameof(MainDialog);

            // Register dialogs
            _onboardingDialog  = serviceProvider.GetService <OnboardingDialog>();
            _switchSkillDialog = serviceProvider.GetService <SwitchSkillDialog>();
            AddDialog(_onboardingDialog);
            AddDialog(_switchSkillDialog);

            // Register a QnAMakerDialog for each registered knowledgebase and ensure localised responses are provided.
            var localizedServices = _services.GetCognitiveModels();

            foreach (var knowledgebase in localizedServices.QnAConfiguration)
            {
                var qnaDialog = new QnAMakerDialog(
                    knowledgeBaseId: knowledgebase.Value.KnowledgeBaseId,
                    endpointKey: knowledgebase.Value.EndpointKey,
                    hostName: knowledgebase.Value.Host,
                    noAnswer: _templateManager.GenerateActivityForLocale("UnsupportedMessage"),
                    activeLearningCardTitle: _templateManager.GenerateActivityForLocale("QnaMakerAdaptiveLearningCardTitle").Text,
                    cardNoMatchText: _templateManager.GenerateActivityForLocale("QnaMakerNoMatchText").Text)
                {
                    Id = knowledgebase.Key
                };
                AddDialog(qnaDialog);
            }

            // Register skill dialogs
            var skillDialogs = serviceProvider.GetServices <SkillDialog>();

            foreach (var dialog in skillDialogs)
            {
                AddDialog(dialog);
            }
        }
예제 #16
0
        public VehicleSettingsDialog(
            BotSettings settings,
            BotServices services,
            ResponseManager responseManager,
            ConversationState conversationState,
            IBotTelemetryClient telemetryClient,
            IHttpContextAccessor httpContext)
            : base(nameof(VehicleSettingsDialog), settings, services, responseManager, conversationState, telemetryClient)
        {
            TelemetryClient = telemetryClient;

            var localeConfig = services.GetCognitiveModels();

            // Initialise supporting LUIS models for followup questions
            vehicleSettingNameSelectionLuisRecognizer  = localeConfig.LuisServices["SettingsName"];
            vehicleSettingValueSelectionLuisRecognizer = localeConfig.LuisServices["SettingsValue"];

            // Initialise supporting LUIS models for followup questions
            vehicleSettingNameSelectionLuisRecognizer  = localeConfig.LuisServices["SettingsName"];
            vehicleSettingValueSelectionLuisRecognizer = localeConfig.LuisServices["SettingsValue"];

            // Supporting setting files are stored as embedded resources
            var resourceAssembly = typeof(VehicleSettingsDialog).Assembly;

            var settingFile = resourceAssembly
                              .GetManifestResourceNames()
                              .Where(x => x.Contains(AvailableSettingsFileName))
                              .First();

            var alternativeSettingFileName = resourceAssembly
                                             .GetManifestResourceNames()
                                             .Where(x => x.Contains(AlternativeSettingsFileName))
                                             .First();

            if (string.IsNullOrEmpty(settingFile) || string.IsNullOrEmpty(alternativeSettingFileName))
            {
                throw new FileNotFoundException($"Unable to find Available Setting and/or Alternative Names files in \"{resourceAssembly.FullName}\" assembly.");
            }

            settingList   = new SettingList(resourceAssembly, settingFile, alternativeSettingFileName);
            settingFilter = new SettingFilter(settingList);

            // Setting Change waterfall
            var processVehicleSettingChangeWaterfall = new WaterfallStep[]
            {
                ProcessSetting,
                ProcessVehicleSettingsChange,
                ProcessChange,
                SendChange
            };

            AddDialog(new WaterfallDialog(Actions.ProcessVehicleSettingChange, processVehicleSettingChangeWaterfall)
            {
                TelemetryClient = telemetryClient
            });

            // Prompts
            AddDialog(new ChoicePrompt(Actions.SettingNameSelectionPrompt, SettingNameSelectionValidator, Culture.English)
            {
                Style = ListStyle.Auto, ChoiceOptions = new ChoiceFactoryOptions {
                    InlineSeparator = string.Empty, InlineOr = string.Empty, InlineOrMore = string.Empty, IncludeNumbers = true
                }
            });
            AddDialog(new ChoicePrompt(Actions.SettingValueSelectionPrompt, SettingValueSelectionValidator, Culture.English)
            {
                Style = ListStyle.Auto, ChoiceOptions = new ChoiceFactoryOptions {
                    InlineSeparator = string.Empty, InlineOr = string.Empty, InlineOrMore = string.Empty, IncludeNumbers = true
                }
            });

            AddDialog(new ConfirmPrompt(Actions.SettingConfirmationPrompt));

            // Set starting dialog for component
            InitialDialogId = Actions.ProcessVehicleSettingChange;

            // Used to resolve image paths (local or hosted)
            _httpContext = httpContext;
        }
예제 #17
0
        public MainDialog(
            IServiceProvider serviceProvider,
            IBotTelemetryClient telemetryClient)
            : base(nameof(MainDialog), serviceProvider, telemetryClient)
        {
            _services       = serviceProvider.GetService <BotServices>();
            _settings       = serviceProvider.GetService <BotSettings>();
            _templateEngine = serviceProvider.GetService <LocaleTemplateEngineManager>();
            _skillsConfig   = serviceProvider.GetService <SkillsConfiguration>();

            var userState = serviceProvider.GetService <UserState>();

            _userProfileState = userState.CreateProperty <UserProfileState>(nameof(UserProfileState));
            var conversationState = serviceProvider.GetService <ConversationState>();

            _previousResponseAccessor = conversationState.CreateProperty <List <Activity> >(StateProperties.PreviousBotResponse);

            WaterfallStep[] steps = SetupWaterfallSteps();

            AddDialog(new WaterfallDialog(nameof(MainDialog), steps));
            AddDialog(new TextPrompt(nameof(TextPrompt)));
            AddDialog(new ChoicePrompt(nameof(ChoicePrompt))
            {
                Style = ListStyle.HeroCard
            });
            InitialDialogId = nameof(MainDialog);

            // Register dialogs
            _oauthPrompt              = serviceProvider.GetService <OAuthPrompt>();
            _loginDialog              = serviceProvider.GetService <LoginDialog>();
            _onboardingDialog         = serviceProvider.GetService <OnboardingDialog>();
            _switchSkillDialog        = serviceProvider.GetService <SwitchSkillDialog>();
            _escalateDialog           = serviceProvider.GetService <EscalateDialog>();
            _cancelDialog             = serviceProvider.GetService <CancelDialog>();
            _entertainDialog          = serviceProvider.GetService <EntertainDialog>();
            _chitchatdialog           = serviceProvider.GetService <ChitchatDialog>();
            _stressDialog             = serviceProvider.GetService <StressDialog>();
            _highstresshandlingDialog = serviceProvider.GetService <HighStressHandlingDialog>();
            _stresshandlingDialog     = serviceProvider.GetService <StressHandlingDialog>();
            _journalingDialog         = serviceProvider.GetService <JournalingDialog>();

            AddDialog(_oauthPrompt);
            AddDialog(_loginDialog);
            AddDialog(_onboardingDialog);
            AddDialog(_switchSkillDialog);
            AddDialog(_escalateDialog);
            AddDialog(_cancelDialog);
            AddDialog(_entertainDialog);
            AddDialog(_chitchatdialog);
            AddDialog(_stressDialog);
            AddDialog(_highstresshandlingDialog);
            AddDialog(_stresshandlingDialog);
            AddDialog(_journalingDialog);



            // Register a QnAMakerDialog for each registered knowledgebase and ensure localised responses are provided.
            var localizedServices = _services.GetCognitiveModels();

            foreach (var knowledgebase in localizedServices.QnAConfiguration)
            {
                var qnaDialog = new QnAMakerDialog(
                    knowledgeBaseId: knowledgebase.Value.KnowledgeBaseId,
                    endpointKey: knowledgebase.Value.EndpointKey,
                    hostName: knowledgebase.Value.Host,
                    noAnswer: _templateEngine.GenerateActivityForLocale("UnsupportedMessage"),
                    activeLearningCardTitle: _templateEngine.GenerateActivityForLocale("QnaMakerAdaptiveLearningCardTitle").Text,
                    cardNoMatchText: _templateEngine.GenerateActivityForLocale("QnaMakerNoMatchText").Text)
                {
                    Id = knowledgebase.Key
                };
                AddDialog(qnaDialog);
            }

            // Register skill dialogs
            var skillDialogs = serviceProvider.GetServices <SkillDialog>();

            foreach (var dialog in skillDialogs)
            {
                AddDialog(dialog);
            }
        }
예제 #18
0
        protected override async Task OnMessageActivityAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
        {
            // get current activity locale
            var localeConfig = _services.GetCognitiveModels();

            // Populate state from SemanticAction as required
            await PopulateStateFromSemanticAction(dc.Context);

            // Get skill LUIS model from configuration
            localeConfig.LuisServices.TryGetValue("ITSM", out var luisService);

            if (luisService == null)
            {
                throw new Exception("The specified LUIS Model could not be found in your Bot Services configuration.");
            }
            else
            {
                var result = await luisService.RecognizeAsync <ITSMLuis>(dc.Context, CancellationToken.None);

                var intent = result?.TopIntent().intent;

                if (intent != null && intent != ITSMLuis.Intent.None)
                {
                    var state = await _stateAccessor.GetAsync(dc.Context, () => new SkillState());

                    state.DigestLuisResult(result, (ITSMLuis.Intent)intent);
                }

                switch (intent)
                {
                case ITSMLuis.Intent.TicketCreate:
                {
                    await dc.BeginDialogAsync(nameof(CreateTicketDialog));

                    break;
                }

                case ITSMLuis.Intent.TicketUpdate:
                {
                    await dc.BeginDialogAsync(nameof(UpdateTicketDialog));

                    break;
                }

                case ITSMLuis.Intent.TicketShow:
                {
                    await dc.BeginDialogAsync(nameof(ShowTicketDialog));

                    break;
                }

                case ITSMLuis.Intent.TicketClose:
                {
                    await dc.BeginDialogAsync(nameof(CloseTicketDialog));

                    break;
                }

                case ITSMLuis.Intent.KnowledgeShow:
                {
                    await dc.BeginDialogAsync(nameof(ShowKnowledgeDialog));

                    break;
                }

                case ITSMLuis.Intent.None:
                {
                    // No intent was identified, send confused message
                    await dc.Context.SendActivityAsync(_responseManager.GetResponse(SharedResponses.DidntUnderstandMessage));

                    break;
                }

                default:
                {
                    // intent was identified but not yet implemented
                    await dc.Context.SendActivityAsync(_responseManager.GetResponse(MainResponses.FeatureNotAvailable));

                    break;
                }
                }
            }
        }