/// <summary>
        /// Initializes a new instance of the <see cref="CoreBot"/> class.
        /// </summary>
        /// <param name="options">Configured options for the <see cref="CoreBot"/> instance.</param>
        /// <param name="conversationState"><see cref="ConversationState"/> for the bot.</param>
        /// <param name="userState"><see cref="UserState"/> instance for the bot.</param>
        /// <param name="resourceExplorer"><see cref="ResourceExplorer"/> instance to access declarative assets.</param>
        /// <param name="telemetryClient"><see cref="IBotTelemetryClient"/> for the bot.</param>
        /// <param name="botFrameworkClient"><see cref="BotFrameworkClient"/> instance for the bot.</param>
        /// <param name="conversationIdfactory"><see cref="SkillConversationIdFactoryBase"/> instance for the bot.</param>
        public CoreBot(
            IOptions <CoreBotOptions> options,
            ConversationState conversationState,
            UserState userState,
            ResourceExplorer resourceExplorer,
            IBotTelemetryClient telemetryClient,
            BotFrameworkClient botFrameworkClient,
            SkillConversationIdFactoryBase conversationIdfactory)
        {
            _conversationState = conversationState;
            _userState         = userState;

            Resource rootDialogResource = resourceExplorer.GetResource(options.Value.RootDialog);
            var      rootDialog         = resourceExplorer.LoadType <AdaptiveDialog>(rootDialogResource);

            _dialogManager = new DialogManager(rootDialog)
                             .UseResourceExplorer(resourceExplorer)
                             .UseLanguageGeneration()
                             .UseLanguagePolicy(new LanguagePolicy(options.Value.DefaultLocale ?? DefaultLocale));

            if (telemetryClient != null)
            {
                _dialogManager.UseTelemetry(telemetryClient);
            }

            _dialogManager.InitialTurnState.Set(botFrameworkClient);
            _dialogManager.InitialTurnState.Set(conversationIdfactory);
            _dialogManager.InitialTurnState.Set(_userState);
            _dialogManager.InitialTurnState.Set(_conversationState);
        }
