public MainDialog(
            IServiceProvider serviceProvider)
            : base(nameof(MainDialog))
        {
            _services        = serviceProvider.GetService <BotServices>();
            _templateManager = serviceProvider.GetService <LocaleTemplateManager>();
            _skillsConfig    = serviceProvider.GetService <SkillsConfiguration>();
            _feedbackOptions = serviceProvider.GetService <FeedbackOptions>();
            TelemetryClient  = serviceProvider.GetService <IBotTelemetryClient>();

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

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

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

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

            // Create state property to track the active skill.
            _activeSkillProperty = conversationState.CreateProperty <BotFrameworkSkill>(ActiveSkillPropertyName);
            _feedbackAccessor    = conversationState.CreateProperty <FeedbackRecord>(nameof(FeedbackRecord));

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

            // Add FeedbackSteps
            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(nameof(TextPrompt)));
            InitialDialogId = nameof(MainDialog);

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

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

            foreach (var dialog in skillDialogs)
            {
                AddDialog(dialog);
            }
        }
Exemple #2
0
        public RootBot(ConversationState conversationState, SkillsConfiguration skillsConfig, SkillHttpClient skillClient, IConfiguration configuration)
        {
            _conversationState = conversationState ?? throw new ArgumentNullException(nameof(conversationState));
            _skillsConfig      = skillsConfig ?? throw new ArgumentNullException(nameof(skillsConfig));
            _skillClient       = skillClient ?? throw new ArgumentNullException(nameof(skillsConfig));
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            _botId = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value;
            if (string.IsNullOrWhiteSpace(_botId))
            {
                throw new ArgumentException($"{MicrosoftAppCredentials.MicrosoftAppIdKey} is not set in configuration");
            }

            // We use a single skill in this example.
            var targetSkillId = "EchoSkillBot";

            if (!_skillsConfig.Skills.TryGetValue(targetSkillId, out _targetSkill))
            {
                throw new ArgumentException($"Skill with ID \"{targetSkillId}\" not found in configuration");
            }

            // Create state property to track the active skill
            _activeSkillProperty = conversationState.CreateProperty <BotFrameworkSkill>("activeSkillProperty");
        }
        public DefaultAdapter(
            BotSettings settings,
            ICredentialProvider credentialProvider,
            IChannelProvider channelProvider,
            AuthenticationConfiguration authConfig,
            LocaleTemplateManager templateEngine,
            ConversationState conversationState,
            TelemetryInitializerMiddleware telemetryMiddleware,
            IBotTelemetryClient telemetryClient,
            ILogger <BotFrameworkHttpAdapter> logger,
            SkillsConfiguration skillsConfig = null,
            SkillHttpClient skillClient      = null)
            : base(credentialProvider, authConfig, channelProvider, logger: logger)
        {
            _conversationState = conversationState ?? throw new ArgumentNullException(nameof(conversationState));
            _logger            = logger ?? throw new ArgumentNullException(nameof(logger));
            _templateEngine    = templateEngine ?? throw new ArgumentNullException(nameof(templateEngine));
            _telemetryClient   = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient));
            _skillClient       = skillClient;
            _skillsConfig      = skillsConfig;
            _settings          = settings;

            OnTurnError = HandleTurnErrorAsync;

            Use(telemetryMiddleware);

            // Uncomment the following line for local development without Azure Storage
            // Use(new TranscriptLoggerMiddleware(new MemoryTranscriptStore()));
            Use(new TranscriptLoggerMiddleware(new AzureBlobTranscriptStore(settings.BlobStorage.ConnectionString, settings.BlobStorage.Container)));
            Use(new ShowTypingMiddleware());
            Use(new SetLocaleMiddleware(settings.DefaultLocale ?? "en-us"));
            Use(new EventDebuggerMiddleware());
            Use(new SetSpeakMiddleware());
        }
        // Dependency injection uses this constructor to instantiate MainDialog.
        public MainDialog(ConversationState conversationState, SkillConversationIdFactoryBase conversationIdFactory, SkillHttpClient skillClient, SkillsConfiguration skillsConfig, IConfiguration configuration)
            : base(nameof(MainDialog))
        {
            _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));

            var botId = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value;

            _skillsConfig = skillsConfig ?? throw new ArgumentNullException(nameof(skillsConfig));

            if (skillClient == null)
            {
                throw new ArgumentNullException(nameof(skillClient));
            }

            if (conversationState == null)
            {
                throw new ArgumentNullException(nameof(conversationState));
            }

            // Create state property to track the active skill.
            _activeSkillProperty = conversationState.CreateProperty <BotFrameworkSkill>(ActiveSkillPropertyName);

            // Register the tangent dialog for testing tangents and resume
            AddDialog(new TangentDialog());

            // Create and add SkillDialog instances for the configured skills.
            AddSkillDialogs(conversationState, conversationIdFactory, skillClient, skillsConfig, botId);

            // Add ChoicePrompt to render available delivery modes.
            AddDialog(new ChoicePrompt("DeliveryModePrompt"));

            // Add ChoicePrompt to render available groups of skills.
            AddDialog(new ChoicePrompt("SkillGroupPrompt"));

            // Add ChoicePrompt to render available skills.
            AddDialog(new ChoicePrompt("SkillPrompt"));

            // Add ChoicePrompt to render skill actions.
            AddDialog(new ChoicePrompt("SkillActionPrompt"));

            // Special case: register SSO dialogs for skills that support SSO actions.
            AddSsoDialogs(configuration);

            // Add main waterfall dialog for this bot.
            var waterfallSteps = new WaterfallStep[]
            {
                SelectDeliveryModeStepAsync,
                SelectSkillGroupStepAsync,
                SelectSkillStepAsync,
                SelectSkillActionStepAsync,
                CallSkillActionStepAsync,
                FinalStepAsync
            };

            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), waterfallSteps));

            // The initial child Dialog to run.
            InitialDialogId = nameof(WaterfallDialog);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AllowedSkillsClaimsValidator"/> class.
        /// Loads the appIds for the configured skills. Only allows responses from skills it has configured.
        /// </summary>
        /// <param name="skillsConfig">The list of configured skills.</param>
        public AllowedSkillsClaimsValidator(SkillsConfiguration skillsConfig)
        {
            if (skillsConfig == null)
            {
                throw new ArgumentNullException(nameof(skillsConfig));
            }

            _allowedSkills = (from skill in skillsConfig.Skills.Values select skill.AppId).ToList();
        }
