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()); }
public AllowedCallersClaimsValidator(IConfiguration config, SkillsConfiguration skillsConfig) { if (config == null) { throw new ArgumentNullException(nameof(config)); } // AllowedCallers is the setting in the appsettings.json file // that consists of the list of parent bot IDs that are allowed to access the skill. // To add a new parent bot, simply edit the AllowedCallers and add // the parent bot's Microsoft app ID to the list. // In this sample, we allow all callers if AllowedCallers contains an "*". var section = config.GetSection(ConfigKey); var appsList = section.Get <string[]>(); if (appsList == null) { throw new ArgumentNullException($"\"{ConfigKey}\" not found in configuration."); } _allowedCallers = new List <string>(appsList); // 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(); }
public AllowedSkillsClaimsValidator(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(); }
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 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)) { _settings = serviceProvider.GetService <BotSettings>(); _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); } }
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"); }
public TokenExchangeSkillHandler( IServiceProvider serviceProvider, BotAdapter adapter, IBot bot, IConfiguration configuration, SkillConversationIdFactoryBase conversationIdFactory, SkillsConfiguration skillsConfig, SkillHttpClient skillClient, ICredentialProvider credentialProvider, AuthenticationConfiguration authConfig, IChannelProvider channelProvider = null, ILogger logger = null) : base(adapter, bot, conversationIdFactory, credentialProvider, authConfig, channelProvider, logger) { _adapter = adapter; _tokenExchangeProvider = adapter as IExtendedUserTokenProvider; _tokenExchangeConfig = serviceProvider.GetService <ITokenExchangeConfig>(); _skillsConfig = skillsConfig; _skillClient = skillClient; _conversationIdFactory = conversationIdFactory; _botId = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value; }
// 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> >(); }
public RootBot(ConversationState conversationState, SkillsConfiguration skillsConfig, SkillHttpClient skillClient, IConfiguration configuration) : base(conversationState, skillsConfig, skillClient, configuration) { }
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 userState = serviceProvider.GetService <UserState>(); _userProfileState = userState.CreateProperty <UserProfileState>(nameof(UserProfileState)); var conversationState = serviceProvider.GetService <ConversationState>(); _previousResponseAccessor = conversationState.CreateProperty <List <Activity> >(StateProperties.PreviousBotResponse); 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 a QnAMakerDialog for each registered knowledgebase and ensure localised responses are provided. var localizedServices = _services.GetCognitiveModels(); foreach (var knowledgebase in localizedServices.QnAConfiguration) { var qnaDialog = new QnAMakerDialog( knowledgeBaseId: knowledgebase.Value.KnowledgeBaseId, endpointKey: knowledgebase.Value.EndpointKey, hostName: knowledgebase.Value.Host, noAnswer: _templateEngine.GenerateActivityForLocale("UnsupportedMessage"), activeLearningCardTitle: _templateEngine.GenerateActivityForLocale("QnaMakerAdaptiveLearningCardTitle").Text, cardNoMatchText: _templateEngine.GenerateActivityForLocale("QnaMakerNoMatchText").Text) { Id = knowledgebase.Key }; AddDialog(qnaDialog); } // Register skill dialogs var skillDialogs = serviceProvider.GetServices <SkillDialog>(); foreach (var dialog in skillDialogs) { AddDialog(dialog); } }