예제 #2
0
        //Dirty hack to get reference to OnTurn in component start

        public BotWithLookup(
            IConfiguration configuration,
            ResourceExplorer resourceExplorer,
            ConversationState conversationState,
            UserState userState,
            SkillConversationIdFactoryBase skillConversationIdFactoryBase,
            LanguagePolicy languagePolicy,
            BotFrameworkAuthentication botFrameworkAuthentication = null,
            IBotTelemetryClient telemetryClient       = null,
            IEnumerable <MemoryScope> scopes          = default,
            IEnumerable <IPathResolver> pathResolvers = default,
            IEnumerable <Dialog> dialogs = default,
            ILogger logger = null)
            : base(
                configuration.GetSection("defaultRootDialog").Value,
                configuration.GetSection("defaultLg").Value ?? "main.lg",
                resourceExplorer,
                conversationState,
                userState,
                skillConversationIdFactoryBase,
                languagePolicy,
                botFrameworkAuthentication ?? BotFrameworkAuthenticationFactory.Create(),
                telemetryClient ?? new NullBotTelemetryClient(),
                scopes ?? Enumerable.Empty <MemoryScope>(),
                pathResolvers ?? Enumerable.Empty <IPathResolver>(),
                dialogs ?? Enumerable.Empty <Dialog>(),
                logger: logger ?? NullLogger <AdaptiveDialogBot> .Instance)
        {
            OnTurn = OnTurn ?? this.OnTurnAsync;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AdaptiveDialogBot"/> class.
        /// </summary>
        /// <param name="adaptiveDialogId">The id of the <see cref="AdaptiveDialog"/> to load from the <see cref="ResourceExplorer"/>.</param>
        /// <param name="languageGeneratorId">The id of the <see cref="LanguageGenerator"/> to load from the <see cref="ResourceExplorer"/>.</param>
        /// <param name="resourceExplorer">The Bot Builder <see cref="ResourceExplorer"/> to load the <see cref="Dialog"/> from.</param>
        /// <param name="conversationState">A <see cref="ConversationState"/> implementation.</param>
        /// <param name="userState">A <see cref="UserState"/> implementation.</param>
        /// <param name="skillConversationIdFactoryBase">A <see cref="SkillConversationIdFactoryBase"/> implementation.</param>
        /// <param name="languagePolicy">A <see cref="LanguagePolicy"/> to use.</param>
        /// <param name="botFrameworkAuthentication">A <see cref="BotFrameworkAuthentication"/> used to obtain a client for making calls to Bot Builder Skills.</param>
        /// <param name="telemetryClient">A <see cref="IBotTelemetryClient"/> used to log bot telemetry events.</param>
        /// <param name="scopes">Custom <see cref="MemoryScope"/> implementations that extend the memory system.</param>
        /// <param name="pathResolvers">Custom <see cref="IPathResolver"/> that add new resolvers path shortcuts to memory scopes.</param>
        /// <param name="dialogs">Custom <see cref="Dialog"/> that will be added to the root DialogSet.</param>
        /// <param name="logger">An <see cref="ILogger"/> instance.</param>
        public AdaptiveDialogBot(
            string adaptiveDialogId,
            string languageGeneratorId,
            ResourceExplorer resourceExplorer,
            ConversationState conversationState,
            UserState userState,
            SkillConversationIdFactoryBase skillConversationIdFactoryBase,
            LanguagePolicy languagePolicy,
            BotFrameworkAuthentication botFrameworkAuthentication,
            IBotTelemetryClient telemetryClient,
            IEnumerable <MemoryScope> scopes          = default,
            IEnumerable <IPathResolver> pathResolvers = default,
            IEnumerable <Dialog> dialogs = default,
            ILogger logger = null)
        {
            _resourceExplorer               = resourceExplorer ?? throw new ArgumentNullException(nameof(resourceExplorer));
            _adaptiveDialogId               = adaptiveDialogId ?? throw new ArgumentNullException(nameof(adaptiveDialogId));
            _languageGeneratorId            = languageGeneratorId ?? throw new ArgumentNullException(nameof(languageGeneratorId));
            _conversationState              = conversationState ?? throw new ArgumentNullException(nameof(conversationState));
            _userState                      = userState ?? throw new ArgumentNullException(nameof(userState));
            _skillConversationIdFactoryBase = skillConversationIdFactoryBase ?? throw new ArgumentNullException(nameof(skillConversationIdFactoryBase));
            _languagePolicy                 = languagePolicy ?? throw new ArgumentNullException(nameof(languagePolicy));
            _botFrameworkAuthentication     = botFrameworkAuthentication ?? throw new ArgumentNullException(nameof(botFrameworkAuthentication));
            _telemetryClient                = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient));
            _memoryScopes                   = scopes ?? Enumerable.Empty <MemoryScope>();
            _pathResolvers                  = pathResolvers ?? Enumerable.Empty <IPathResolver>();
            _dialogs = dialogs ?? Enumerable.Empty <Dialog>();
            _logger  = logger ?? NullLogger <AdaptiveDialogBot> .Instance;

            _lazyRootDialog               = new Lazy <Task <Dialog> >(CreateDialogAsync);
            _lazyLanguageGenerator        = new Lazy <LanguageGenerator>(CreateLanguageGenerator);
            _lazyLanguageGeneratorManager = new Lazy <LanguageGeneratorManager>(CreateLanguageGeneratorManager);
        }
 public ForwardController(BotFrameworkHttpClient client, IConfiguration configuration, SkillConversationIdFactoryBase factory)
 {
     _client     = client;
     _toUri      = new Uri(configuration["Next"]);
     _serviceUrl = new Uri(configuration["ServiceUrl"]);
     _factory    = factory;
 }
        public TokenExchangeSkillHandler(
            BotAdapter adapter,
            IBot bot,
            IConfiguration configuration,
            SkillConversationIdFactoryBase conversationIdFactory,
            SkillsConfiguration skillsConfig,
            SkillHttpClient skillClient,
            ICredentialProvider credentialProvider,
            AuthenticationConfiguration authConfig,
            IChannelProvider channelProvider           = null,
            ILogger <TokenExchangeSkillHandler> logger = null)
            : base(adapter, bot, conversationIdFactory, credentialProvider, authConfig, channelProvider, logger)
        {
            _adapter = adapter;
            _tokenExchangeProvider = adapter as IExtendedUserTokenProvider;
            if (_tokenExchangeProvider == null)
            {
                throw new ArgumentException($"{nameof(adapter)} does not support token exchange");
            }

            _configuration         = configuration;
            _skillsConfig          = skillsConfig;
            _skillClient           = skillClient;
            _conversationIdFactory = conversationIdFactory;
            _logger = logger ?? NullLogger <TokenExchangeSkillHandler> .Instance;
            _botId  = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value;
        }