Exemple #6
0
        public AllowedCallersClaimsValidator(SkillsConfiguration skillsConfig)
        {
            if (skillsConfig == null)
            {
                throw new ArgumentNullException(nameof(skillsConfig));
            }

            // Load the appIds for the configured skills (we will only allow responses from skills we have configured).
            _allowedSkills = (from skill in skillsConfig.Skills.Values select skill.AppId).ToList();
        }
Exemple #7
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);
            }
        }
        public void MissingSkillEndpointUrlThrows()
        {
            var config = GetConfig("configSettings_missingSkillEndpointUrl.json");

            var ex = Assert.ThrowsException <InvalidOperationException>(
                () =>
            {
                var skillsConfig = new SkillsConfiguration(config);
            }, "Should have thrown: Skill in appsettings is missing 'endpointUrl'.");

            Assert.AreEqual("Skill in appsettings is missing 'endpointUrl'.", ex.Message);
        }
Exemple #9
0
 // Helper to create a SkillDialogOptions instance for the SSO skill.
 private SkillDialogOptions CreateSkillDialogOptions(SkillsConfiguration skillsConfig, string botId, SkillConversationIdFactoryBase conversationIdFactory, ConversationState conversationState)
 {
     return(new SkillDialogOptions
     {
         BotId = botId,
         ConversationIdFactory = conversationIdFactory,
         SkillClient = _auth.CreateBotFrameworkClient(),
         SkillHostEndpoint = skillsConfig.SkillHostEndpoint,
         ConversationState = conversationState,
         Skill = _ssoSkill,
     });
 }
 public DefaultActivityHandler(IServiceProvider serviceProvider, T dialog, string appId)
 {
     _dialog              = dialog;
     _conversationState   = serviceProvider.GetService <ConversationState>();
     _dialogStateAccessor = _conversationState.CreateProperty <DialogState>(nameof(DialogState));
     _templateEngine      = serviceProvider.GetService <LocaleTemplateEngineManager>();
     _skillHttpClient     = serviceProvider.GetService <SkillHttpClient>();
     _skillsConfig        = serviceProvider.GetService <SkillsConfiguration>();
     _telemetryClient     = serviceProvider.GetService <IBotTelemetryClient>();
     this._appId          = appId;
     _composeExtensionCommandIdSeparator = ":";
 }
        public void MissingSkillsThrows()
        {
            var config = GetConfig("configSettings_missingSkills.json");

            var ex = Assert.ThrowsException <InvalidOperationException>(
                () =>
            {
                var skillsConfig = new SkillsConfiguration(config);
            }, "Should have thrown: Missing 'skill' section in appsettings.");

            Assert.AreEqual("Missing 'skill' section in appsettings.", ex.Message);
        }
        // Dependency injection uses this constructor to instantiate MainDialog.
        public MainDialog(ConversationState conversationState, SkillConversationIdFactoryBase conversationIdFactory, SkillHttpClient skillClient, SkillsConfiguration skillsConfig, IConfiguration configuration)
            : base(nameof(MainDialog))
        {
            var botId = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value;

            _skillsConfig = skillsConfig ?? throw new ArgumentNullException(nameof(skillsConfig));

            if (skillClient == null)
            {
                throw new ArgumentNullException(nameof(skillClient));
            }

            if (conversationState == null)
            {
                throw new ArgumentNullException(nameof(conversationState));
            }

            // Create state property to track the active skill.
            _activeSkillProperty = conversationState.CreateProperty <BotFrameworkSkill>(ActiveSkillPropertyName);

            // Register the tangent dialog for testing tangents and resume
            AddDialog(new TangentDialog());

            // Create and add SkillDialog instances for the configured skills.
            AddSkillDialogs(conversationState, conversationIdFactory, skillClient, skillsConfig, botId);

            // Add ChoicePrompt to render available skills.
            AddDialog(new ChoicePrompt("SkillPrompt"));

            // Add ChoicePrompt to render skill actions.
            AddDialog(new ChoicePrompt("SkillActionPrompt", SkillActionPromptValidator));

            // Add dialog to prepare SSO on the host and test the SSO skill
            // The waterfall skillDialog created in AddSkillDialogs contains the SSO skill action.
            var waterfallDialog = Dialogs.Find("WaterfallSkillBot");

            AddDialog(new SsoDialog(waterfallDialog, configuration));

            // Add main waterfall dialog for this bot.
            var waterfallSteps = new WaterfallStep[]
            {
                SelectSkillStepAsync,
                SelectSkillActionStepAsync,
                CallSkillActionStepAsync,
                FinalStepAsync
            };

            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), waterfallSteps));

            // The initial child Dialog to run.
            InitialDialogId = nameof(WaterfallDialog);
        }
