public BotFrameworkHttpAdapter GetBotAdapter(IStorage storage, BotSettings settings, UserState userState, ConversationState conversationState, IServiceProvider s, TelemetryInitializerMiddleware telemetryInitializerMiddleware) { var adapter = new BotFrameworkHttpAdapter(new ConfigurationCredentialProvider(this.Configuration)); adapter .UseStorage(storage) .UseBotState(userState, conversationState) .Use(new RegisterClassMiddleware <IConfiguration>(Configuration)) .Use(telemetryInitializerMiddleware); // Configure Middlewares ConfigureTranscriptLoggerMiddleware(adapter, settings); ConfigureInspectionMiddleWare(adapter, settings, storage); ConfigureShowTypingMiddleWare(adapter, settings); adapter.OnTurnError = async(turnContext, exception) => { await turnContext.SendActivityAsync(exception.Message).ConfigureAwait(false); await conversationState.ClearStateAsync(turnContext).ConfigureAwait(false); await conversationState.SaveChangesAsync(turnContext).ConfigureAwait(false); }; return(adapter); }
public void SetCurrent(string botDir) { IStorage storage = new MemoryStorage(); var userState = new UserState(storage); var conversationState = new ConversationState(storage); var inspectionState = new InspectionState(storage); // manage all bot resources var resourceExplorer = new ResourceExplorer().AddFolder(botDir); var adapter = new BotFrameworkHttpAdapter(new ConfigurationCredentialProvider(Config)); var credentials = new MicrosoftAppCredentials(Config["MicrosoftAppId"], Config["MicrosoftAppPassword"]); adapter .UseStorage(storage) .UseState(userState, conversationState) .UseAdaptiveDialogs() .UseResourceExplorer(resourceExplorer) .UseLanguageGeneration(resourceExplorer, "common.lg") .Use(new RegisterClassMiddleware <IConfiguration>(Config)) .Use(new InspectionMiddleware(inspectionState, userState, conversationState, credentials)); adapter.OnTurnError = async(turnContext, exception) => { await turnContext.SendActivityAsync(exception.Message).ConfigureAwait(false); await conversationState.ClearStateAsync(turnContext).ConfigureAwait(false); await conversationState.SaveChangesAsync(turnContext).ConfigureAwait(false); }; CurrentAdapter = adapter; CurrentBot = new ComposerBot("Main.dialog", conversationState, userState, resourceExplorer, DebugSupport.SourceMap); }
public override void Configure(IFunctionsHostBuilder builder) { // Get assets directory. var assetsDirectory = GetAssetsDirectory(); // Build configuration with assets. var config = BuildConfiguration(assetsDirectory); var settings = new BotSettings(); config.Bind(settings); var services = builder.Services; services.AddSingleton <IConfiguration>(config); services.AddLogging(); // Create the credential provider to be used with the Bot Framework Adapter. services.AddSingleton <ICredentialProvider, ConfigurationCredentialProvider>(); services.AddSingleton <BotAdapter>(sp => (BotFrameworkHttpAdapter)sp.GetService <IBotFrameworkHttpAdapter>()); // Register AuthConfiguration to enable custom claim validation. services.AddSingleton <AuthenticationConfiguration>(); // Adaptive component registration ComponentRegistration.Add(new DialogsComponentRegistration()); ComponentRegistration.Add(new DeclarativeComponentRegistration()); ComponentRegistration.Add(new AdaptiveComponentRegistration()); ComponentRegistration.Add(new LanguageGenerationComponentRegistration()); ComponentRegistration.Add(new QnAMakerComponentRegistration()); ComponentRegistration.Add(new LuisComponentRegistration()); // This is for custom action component registration. //ComponentRegistration.Add(new CustomActionComponentRegistration()); // Register the skills client and skills request handler. services.AddSingleton <SkillConversationIdFactoryBase, SkillConversationIdFactory>(); services.AddHttpClient <BotFrameworkClient, SkillHttpClient>(); services.AddSingleton <ChannelServiceHandler, SkillHandler>(); // Register telemetry client, initializers and middleware services.AddApplicationInsightsTelemetry(settings?.ApplicationInsights?.InstrumentationKey ?? string.Empty); services.AddSingleton <ITelemetryInitializer, OperationCorrelationTelemetryInitializer>(); services.AddSingleton <ITelemetryInitializer, TelemetryBotIdInitializer>(); services.AddSingleton <IBotTelemetryClient, BotTelemetryClient>(); services.AddSingleton <TelemetryLoggerMiddleware>(sp => { var telemetryClient = sp.GetService <IBotTelemetryClient>(); return(new TelemetryLoggerMiddleware(telemetryClient, logPersonalInformation: settings?.Telemetry?.LogPersonalInformation ?? false)); }); services.AddSingleton <TelemetryInitializerMiddleware>(sp => { var httpContextAccessor = sp.GetService <IHttpContextAccessor>(); var telemetryLoggerMiddleware = sp.GetService <TelemetryLoggerMiddleware>(); return(new TelemetryInitializerMiddleware(httpContextAccessor, telemetryLoggerMiddleware, settings?.Telemetry?.LogActivities ?? false)); }); // Storage IStorage storage; if (ConfigSectionValid(settings?.CosmosDb?.AuthKey)) { storage = new CosmosDbPartitionedStorage(settings?.CosmosDb); } else { storage = new MemoryStorage(); } services.AddSingleton(storage); var userState = new UserState(storage); var conversationState = new ConversationState(storage); services.AddSingleton(userState); services.AddSingleton(conversationState); // Resource explorer to track declarative assets var resourceExplorer = new ResourceExplorer().AddFolder(assetsDirectory.FullName); services.AddSingleton(resourceExplorer); // Adapter services.AddSingleton <IBotFrameworkHttpAdapter, BotFrameworkHttpAdapter>(s => { // Retrieve required dependencies IStorage storage = s.GetService <IStorage>(); UserState userState = s.GetService <UserState>(); ConversationState conversationState = s.GetService <ConversationState>(); TelemetryInitializerMiddleware telemetryInitializerMiddleware = s.GetService <TelemetryInitializerMiddleware>(); var adapter = new BotFrameworkHttpAdapter(new ConfigurationCredentialProvider(config)); adapter .UseStorage(storage) .UseBotState(userState, conversationState) .Use(new RegisterClassMiddleware <IConfiguration>(config)) .Use(telemetryInitializerMiddleware); // Configure Middlewares ConfigureTranscriptLoggerMiddleware(adapter, settings); ConfigureInspectionMiddleWare(adapter, settings, s); ConfigureShowTypingMiddleWare(adapter, settings); adapter.OnTurnError = async(turnContext, exception) => { await turnContext.SendActivityAsync(exception.Message).ConfigureAwait(false); await conversationState.ClearStateAsync(turnContext).ConfigureAwait(false); await conversationState.SaveChangesAsync(turnContext).ConfigureAwait(false); }; return(adapter); }); var defaultLocale = config.GetValue <string>(DefaultLanguageSetting) ?? EnglishLocale; var removeRecipientMention = settings?.Feature?.RemoveRecipientMention ?? false; // Bot services.AddSingleton <IBot>(s => new ComposerBot( s.GetService <ConversationState>(), s.GetService <UserState>(), s.GetService <ResourceExplorer>(), s.GetService <BotFrameworkClient>(), s.GetService <SkillConversationIdFactoryBase>(), s.GetService <IBotTelemetryClient>(), GetRootDialog(assetsDirectory.FullName), defaultLocale, removeRecipientMention)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddSingleton <IConfiguration>(this.Configuration); // Create the credential provider to be used with the Bot Framework Adapter. services.AddSingleton <ICredentialProvider, ConfigurationCredentialProvider>(); services.AddSingleton <InspectionMiddleware>(); // Load settings var settings = new BotSettings(); Configuration.Bind(settings); IStorage storage = null; // Configure storage for deployment if (!string.IsNullOrEmpty(settings.CosmosDb.AuthKey)) { storage = new CosmosDbStorage(settings.CosmosDb); } else { Console.WriteLine("The settings of CosmosDbStorage is incomplete, please check following settings: settings.CosmosDb"); storage = new MemoryStorage(); } services.AddSingleton(storage); var userState = new UserState(storage); var conversationState = new ConversationState(storage); var inspectionState = new InspectionState(storage); // Configure telemetry services.AddApplicationInsightsTelemetry(); var telemetryClient = new BotTelemetryClient(new TelemetryClient()); services.AddSingleton <IBotTelemetryClient>(telemetryClient); services.AddBotApplicationInsights(telemetryClient); var botFile = Configuration.GetSection("bot").Get <string>(); TypeFactory.Configuration = this.Configuration; // manage all bot resources var resourceExplorer = new ResourceExplorer().AddFolder(botFile); var credentials = new MicrosoftAppCredentials(this.Configuration["MicrosoftAppId"], this.Configuration["MicrosoftAppPassword"]); services.AddSingleton <IBotFrameworkHttpAdapter, BotFrameworkHttpAdapter>((s) => { var adapter = new BotFrameworkHttpAdapter(new ConfigurationCredentialProvider(this.Configuration)); adapter .UseStorage(storage) .UseState(userState, conversationState) .UseAdaptiveDialogs() .UseResourceExplorer(resourceExplorer) .UseLanguageGeneration(resourceExplorer, "common.lg") .Use(new RegisterClassMiddleware <IConfiguration>(Configuration)) .Use(new InspectionMiddleware(inspectionState, userState, conversationState, credentials)); if (!string.IsNullOrEmpty(settings.BlobStorage.ConnectionString) && !string.IsNullOrEmpty(settings.BlobStorage.Container)) { adapter.Use(new TranscriptLoggerMiddleware(new AzureBlobTranscriptStore(settings.BlobStorage.ConnectionString, settings.BlobStorage.Container))); } else { Console.WriteLine("The settings of TranscriptLoggerMiddleware is incomplete, please check following settings: settings.BlobStorage.ConnectionString, settings.BlobStorage.Container"); } adapter.OnTurnError = async(turnContext, exception) => { await turnContext.SendActivityAsync(exception.Message).ConfigureAwait(false); telemetryClient.TrackException(new Exception("Exceptions: " + exception.Message)); await conversationState.ClearStateAsync(turnContext).ConfigureAwait(false); await conversationState.SaveChangesAsync(turnContext).ConfigureAwait(false); }; return(adapter); }); services.AddSingleton <IBot, ComposerBot>((sp) => new ComposerBot("Main.dialog", conversationState, userState, resourceExplorer, DebugSupport.SourceMap, telemetryClient)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers().AddNewtonsoftJson(); services.AddSingleton <IConfiguration>(this.Configuration); // Create the credential provider to be used with the Bot Framework Adapter. services.AddSingleton <ICredentialProvider, ConfigurationCredentialProvider>(); services.AddSingleton <BotAdapter>(sp => (BotFrameworkHttpAdapter)sp.GetService <IBotFrameworkHttpAdapter>()); // Register AuthConfiguration to enable custom claim validation. services.AddSingleton <AuthenticationConfiguration>(); // Register the skills client and skills request handler. services.AddSingleton <SkillConversationIdFactoryBase, SkillConversationIdFactory>(); services.AddHttpClient <BotFrameworkClient, SkillHttpClient>(); services.AddSingleton <ChannelServiceHandler, SkillHandler>(); // Load settings var settings = new BotSettings(); Configuration.Bind(settings); IStorage storage = null; // Configure storage for deployment if (!string.IsNullOrEmpty(settings.CosmosDb.AuthKey)) { storage = new CosmosDbStorage(settings.CosmosDb); } else { Console.WriteLine("The settings of CosmosDbStorage is incomplete, please check following settings: settings.CosmosDb"); storage = new MemoryStorage(); } services.AddSingleton(storage); var userState = new UserState(storage); var conversationState = new ConversationState(storage); var botFile = Configuration.GetSection("bot").Get <string>(); // manage all bot resources var resourceExplorer = new ResourceExplorer().AddFolder(botFile); services.AddSingleton(userState); services.AddSingleton(conversationState); services.AddSingleton(resourceExplorer); services.AddSingleton <IBotFrameworkHttpAdapter, BotFrameworkHttpAdapter>((s) => { HostContext.Current.Set <IConfiguration>(Configuration); var adapter = new BotFrameworkHttpAdapter(new ConfigurationCredentialProvider(this.Configuration)); adapter .UseStorage(storage) .UseState(userState, conversationState); if (!string.IsNullOrEmpty(settings.BlobStorage.ConnectionString) && !string.IsNullOrEmpty(settings.BlobStorage.Container)) { adapter.Use(new TranscriptLoggerMiddleware(new AzureBlobTranscriptStore(settings.BlobStorage.ConnectionString, settings.BlobStorage.Container))); } else { Console.WriteLine("The settings of TranscriptLoggerMiddleware is incomplete, please check following settings: settings.BlobStorage.ConnectionString, settings.BlobStorage.Container"); } adapter.OnTurnError = async(turnContext, exception) => { await turnContext.SendActivityAsync(exception.Message).ConfigureAwait(false); await conversationState.ClearStateAsync(turnContext).ConfigureAwait(false); await conversationState.SaveChangesAsync(turnContext).ConfigureAwait(false); }; return(adapter); }); services.AddSingleton <IBot, ComposerBot>(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(options => options.EnableEndpointRouting = false).SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddSingleton <IConfiguration>(this.Configuration); // Create the credential provider to be used with the Bot Framework Adapter. services.AddSingleton <ICredentialProvider, ConfigurationCredentialProvider>(); // Load settings var settings = new BotSettings(); Configuration.Bind(settings); IStorage storage = null; // Configure storage for deployment if (!string.IsNullOrEmpty(settings.CosmosDb.AuthKey)) { storage = new CosmosDbStorage(settings.CosmosDb); } else { Console.WriteLine("The settings of CosmosDbStorage is incomplete, please check following settings: settings.CosmosDb"); storage = new MemoryStorage(); } services.AddSingleton(storage); var userState = new UserState(storage); var conversationState = new ConversationState(storage); var botFile = Configuration.GetSection("bot").Get <string>(); // manage all bot resources var resourceExplorer = new ResourceExplorer().AddFolder(botFile); var credentials = new MicrosoftAppCredentials(this.Configuration["MicrosoftAppId"], this.Configuration["MicrosoftAppPassword"]); services.AddSingleton <IBotFrameworkHttpAdapter, BotFrameworkHttpAdapter>((s) => { HostContext.Current.Set <IConfiguration>(Configuration); var adapter = new BotFrameworkHttpAdapter(new ConfigurationCredentialProvider(this.Configuration)); adapter .UseStorage(storage) .UseState(userState, conversationState); if (!string.IsNullOrEmpty(settings.BlobStorage.ConnectionString) && !string.IsNullOrEmpty(settings.BlobStorage.Container)) { adapter.Use(new TranscriptLoggerMiddleware(new AzureBlobTranscriptStore(settings.BlobStorage.ConnectionString, settings.BlobStorage.Container))); } else { Console.WriteLine("The settings of TranscriptLoggerMiddleware is incomplete, please check following settings: settings.BlobStorage.ConnectionString, settings.BlobStorage.Container"); } adapter.OnTurnError = async(turnContext, exception) => { await turnContext.SendActivityAsync(exception.Message).ConfigureAwait(false); await conversationState.ClearStateAsync(turnContext).ConfigureAwait(false); await conversationState.SaveChangesAsync(turnContext).ConfigureAwait(false); }; return(adapter); }); services.AddSingleton <IBot, ComposerBot>((sp) => new ComposerBot("Main.dialog", conversationState, userState, resourceExplorer, DebugSupport.SourceMap)); }