예제 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AdaptiveDialogBot"/> class.
 /// </summary>
 /// <param name="adaptiveDialogId">The id of the <see cref="AdaptiveDialog"/> to load from the <see cref="ResourceExplorer"/>.</param>
 /// <param name="languageGeneratorId">The id of the <see cref="LanguageGenerator"/> to load from the <see cref="ResourceExplorer"/>.</param>
 /// <param name="defaultLocale">The default locale for this bot.</param>
 /// <param name="resourceExplorer">The Bot Builder <see cref="ResourceExplorer"/> to load the <see cref="Dialog"/> from.</param>
 /// <param name="conversationState">A <see cref="ConversationState"/> implementation.</param>
 /// <param name="userState">A <see cref="UserState"/> implementation.</param>
 /// <param name="skillConversationIdFactoryBase">A <see cref="SkillConversationIdFactoryBase"/> implementation.</param>
 /// <param name="botFrameworkAuthentication">A <see cref="BotFrameworkAuthentication"/> used to obtain a client for making calls to Bot Builder Skills.</param>
 /// <param name="scopes">Custom <see cref="MemoryScope"/> implementations that extend the memory system.</param>
 /// <param name="pathResolvers">Custom <see cref="IPathResolver"/> that add new resolvers path shortcuts to memory scopes.</param>
 /// <param name="dialogs">Custom <see cref="Dialog"/> that will be added to the root DialogSet.</param>
 /// <param name="logger">An <see cref="ILogger"/> instance.</param>
 public AdaptiveDialogBot(
     string adaptiveDialogId,
     string languageGeneratorId,
     string defaultLocale,
     ResourceExplorer resourceExplorer,
     ConversationState conversationState,
     UserState userState,
     SkillConversationIdFactoryBase skillConversationIdFactoryBase,
     BotFrameworkAuthentication botFrameworkAuthentication,
     IEnumerable <MemoryScope> scopes          = default,
     IEnumerable <IPathResolver> pathResolvers = default,
     IEnumerable <Dialog> dialogs = default,
     ILogger logger = null)
 {
     _resourceExplorer               = resourceExplorer ?? throw new ArgumentNullException(nameof(resourceExplorer));
     _adaptiveDialogId               = adaptiveDialogId ?? throw new ArgumentNullException(nameof(adaptiveDialogId));
     _languageGeneratorId            = languageGeneratorId ?? throw new ArgumentNullException(nameof(languageGeneratorId));
     _defaultLocale                  = defaultLocale ?? throw new ArgumentNullException(nameof(defaultLocale));
     _conversationState              = conversationState ?? throw new ArgumentNullException(nameof(conversationState));
     _userState                      = userState ?? throw new ArgumentNullException(nameof(userState));
     _skillConversationIdFactoryBase = skillConversationIdFactoryBase ?? throw new ArgumentNullException(nameof(skillConversationIdFactoryBase));
     _botFrameworkAuthentication     = botFrameworkAuthentication ?? throw new ArgumentNullException(nameof(botFrameworkAuthentication));
     _memoryScopes                   = scopes ?? Enumerable.Empty <MemoryScope>();
     _pathResolvers                  = pathResolvers ?? Enumerable.Empty <IPathResolver>();
     _dialogs = dialogs ?? Enumerable.Empty <Dialog>();
     _logger  = logger ?? NullLogger <AdaptiveDialogBot> .Instance;
 }