Exemple #13
0
        // Dependency injection uses this constructor to instantiate MainDialog.
        public MainDialog(ConversationState conversationState, SkillConversationIdFactoryBase conversationIdFactory, SkillHttpClient skillClient, SkillsConfiguration skillsConfig, IConfiguration configuration)
            : base(nameof(MainDialog))
        {
            var botId = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value;

            if (string.IsNullOrWhiteSpace(botId))
            {
                throw new ArgumentException($"{MicrosoftAppCredentials.MicrosoftAppIdKey} is not in configuration");
            }

            _skillsConfig = skillsConfig ?? throw new ArgumentNullException(nameof(skillsConfig));

            if (skillClient == null)
            {
                throw new ArgumentNullException(nameof(skillClient));
            }

            if (conversationState == null)
            {
                throw new ArgumentNullException(nameof(conversationState));
            }

            // Register the tangent
            AddDialog(new TangentDialog());

            // Use helper method to add SkillDialog instances for the configured skills.
            AddSkillDialogs(conversationState, conversationIdFactory, skillClient, skillsConfig, botId);

            // Add ChoicePrompt to render available skills.
            AddDialog(new ChoicePrompt("SkillPrompt"));

            // Add ChoicePrompt to render skill actions.
            AddDialog(new ChoicePrompt("SkillActionPrompt", SkillActionPromptValidator));

            // Add main waterfall dialog for this bot.
            var waterfallSteps = new WaterfallStep[]
            {
                SelectSkillStepAsync,
                SelectSkillActionStepAsync,
                CallSkillActionStepAsync,
                FinalStepAsync
            };

            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), waterfallSteps));

            // Create state property to track the active skill.
            _activeSkillProperty = conversationState.CreateProperty <BotFrameworkSkill>(ActiveSkillPropertyName);

            // The initial child Dialog to run.
            InitialDialogId = nameof(WaterfallDialog);
        }
        // Dependency injection uses this constructor to instantiate MainDialog
        public MainDialog(ConversationState conversationState, SkillConversationIdFactoryBase conversationIdFactory, SkillHttpClient skillClient, SkillsConfiguration skillsConfig, IConfiguration configuration)
            : base(nameof(MainDialog))
        {
            var botId = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value;

            if (string.IsNullOrWhiteSpace(botId))
            {
                throw new ArgumentException($"{MicrosoftAppCredentials.MicrosoftAppIdKey} is not in configuration");
            }

            _skillsConfig = skillsConfig ?? throw new ArgumentNullException(nameof(skillsConfig));

            if (skillClient == null)
            {
                throw new ArgumentNullException(nameof(skillClient));
            }

            if (conversationState == null)
            {
                throw new ArgumentNullException(nameof(conversationState));
            }

            // ChoicePrompt to render available skills and skill actions
            AddDialog(new ChoicePrompt(nameof(ChoicePrompt)));

            // SkillDialog used to wrap interaction with the selected skill
            var skillDialogOptions = new SkillDialogOptions
            {
                BotId = botId,
                ConversationIdFactory = conversationIdFactory,
                SkillClient           = skillClient,
                SkillHostEndpoint     = skillsConfig.SkillHostEndpoint
            };

            AddDialog(new SkillDialog(skillDialogOptions, conversationState));

            // Main waterfall dialog for this bot
            var waterfallSteps = new WaterfallStep[]
            {
                SelectSkillStepAsync,
                SelectSkillActionStepAsync,
                CallSkillActionStepAsync,
                FinalStepAsync
            };

            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), waterfallSteps));

            // The initial child Dialog to run.
            InitialDialogId = nameof(WaterfallDialog);
        }
