public async Task StartAsync(CancellationToken cancellationToken) { using var scope = logger.BeginScope("Bot initialization"); if (await TryInitializeAutomatically()) { return; } #if DEBUG retry: logger.LogInformation("Input webhook URL: "); var input = Console.ReadLine(); try { await botProvider.InitializeAsync(() => RegisterAsync(input)); } catch (Exception e) { logger.LogError(e, "Wrong webhook: " + input); goto retry; } #endif }
/// <summary> /// Logic required to start the application. /// </summary> protected void Application_Start() { RegisterContainer(); GlobalConfiguration.Configure(WebApiConfig.Register); using (ILifetimeScope scope = Container.BeginLifetimeScope()) { IBotProvider provider = scope.Resolve <IBotProvider>(); Task.Run(() => provider.InitializeAsync()).Wait(); ApplicationInsights.Extensibility.TelemetryConfiguration.Active.InstrumentationKey = provider.Configuration.InstrumentationKey; Conversation.UpdateContainer( builder => { builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly())); DocumentDbBotDataStore store = new DocumentDbBotDataStore( new Uri(provider.Configuration.CosmosDbEndpoint), provider.Configuration.CosmosDbAccessKey.ToUnsecureString()); builder.Register(c => { return(new MicrosoftAppCredentials( provider.Configuration.MicrosoftAppId, provider.Configuration.MicrosoftAppPassword.ToUnsecureString())); }).SingleInstance(); builder.Register(c => store) .Keyed <IBotDataStore <BotData> >(AzureModule.Key_DataStore) .AsSelf() .SingleInstance(); builder.Register(c => new CachingBotDataStore(store, CachingBotDataStoreConsistencyPolicy.ETagBasedConsistency)) .As <IBotDataStore <BotData> >() .AsSelf() .InstancePerLifetimeScope(); }); } }