예제 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConfigurationAdaptiveDialogBot"/> class using <see cref="IConfiguration"/>.
 /// </summary>
 /// <param name="configuration">An <see cref="IConfiguration"/> instance.</param>
 /// <param name="resourceExplorer">The Bot Builder <see cref="ResourceExplorer"/> to load the <see cref="AdaptiveDialog"/> from.</param>
 /// <param name="conversationState">The <see cref="ConversationState"/> implementation to use for this <see cref="AdaptiveDialog"/>.</param>
 /// <param name="userState">The <see cref="UserState"/> implementation to use for this <see cref="AdaptiveDialog"/>.</param>
 /// <param name="skillConversationIdFactoryBase">The <see cref="SkillConversationIdFactoryBase"/> implementation to use for this <see cref="AdaptiveDialog"/>.</param>
 /// <param name="botFrameworkAuthentication">A <see cref="BotFrameworkAuthentication"/> for making calls to Bot Builder Skills.</param>
 /// <param name="scopes">A set of <see cref="MemoryScope"/> that will be added to the <see cref="ITurnContext"/>.</param>
 /// <param name="pathResolvers">A set of <see cref="IPathResolver"/> that will be added to the <see cref="ITurnContext"/>.</param>
 /// <param name="dialogs">Custom <see cref="Dialog"/> that will be added to the root DialogSet.</param>
 /// <param name="logger">An <see cref="ILogger"/> instance.</param>
 public ConfigurationAdaptiveDialogBot(
     IConfiguration configuration,
     ResourceExplorer resourceExplorer,
     ConversationState conversationState,
     UserState userState,
     SkillConversationIdFactoryBase skillConversationIdFactoryBase,
     BotFrameworkAuthentication botFrameworkAuthentication = null,
     IEnumerable <MemoryScope> scopes          = default,
     IEnumerable <IPathResolver> pathResolvers = default,
     IEnumerable <Dialog> dialogs = default,
     ILogger logger = null)
     : base(
         configuration.GetSection(ConfigurationConstants.RootDialogKey).Value,
         configuration.GetSection(ConfigurationConstants.LanguageGeneratorKey).Value ?? DefaultLanguageGeneratorId,
         configuration.GetSection(ConfigurationConstants.DefaultLocaleKey).Value ?? DefaultLocale,
         resourceExplorer,
         conversationState,
         userState,
         skillConversationIdFactoryBase,
         botFrameworkAuthentication ?? BotFrameworkAuthenticationFactory.Create(),
         scopes ?? Enumerable.Empty <MemoryScope>(),
         pathResolvers ?? Enumerable.Empty <IPathResolver>(),
         dialogs ?? Enumerable.Empty <Dialog>(),
         logger: logger ?? NullLogger <AdaptiveDialogBot> .Instance)
 {
 }
        // 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);
        }
예제 #9
0
 public RoutingHandler(
     SkillConversationIdFactoryBase factory,
     ICredentialProvider credentialProvider,
     AuthenticationConfiguration authConfiguration,
     IChannelProvider channelProvider = null)
     : base(credentialProvider, authConfiguration, channelProvider)
 {
     _factory     = factory;
     _credentials = MicrosoftAppCredentials.Empty;
 }
        // 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);
        }
예제 #11
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);
        }
예제 #12
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));
            }

            // 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);
        }