Exemple #15
0
        // Dependency injection uses this constructor to instantiate MainDialog
        public MainDialog(ConversationState conversationState, SkillHttpClient skillClient, SkillsConfiguration skillsConfig, SkillDialog skillDialog, IConfiguration configuration)
            : base(nameof(MainDialog))
        {
            _botId             = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value;
            _skillClient       = skillClient;
            _skillsConfig      = skillsConfig;
            _conversationState = conversationState ?? throw new ArgumentNullException(nameof(conversationState));
            AddDialog(new TextPrompt(nameof(TextPrompt)));
            AddDialog(skillDialog);
            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[] { IntroStepAsync, ActStepAsync, FinalStepAsync }));

            // The initial child Dialog to run.
            InitialDialogId = nameof(WaterfallDialog);
        }
        public TestController(ConversationState conversationState, SkillsConfiguration skillsConfig, SkillHttpClient skillClient, IConfiguration configuration)
        {
            _skillsConfig = skillsConfig ?? throw new ArgumentNullException(nameof(skillsConfig));
            _skillClient  = skillClient ?? throw new ArgumentNullException(nameof(skillsConfig));
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            _botId = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value;
            if (string.IsNullOrWhiteSpace(_botId))
            {
                throw new ArgumentException($"{MicrosoftAppCredentials.MicrosoftAppIdKey} is not set in configuration");
            }
        }
