Exemple #1
0
        public AdapterWithErrorHandler(IConfiguration configuration, ILogger<BotFrameworkHttpAdapter> logger, ConversationState conversationState, SkillHttpClient skillClient = null, SkillsConfiguration skillsConfig = null)
            : base(configuration, logger)
        {
            _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
            _conversationState = conversationState ?? throw new ArgumentNullException(nameof(conversationState));
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));
            _skillClient = skillClient;
            _skillsConfig = skillsConfig;

            OnTurnError = HandleTurnError;
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AdapterWithErrorHandler"/> class to handle errors.
        /// </summary>
        /// <param name="botFrameworkAuthentication">The cloud environment for the bot.</param>
        /// <param name="configuration">The configuration properties.</param>
        /// <param name="logger">An instance of a logger.</param>
        /// <param name="conversationState">A state management object for the conversation.</param>
        /// <param name="skillClient">The HTTP client for the skills.</param>
        /// <param name="skillsConfig">The skills configuration.</param>
        public AdapterWithErrorHandler(BotFrameworkAuthentication botFrameworkAuthentication, IConfiguration configuration, ILogger <CloudAdapter> logger, ConversationState conversationState = null, SkillHttpClient skillClient = null, SkillsConfiguration skillsConfig = null)
            : base(botFrameworkAuthentication, logger)
        {
            _configuration     = configuration ?? throw new ArgumentNullException(nameof(configuration));
            _conversationState = conversationState;
            _logger            = logger ?? throw new ArgumentNullException(nameof(logger));
            _skillClient       = skillClient;
            _skillsConfig      = skillsConfig;

            OnTurnError = HandleTurnErrorAsync;
        }
 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 = ":";
 }
Exemple #4
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 AdapterWithErrorHandler(IConfiguration configuration, ICredentialProvider credentialProvider,
                                       AuthenticationConfiguration authConfig, ILogger <BotFrameworkHttpAdapter> logger,
                                       ConversationState conversationState = null, SkillHttpClient skillClient = null,
                                       SkillsConfiguration skillsConfig    = null)
            : base(configuration, credentialProvider, authConfig, logger: logger)
        {
            _configuration     = configuration ?? throw new ArgumentNullException(nameof(configuration));
            _conversationState = conversationState;
            _logger            = logger ?? throw new ArgumentNullException(nameof(logger));
            _skillClient       = skillClient;
            _skillsConfig      = skillsConfig;

            OnTurnError = HandleTurnError;
        }
        public AdapterWithErrorHandler(IConfiguration configuration, ILogger <BotFrameworkHttpAdapter> logger, IStorage storage, ConversationState conversationState, SkillHttpClient skillClient = null, SkillsConfiguration skillsConfig = null)
            : base(configuration, logger)
        {
            _configuration     = configuration ?? throw new ArgumentNullException(nameof(configuration));
            _conversationState = conversationState ?? throw new ArgumentNullException(nameof(conversationState));
            _logger            = logger ?? throw new ArgumentNullException(nameof(logger));
            _skillClient       = skillClient;
            _skillsConfig      = skillsConfig;

            this.UseStorage(storage);
            this.UseBotState(conversationState);

            OnTurnError = HandleTurnError;
            Use(new LoggerMiddleware(logger));
        }
        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 #8
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;
 }
Exemple #9
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);
        }
        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);
        }
Exemple #11
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>("activeSkillProperty");
        }
Exemple #12
0
        public TeamsSkillDialog(ConversationState conversationState, SkillHttpClient skillClient, EnhancedBotFrameworkSkill skill, IConfiguration configuration, Uri skillHostEndpoint)
            : base(skill?.Id)
        {
            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");
            }

            _skillHostEndpoint = skillHostEndpoint;
            _skillClient       = skillClient ?? throw new ArgumentNullException(nameof(skillClient));
            _skill             = skill ?? throw new ArgumentNullException(nameof(skill));
            _conversationState = conversationState ?? throw new ArgumentNullException(nameof(conversationState));
        }