예제 #13
0
        public DefaultAdapter(
            BotSettings settings,
            ICredentialProvider credentialProvider,
            IChannelProvider channelProvider,
            AuthenticationConfiguration authConfig,
            LocaleTemplateManager templateEngine,
            ConversationState conversationState,
            TelemetryInitializerMiddleware telemetryMiddleware,
            IBotTelemetryClient telemetryClient,
            ILogger <BotFrameworkHttpAdapter> logger,
            IStorage storage,
            UserState userState,
            IConfiguration configuration,
            SkillConversationIdFactoryBase skillConversationIdFactoryBase,
            BotFrameworkClient botFrameworkClient)
            : 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));
            _skillConversationIdFactoryBase = skillConversationIdFactoryBase;

            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 TelemetryLoggerMiddleware(telemetryClient, logPersonalInformation: true));
            Use(new ShowTypingMiddleware());
            Use(new SetLocaleMiddleware(settings.DefaultLocale ?? "en-us"));
            Use(new EventDebuggerMiddleware());
            Use(new SetSpeakMiddleware());
            Use(new RegisterClassMiddleware <SkillConversationIdFactoryBase>(_skillConversationIdFactoryBase));
            Use(new RegisterClassMiddleware <BotFrameworkClient>(botFrameworkClient));

            //from instructions: https://microsoft.github.io/botframework-solutions/skills/handbook/experimental-add-composer/
            this.Use(new RegisterClassMiddleware <IConfiguration>(configuration));
            this.UseStorage(storage);
            this.UseBotState(userState);
            this.UseBotState(conversationState);
        }
예제 #14
0
        // 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));
            }
        }
예제 #15
0
        public TokenExchangeSkillHandler(
            BotAdapter adapter,
            IBot bot,
            IConfiguration configuration,
            SkillConversationIdFactoryBase conversationIdFactory,
            BotFrameworkAuthentication auth,
            SkillsConfiguration skillsConfig,
            ILogger <TokenExchangeSkillHandler> logger = null)
            : base(adapter, bot, conversationIdFactory, auth, logger)
        {
            _adapter = adapter ?? throw new ArgumentNullException(nameof(adapter));
            _auth    = auth ?? throw new ArgumentNullException(nameof(auth));
            _conversationIdFactory = conversationIdFactory;
            _skillsConfig          = skillsConfig ?? new SkillsConfiguration(configuration);
            _configuration         = configuration;

            _botId  = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value;
            _logger = logger ?? NullLogger <TokenExchangeSkillHandler> .Instance;
        }
예제 #16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HostBot"/> class.
        /// </summary>
        /// <param name="auth">The cloud environment for the bot.</param>
        /// <param name="conversationState">A state management object for the conversation.</param>
        /// <param name="skillsConfig">The skills configuration.</param>
        /// <param name="configuration">The configuration properties.</param>
        /// <param name="conversationIdFactory">The conversation id factory.</param>
        /// <param name="dialog">The dialog to use.</param>
        public HostBot(BotFrameworkAuthentication auth, ConversationState conversationState, SkillsConfiguration skillsConfig, SkillConversationIdFactoryBase conversationIdFactory, IConfiguration configuration, SetupDialog dialog)
        {
            _auth = auth ?? throw new ArgumentNullException(nameof(auth));
            _conversationState     = conversationState ?? throw new ArgumentNullException(nameof(conversationState));
            _skillsConfig          = skillsConfig ?? throw new ArgumentNullException(nameof(skillsConfig));
            _conversationIdFactory = conversationIdFactory ?? throw new ArgumentNullException(nameof(conversationIdFactory));
            _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);
        }
예제 #17
0
        public TokenExchangeSkillHandler(
            BotAdapter adapter,
            IBot bot,
            IConfiguration configuration,
            SkillConversationIdFactoryBase conversationIdFactory,
            BotFrameworkAuthentication authConfig,
            SkillsConfiguration skillsConfig = default,
            ILogger logger = default)
            : base(adapter, bot, conversationIdFactory, authConfig, logger)
        {
            _adapter = adapter;
            _botAuth = authConfig;
            _conversationIdFactory = conversationIdFactory;
            _skillsConfig          = skillsConfig ?? new SkillsConfiguration(configuration);
            _botId  = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value;
            _logger = logger;

            var settings = configuration.GetSection("Bot.Builder.Community.Components.TokenExchangeSkillHandler")?.Get <ComponentSettings>() ?? new ComponentSettings();

            _connectionName = settings.TokenExchangeConnectionName ?? configuration.GetSection("tokenExchangeConnectionName")?.Value;
        }