Exemple #17
0
 public DefaultActivityHandler(IServiceProvider serviceProvider, ILogger <DefaultActivityHandler <T> > logger, T dialog)
 {
     _dialog = dialog;
     _dialog.TelemetryClient = serviceProvider.GetService <IBotTelemetryClient>();
     _conversationState      = serviceProvider.GetService <ConversationState>();
     _userState             = serviceProvider.GetService <UserState>();
     _dialogStateAccessor   = _conversationState.CreateProperty <DialogState>(nameof(DialogState));
     _userProfileState      = _userState.CreateProperty <UserProfileState>(nameof(UserProfileState));
     _templateManager       = serviceProvider.GetService <LocaleTemplateManager>();
     _skillHttpClient       = serviceProvider.GetService <SkillHttpClient>();
     _skillsConfig          = serviceProvider.GetService <SkillsConfiguration>();
     _configuration         = serviceProvider.GetService <IConfiguration>();
     _virtualAssistantBotId = _configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value;
     _logger = logger;
 }
        public MainDialog(
            IServiceProvider serviceProvider)
            : base(nameof(MainDialog))
        {
            _serviceProvider = serviceProvider;
            _services        = serviceProvider.GetService <BotServices>();
            _templateManager = serviceProvider.GetService <LocaleTemplateManager>();
            _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);

            // Create state property to track the active skill.
            _activeSkillProperty = conversationState.CreateProperty <BotFrameworkSkill>(ActiveSkillPropertyName);

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

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

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

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

            foreach (var dialog in skillDialogs)
            {
                AddDialog(dialog);
            }
        }
Exemple #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HostBot"/> class.
        /// </summary>
        /// <param name="conversationState">A state management object for the conversation.</param>
        /// <param name="skillsConfig">The skills configuration.</param>
        /// <param name="skillClient">The HTTP client for the skills.</param>
        /// <param name="configuration">The configuration properties.</param>
        /// <param name="dialog">The dialog to use.</param>
        public HostBot(ConversationState conversationState, SkillsConfiguration skillsConfig, SkillHttpClient skillClient, IConfiguration configuration, SetupDialog dialog)
        {
            _conversationState   = conversationState ?? throw new ArgumentNullException(nameof(conversationState));
            _skillsConfig        = skillsConfig ?? throw new ArgumentNullException(nameof(skillsConfig));
            _skillClient         = skillClient ?? throw new ArgumentNullException(nameof(skillClient));
            _dialog              = dialog ?? throw new ArgumentNullException(nameof(dialog));
            _dialogStateProperty = _conversationState.CreateProperty <DialogState>("DialogState");
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            _botId = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value;

            // Create state properties to track the delivery mode and active skill.
            _deliveryModeProperty = conversationState.CreateProperty <string>(DeliveryModePropertyName);
            _activeSkillProperty  = conversationState.CreateProperty <BotFrameworkSkill>(ActiveSkillPropertyName);
        }
Exemple #20
0
        public RootBot(ConversationState conversationState, SkillsConfiguration skillsConfig, SkillHttpClient skillClient, IConfiguration configuration)
        {
            _conversationState = conversationState ?? throw new ArgumentNullException(nameof(conversationState));
            _skillsConfig      = skillsConfig ?? throw new ArgumentNullException(nameof(skillsConfig));
            _skillClient       = skillClient ?? throw new ArgumentNullException(nameof(skillsConfig));
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            _botId = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value;
            if (string.IsNullOrWhiteSpace(_botId))
            {
                throw new ArgumentException($"{MicrosoftAppCredentials.MicrosoftAppIdKey} is not set in configuration");
            }

            // Create state property to track the active skill
            _activeSkillProperty = conversationState.CreateProperty <BotFrameworkSkill>(ActiveSkillPropertyName);
        }
        public SkillDialog(ConversationState conversationState, SkillHttpClient skillClient, SkillsConfiguration skillsConfig, IConfiguration configuration)
            : base(nameof(SkillDialog))
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            _botId = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value;
            if (string.IsNullOrWhiteSpace(_botId))
            {
                throw new ArgumentException($"{MicrosoftAppCredentials.MicrosoftAppIdKey} is not in configuration");
            }

            _skillClient = skillClient ?? throw new ArgumentNullException(nameof(skillClient));
            _skillsConfig = skillsConfig ?? throw new ArgumentNullException(nameof(skillsConfig));
            _conversationState = conversationState ?? throw new ArgumentNullException(nameof(conversationState));
            _activeSkillProperty = conversationState.CreateProperty<string>(ActiveSkillPropertyName);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="HostBot"/> class.
        /// </summary>
        /// <param name="conversationState">A state management object for the conversation.</param>
        /// <param name="skillsConfig">The skills configuration.</param>
        /// <param name="skillClient">The HTTP client for the skills.</param>
        /// <param name="configuration">The configuration properties.</param>
        public HostBot(ConversationState conversationState, SkillsConfiguration skillsConfig, SkillHttpClient skillClient, IConfiguration configuration)
        {
            _conversationState = conversationState ?? throw new ArgumentNullException(nameof(conversationState));
            _skillsConfig      = skillsConfig ?? throw new ArgumentNullException(nameof(skillsConfig));
            _skillClient       = skillClient ?? throw new ArgumentNullException(nameof(skillClient));
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            _botId = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value;

            if (!_skillsConfig.Skills.TryGetValue(TargetSkillId, out _targetSkill))
            {
                throw new ArgumentException($"Skill with ID \"{TargetSkillId}\" not found in configuration");
            }

            // Create state property to track the active skill
            _activeSkillProperty = conversationState.CreateProperty <BotFrameworkSkill>(ActiveSkillPropertyName);
        }