Exemple #13
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);
        }
        /// <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);
        }
        public async Task PostActivityWithOriginatingAudience()
        {
            var conversationId        = Guid.NewGuid().ToString();
            var conversationIdFactory = new SimpleConversationIdFactory(conversationId);
            var testActivity          = MessageFactory.Text("some message");

            testActivity.Conversation = new ConversationAccount();
            var skill = new BotFrameworkSkill
            {
                Id            = "SomeSkill",
                AppId         = string.Empty,
                SkillEndpoint = new Uri("https://someskill.com/api/messages")
            };

            var httpClient = CreateHttpClientWithMockHandler((request, cancellationToken) =>
            {
                Assert.Equal(skill.SkillEndpoint, request.RequestUri);

                // Assert that the activity being sent has what we expect.
                var activitySent = JsonConvert.DeserializeObject <Activity>(request.Content.ReadAsStringAsync().Result);
                Assert.Equal(conversationId, activitySent.Conversation.Id);
                Assert.Equal("https://parentbot.com/api/messages", activitySent.ServiceUrl);

                // Create mock response.
                var response = new HttpResponseMessage(HttpStatusCode.OK);
                return(Task.FromResult(response));
            });

            var sut    = new SkillHttpClient(httpClient, new Mock <ICredentialProvider>().Object, conversationIdFactory);
            var result = await sut.PostActivityAsync <object>("someOriginatingAudience", string.Empty, skill, new Uri("https://parentbot.com/api/messages"), testActivity, CancellationToken.None);

            // Assert factory options
            Assert.Equal(string.Empty, conversationIdFactory.CreationOptions.FromBotId);
            Assert.Equal("someOriginatingAudience", conversationIdFactory.CreationOptions.FromBotOAuthScope);
            Assert.Equal(testActivity, conversationIdFactory.CreationOptions.Activity);
            Assert.Equal(skill, conversationIdFactory.CreationOptions.BotFrameworkSkill);

            // Assert result
            Assert.IsType <InvokeResponse <object> >(result);
            Assert.Equal(200, result.Status);
        }
        public DefaultAdapter(
            BotSettings settings,
            ICredentialProvider credentialProvider,
            IChannelProvider channelProvider,
            AuthenticationConfiguration authConfig,
            LocaleTemplateManager templateEngine,
            ConversationState conversationState,
            TelemetryInitializerMiddleware telemetryMiddleware,
            IBotTelemetryClient telemetryClient,
            ILogger <BotFrameworkHttpAdapter> logger,
            LoggingMiddleware loggingMiddleware,
            HandoffMiddleware handoffMiddleware,
            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);
            Use(loggingMiddleware);
            Use(handoffMiddleware);

            // 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());
        }
Exemple #17
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 #18
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);
        }
Exemple #19
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);
        }
Exemple #20
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)));

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

            // Create SkillDialog instances for the configured skills
            foreach (var skillInfo in _skillsConfig.Skills.Values)
            {
                // SkillDialog used to wrap interaction with the selected skill
                var skillDialogOptions = new SkillDialogOptions
                {
                    BotId = botId,
                    ConversationIdFactory = conversationIdFactory,
                    SkillClient           = skillClient,
                    SkillHostEndpoint     = skillsConfig.SkillHostEndpoint,
                    ConversationState     = conversationState,
                    Skill = skillInfo
                };
                AddDialog(new SkillDialog(skillDialogOptions, skillInfo.Id));
            }

            // 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);
        }
Exemple #21
0
 public RootBot(ConversationState conversationState, SkillsConfiguration skillsConfig, SkillHttpClient skillClient, IConfiguration configuration)
     : base(conversationState, skillsConfig, skillClient, configuration)
 {
 }
Exemple #22
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");
        }
        // 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));
            }
        }
Exemple #24
0
        public ActivityRouterDialog(IConfiguration configuration, IHttpContextAccessor httpContextAccessor, ConversationState conversationState, SkillConversationIdFactoryBase conversationIdFactory, SkillHttpClient skillClient, ConcurrentDictionary <string, ContinuationParameters> continuationParametersStore)
            : base(nameof(ActivityRouterDialog))
        {
            AddDialog(new CardDialog(httpContextAccessor));
            AddDialog(new MessageWithAttachmentDialog(new Uri($"{httpContextAccessor.HttpContext.Request.Scheme}://{httpContextAccessor.HttpContext.Request.Host.Value}")));
            AddDialog(new WaitForProactiveDialog(httpContextAccessor, continuationParametersStore));
            AddDialog(new AuthDialog(configuration));
            AddDialog(new SsoSkillDialog(configuration));
            AddDialog(new FileUploadDialog());
            AddDialog(new DeleteDialog());
            AddDialog(new UpdateDialog());

            AddDialog(CreateEchoSkillDialog(conversationState, conversationIdFactory, skillClient, configuration));

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

            // 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));
            }

            // 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 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;

            _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 types of skill.
            AddDialog(new ChoicePrompt("SkillTypePrompt"));

            // 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
                                  .GetDialogs()
                                  .Where(e => e.Id.StartsWith("WaterfallSkill"))
                                  .First();

            AddDialog(new SsoDialog(waterfallDialog, configuration));

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

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

            // The initial child Dialog to run.
            InitialDialogId = nameof(WaterfallDialog);
        }
Exemple #27
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)));
        }
        // 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);
        }