예제 #18
0
        public RootBot(BotFrameworkAuthentication auth, ConversationState conversationState, SkillsConfiguration skillsConfig, SkillConversationIdFactoryBase conversationIdFactory, IConfiguration configuration)
        {
            _auth = auth ?? throw new ArgumentNullException(nameof(auth));
            _conversationState     = conversationState ?? throw new ArgumentNullException(nameof(conversationState));
            _skillsConfig          = skillsConfig ?? throw new ArgumentNullException(nameof(skillsConfig));
            _conversationIdFactory = conversationIdFactory ?? throw new ArgumentNullException(nameof(conversationIdFactory));

            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);
        }
        public TokenExchangeSkillHandler(
            BotAdapter adapter,
            IBot bot,
            IConfiguration configuration,
            ICredentialProvider credentialProvider,
            SkillConversationIdFactoryBase conversationIdFactory,
            AuthenticationConfiguration authConfig,
            BotFrameworkAuthentication botAuth,
            SkillsConfiguration skillsConfig,
            IChannelProvider channelProvider           = null,
            ILogger <TokenExchangeSkillHandler> logger = null)
            : base(adapter, bot, conversationIdFactory, credentialProvider, authConfig, channelProvider, logger)
        {
            _adapter = adapter;

            _configuration         = configuration;
            _botAuth               = botAuth;
            _authConfig            = authConfig;
            _conversationIdFactory = conversationIdFactory;
            _skillsConfig          = skillsConfig ?? new SkillsConfiguration(configuration);
            _botId  = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value;
            _logger = logger;
        }
예제 #20
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;
        }
예제 #21
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)));
        }
예제 #22
0
 private SkillHandlerInstanceForTests CreateSkillHandlerForTesting(SkillConversationIdFactoryBase overrideFactory = null)
 {
     return(new SkillHandlerInstanceForTests(_mockAdapter.Object, _mockBot.Object, overrideFactory ?? _testConversationIdFactory, new Mock <ICredentialProvider>().Object, new AuthenticationConfiguration()));
 }
예제 #23
0
        public ComposerBot(ConversationState conversationState, UserState userState, ResourceExplorer resourceExplorer, BotFrameworkClient skillClient, SkillConversationIdFactoryBase conversationIdFactory, IBotTelemetryClient telemetryClient, string rootDialog, string defaultLocale, bool removeRecipientMention = false)
        {
            this.conversationState      = conversationState;
            this.userState              = userState;
            this.dialogState            = conversationState.CreateProperty <DialogState>("DialogState");
            this.resourceExplorer       = resourceExplorer;
            this.rootDialogFile         = rootDialog;
            this.defaultLocale          = defaultLocale;
            this.telemetryClient        = telemetryClient;
            this.removeRecipientMention = removeRecipientMention;

            LoadRootDialogAsync();
            if (skillClient != null)
            {
                this.dialogManager.InitialTurnState.Set(skillClient);
            }

            this.dialogManager.InitialTurnState.Set(conversationIdFactory);
        }
예제 #24
0
        private static SkillDialog CreateEchoSkillDialog(ConversationState conversationState, SkillConversationIdFactoryBase conversationIdFactory, SkillHttpClient skillClient, IConfiguration configuration)
        {
            var botId = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value;

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

            var skillHostEndpoint = configuration.GetSection("SkillHostEndpoint")?.Value;

            if (string.IsNullOrWhiteSpace(skillHostEndpoint))
            {
                throw new ArgumentException("SkillHostEndpoint is not in configuration");
            }

            var skillInfo = configuration.GetSection("EchoSkillInfo").Get <BotFrameworkSkill>() ?? throw new ArgumentException("EchoSkillInfo is not set in configuration");

            var skillDialogOptions = new SkillDialogOptions
            {
                BotId = botId,
                ConversationIdFactory = conversationIdFactory,
                SkillClient           = skillClient,
                SkillHostEndpoint     = new Uri(skillHostEndpoint),
                ConversationState     = conversationState,
                Skill = skillInfo
            };
            var echoSkillDialog = new SkillDialog(skillDialogOptions);

            return(echoSkillDialog);
        }