Exemple #23
0
        public RootBot(ConversationState conversationState, SkillsConfiguration skillsConfig, SkillHttpClient skillClient, IConfiguration configuration)
        {
            _conversationState = conversationState ?? throw new ArgumentNullException(nameof(conversationState));
            _skillsConfig      = skillsConfig ?? throw new ArgumentNullException(nameof(skillsConfig));
            _skillClient       = skillClient ?? throw new ArgumentNullException(nameof(skillsConfig));
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            _botId = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value;

            // We use a single skill in this example.
            var targetSkillId = "EchoSkillBot";

            _skillsConfig.Skills.TryGetValue(targetSkillId, out _targetSkill);

            // Create state property to track the active skill
            _activeSkillProperty = conversationState.CreateProperty <BotFrameworkSkill>(ActiveSkillPropertyName);
        }
Exemple #24
0
        public TokenExchangeSkillHandler(
            BotAdapter adapter,
            IBot bot,
            IConfiguration configuration,
            SkillConversationIdFactoryBase conversationIdFactory,
            SkillsConfiguration skillsConfig,
            SkillHttpClient skillClient,
            ICredentialProvider credentialProvider,
            AuthenticationConfiguration authConfig,
            ITokenExchangeConfig tokenExchangeConfig,
            IChannelProvider channelProvider = null,
            ILogger logger = null)
            : base(adapter, bot, conversationIdFactory, credentialProvider, authConfig, channelProvider, logger)
        {
            _adapter = adapter;
            _tokenExchangeProvider = adapter as IExtendedUserTokenProvider;
            _tokenExchangeConfig   = tokenExchangeConfig;
            _skillsConfig          = skillsConfig;
            _skillClient           = skillClient;
            _conversationIdFactory = conversationIdFactory;

            _botId = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value;
        }
Exemple #25
0
        public SetupDialog(ConversationState conversationState, SkillsConfiguration skillsConfig)
            : base(nameof(SetupDialog))
        {
            _skillsConfig = skillsConfig ?? throw new ArgumentNullException(nameof(skillsConfig));

            _deliveryModeProperty = conversationState.CreateProperty <string>(HostBot.DeliveryModePropertyName);
            _activeSkillProperty  = conversationState.CreateProperty <BotFrameworkSkill>(HostBot.ActiveSkillPropertyName);

            // Define the setup dialog and its related components.
            // Add ChoicePrompt to render available skills.
            AddDialog(new ChoicePrompt(nameof(ChoicePrompt)));

            // Add main waterfall dialog for this bot.
            var waterfallSteps = new WaterfallStep[]
            {
                SelectDeliveryModeStepAsync,
                SelectSkillStepAsync,
                FinalStepAsync
            };

            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), waterfallSteps));

            InitialDialogId = nameof(WaterfallDialog);
        }
Exemple #26
0
        public MainDialog(ConversationState conversationState, SkillsConfiguration skillsConfig, SkillHttpClient skillClient, IConfiguration configuration, SkillConversationIdFactoryBase conversationIdFactory, ILogger <MainDialog> logger)
            : base(nameof(MainDialog))
        {
            _logger = logger;

            AddDialog(new SignInDialog(configuration));
            AddDialog(new SignOutDialog(configuration));
            AddDialog(new DisplayTokenDialog(configuration));

            var botId = configuration.GetSection("MicrosoftAppId")?.Value;

            skillsConfig.Skills.TryGetValue("SkillBot", out var skill);
            AddDialog(new SkillDialog(
                          new SkillDialogOptions()
            {
                BotId = botId,
                ConversationIdFactory = conversationIdFactory,
                ConversationState     = conversationState,
                Skill             = skill,
                SkillClient       = skillClient,
                SkillHostEndpoint = skillsConfig.SkillHostEndpoint
            },
                          nameof(SkillDialog)));
        }
Exemple #27
0
        public MainDialog(BotFrameworkAuthentication auth, ConversationState conversationState, SkillConversationIdFactoryBase conversationIdFactory, SkillsConfiguration skillsConfig, IConfiguration configuration)
            : base(nameof(MainDialog))
        {
            _auth = auth ?? throw new ArgumentNullException(nameof(auth));

            var botId = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value;

            if (string.IsNullOrWhiteSpace(botId))
            {
                throw new ArgumentException($"{MicrosoftAppCredentials.MicrosoftAppIdKey} is not set in configuration");
            }

            _connectionName = configuration.GetSection("ConnectionName")?.Value;
            if (string.IsNullOrWhiteSpace(_connectionName))
            {
                throw new ArgumentException("\"ConnectionName\" is not set in configuration");
            }

            // We use a single skill in this example.
            var targetSkillId = "SkillBot";

            if (!skillsConfig.Skills.TryGetValue(targetSkillId, out _ssoSkill))
            {
                throw new ArgumentException($"Skill with ID \"{targetSkillId}\" not found in configuration");
            }

            AddDialog(new ChoicePrompt("ActionStepPrompt"));
            AddDialog(new SsoSignInDialog(_connectionName));
            AddDialog(new SkillDialog(CreateSkillDialogOptions(skillsConfig, botId, conversationIdFactory, conversationState), nameof(SkillDialog)));

            var waterfallSteps = new WaterfallStep[]
            {
                PromptActionStepAsync,
                HandleActionStepAsync,
                PromptFinalStepAsync,
            };

            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), waterfallSteps));

            // Create state property to track the active skill.
            _activeSkillProperty = conversationState.CreateProperty <BotFrameworkSkill>(ActiveSkillPropertyName);

            // The initial child Dialog to run.
            InitialDialogId = nameof(WaterfallDialog);
        }
        // Helper method that creates and adds SkillDialog instances for the configured skills.
        private void AddSkillDialogs(ConversationState conversationState, SkillConversationIdFactoryBase conversationIdFactory, SkillHttpClient skillClient, SkillsConfiguration skillsConfig, string botId)
        {
            foreach (var skillInfo in _skillsConfig.Skills.Values)
            {
                // Create the dialog options.
                var skillDialogOptions = new SkillDialogOptions
                {
                    BotId = botId,
                    ConversationIdFactory = conversationIdFactory,
                    SkillClient           = skillClient,
                    SkillHostEndpoint     = skillsConfig.SkillHostEndpoint,
                    ConversationState     = conversationState,
                    Skill = skillInfo
                };

                // Add a SkillDialog for the selected skill.
                AddDialog(new SkillDialog(skillDialogOptions, skillInfo.Id));
            }
        }
        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);
            }
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Configure MVC
            services.AddControllers().AddNewtonsoftJson();

            services.AddSingleton(Configuration);

            // Load settings
            var settings = new BotSettings();

            Configuration.Bind(settings);
            services.AddSingleton(settings);

            // Configure channel provider
            services.AddSingleton <IChannelProvider, ConfigurationChannelProvider>();

            // Configure configuration provider
            services.AddSingleton <ICredentialProvider, ConfigurationCredentialProvider>();

            // Register the skills configuration class.
            var skillsConfig = new SkillsConfiguration(Configuration);

            services.AddSingleton(skillsConfig);

            // Register AuthConfiguration to enable custom claim validation.
            services.AddSingleton(sp => new AuthenticationConfiguration {
                ClaimsValidator = new AllowedCallersClaimsValidator(skillsConfig)
            });

            // Configure telemetry
            services.AddApplicationInsightsTelemetry();
            services.AddSingleton <IBotTelemetryClient, BotTelemetryClient>();
            services.AddSingleton <ITelemetryInitializer, OperationCorrelationTelemetryInitializer>();
            services.AddSingleton <ITelemetryInitializer, TelemetryBotIdInitializer>();
            services.AddSingleton <TelemetryInitializerMiddleware>();
            services.AddSingleton <TelemetryLoggerMiddleware>();

            // Configure bot services
            services.AddSingleton <BotServices>();

            // Configure storage
            // Uncomment the following line for local development without Cosmos Db
            // services.AddSingleton<IStorage, MemoryStorage>();
            services.AddSingleton <IStorage>(new CosmosDbPartitionedStorage(settings.CosmosDb));
            services.AddSingleton <UserState>();
            services.AddSingleton <ConversationState>();

            // Configure localized responses
            var localizedTemplates = new Dictionary <string, string>();
            var templateFile       = "AllResponses";
            var supportedLocales   = new List <string>()
            {
                "en-us", "de-de", "es-es", "fr-fr", "it-it", "zh-cn"
            };

            foreach (var locale in supportedLocales)
            {
                // LG template for en-us does not include locale in file extension.
                var localeTemplateFile = locale.Equals("en-us")
                    ? Path.Combine(".", "Responses", $"{templateFile}.lg")
                    : Path.Combine(".", "Responses", $"{templateFile}.{locale}.lg");

                localizedTemplates.Add(locale, localeTemplateFile);
            }

            services.AddSingleton(new LocaleTemplateManager(localizedTemplates, settings.DefaultLocale ?? "en-us"));

            // Register the Bot Framework Adapter with error handling enabled.
            // Note: some classes use the base BotAdapter so we add an extra registration that pulls the same instance.
            services.AddSingleton <BotFrameworkHttpAdapter, DefaultAdapter>();
            services.AddSingleton <BotAdapter>(sp => sp.GetService <BotFrameworkHttpAdapter>());

            // Register the skills conversation ID factory, the client and the request handler.
            services.AddSingleton <SkillConversationIdFactoryBase, SkillConversationIdFactory>();
            services.AddHttpClient <SkillHttpClient>();
            services.AddSingleton <ChannelServiceHandler, TokenExchangeSkillHandler>();

            // Register dialogs
            services.AddTransient <MainDialog>();
            services.AddTransient <SwitchSkillDialog>();
            services.AddTransient <OnboardingDialog>();

            // Register the SkillDialogs (remote skills).
            var botId = Configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value;

            if (string.IsNullOrWhiteSpace(botId))
            {
                throw new ArgumentException($"{MicrosoftAppCredentials.MicrosoftAppIdKey} is not in configuration");
            }

            foreach (var skill in skillsConfig.Skills.Values)
            {
                services.AddSingleton(sp =>
                {
                    var skillDialogOptions = new SkillDialogOptions
                    {
                        BotId = botId,
                        ConversationIdFactory = sp.GetService <SkillConversationIdFactoryBase>(),
                        SkillClient           = sp.GetService <SkillHttpClient>(),
                        SkillHostEndpoint     = skillsConfig.SkillHostEndpoint,
                        Skill             = skill,
                        ConversationState = sp.GetService <ConversationState>()
                    };

                    return(new SkillDialog(skillDialogOptions, skill.Id));
                });
            }

            // Configure TokenExchangeConfig for SSO
            if (settings.TokenExchangeConfig != null)
            {
                services.AddSingleton <ITokenExchangeConfig>(settings.TokenExchangeConfig);
            }

            // Configure bot
            services.AddTransient <IBot, DefaultActivityHandler <MainDialog> >();
        }