예제 #25
0
 public SkillHttpClient(HttpClient httpClient, ICredentialProvider credentialProvider, SkillConversationIdFactoryBase conversationIdFactory, IChannelProvider channelProvider = null, ILogger logger = null)
     : base(httpClient, credentialProvider, channelProvider, logger)
 {
     _conversationIdFactory = conversationIdFactory;
 }
예제 #26
0
        public ActivityRouterDialog(DialogSkillBotRecognizer luisRecognizer, ConversationState conversationState, SkillConversationIdFactoryBase conversationIdFactory, SkillHttpClient skillClient, IConfiguration configuration)
            : base(nameof(ActivityRouterDialog))
        {
            _luisRecognizer = luisRecognizer;

            AddDialog(new BookingDialog());
            AddDialog(new OAuthTestDialog(configuration));

            // SkillDialog used to call EchoSkill
            var echoSkillDialog = CreateEchoSkillDialog(conversationState, conversationIdFactory, skillClient, configuration);

            AddDialog(echoSkillDialog);

            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[] { ProcessActivityAsync }));

            // The initial child Dialog to run.
            InitialDialogId = nameof(WaterfallDialog);
        }
예제 #27
0
 public SkillHandlerInstanceForTests(BotAdapter adapter, IBot bot, SkillConversationIdFactoryBase testConversationIdFactory, ICredentialProvider credentialProvider, AuthenticationConfiguration authConfig, IChannelProvider channelProvider = null, ILogger logger = null)
     : base(adapter, bot, testConversationIdFactory, credentialProvider, authConfig, channelProvider, logger)
 {
 }
예제 #28
0
        public TestBot(ConversationState conversationState, ResourceExplorer resourceExplorer, BotFrameworkClient skillClient, SkillConversationIdFactoryBase conversationIdFactory)
        {
            HostContext.Current.Set(skillClient);
            HostContext.Current.Set(conversationIdFactory);
            this.dialogStateAccessor = conversationState.CreateProperty <DialogState>("RootDialogState");
            this.resourceExplorer    = resourceExplorer;

            // auto reload dialogs when file changes
            this.resourceExplorer.Changed += (resources) =>
            {
                if (resources.Any(resource => resource.Id.EndsWith(".dialog") || resource.Id.EndsWith(".lg")))
                {
                    Task.Run(() => this.LoadDialogs());
                }
            };
            LoadDialogs();
        }
 public EchoBotSkillHandler(BotAdapter adapter, Bots.EchoBot bot, SkillConversationIdFactoryBase conversationIdFactory, ICredentialProvider credentialProvider, AuthenticationConfiguration authConfig, IChannelProvider channelProvider = null, ILogger logger = null)
     : base(adapter, bot, conversationIdFactory, credentialProvider, authConfig, channelProvider, logger)
 {
 }
 public ComposerBot(ConversationState conversationState, UserState userState, ResourceExplorer resourceExplorer, BotFrameworkClient skillClient, SkillConversationIdFactoryBase conversationIdFactory, string rootDialog)
 {
     HostContext.Current.Set(skillClient);
     HostContext.Current.Set(conversationIdFactory);
     this.conversationState = conversationState;
     this.userState         = userState;
     this.dialogState       = conversationState.CreateProperty <DialogState>("DialogState");
     this.resourceExplorer  = resourceExplorer;
     this.rootDialogFile    = rootDialog;
     LoadRootDialogAsync();
 }