public static void InstallSlackClients(this IServiceCollection services, SlackConfig config) { services.AddSingleton <ISlackClientFactory, SlackClientFactory>(); services.AddHttpClient <ISlackMessageClient, SlackMessageClient>(c => c.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", config.OauthAccessToken)); services.AddHttpClient <ISlackFileClient, SlackFileClient>(c => c.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", config.OauthAccessToken)); }
public void Implements_ServiceConfig() { // Arrange var config = new SlackConfig(); // Act // Assert Assert.IsAssignableFrom <IServiceConfig>(config); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => false; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.Configure <UserSecrets>(Configuration.GetSection(nameof(UserSecrets))); var secrets = Configuration.GetSection(nameof(UserSecrets)).Get <UserSecrets>(); services.Configure <ConnectedClientSettings>(Configuration.GetSection("ChatClients")); // Injected into ChatClients by DI for Hangfire scheduled actions var slackConfig = new SlackConfig { ApiKey = secrets.SlackApiKey, DefaultChannel = Configuration["ChatClients:SlackDefaultChannel"], }; var discordConfig = new DiscordConfig { DiscordToken = secrets.DiscordToken, DefaultChannel = Configuration["ChatClients:DiscordDefaultChannel"], }; var twitchConfig = new TwitchConfig { Username = secrets.TwitchUsername, Token = secrets.TwitchToken, Channel = secrets.TwitchChannel, }; services.AddSingleton(slackConfig); services.AddSingleton(discordConfig); services.AddSingleton(twitchConfig); services.AddSingleton <IConnectedClients, ConnectedClients>(); services.AddSingleton <IBotSettings, BotSettings>(); services.AddSingleton <IBotClient, BotGraphClient>(); services.AddHangfire(x => x.UseSqlServerStorage(secrets.DatabaseConnectionString)); services.AddDbContext <AppDataContext>(options => options.UseSqlServer(secrets.DatabaseConnectionString)); services.AddScoped <IRepository, EntityFrameworkRepository>(); services.AddSingleton <IActionScheduler, HangfireActionScheduler>(); services.AddSingleton <IAnswerSearchEngine, AnswerSearch>(); services.AddSingleton <IBot, Core.Bot>(); RegisterGraphQL.Configure(services, _env); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
public void Returns_True(string webhook) { // Arrange var config = new SlackConfig { Webhook = webhook }; // Act var result = config.IsValid; // Assert Assert.True(result); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddLogging(loggingBuilder => { loggingBuilder.AddConsole(); //loggingBuilder.AddSerilog(); loggingBuilder.AddDebug(); }); services.AddControllers().AddNewtonsoftJson(); services.AddDbContext <SlackWhereIsDbContext>(options => { options.UseNpgsql(Configuration.GetConnectionString("slackwhereis")).UseSnakeCaseNamingConvention(); //options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking); }); services.AddScoped <ILocationRepository, EntityFrameworkLocationRepository>(); services.AddTransient <BotProcessingService>(); services.AddHostedService <BotProcessingService>(); services.AddSingleton <IBackgroundTaskQueue, BackgroundTaskQueue>(); services.AddHttpClient(); // 1. Add Authentication Services services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(options => { options.Authority = "https://absoluteps.auth0.com/"; options.Audience = "WhereIs Slack Bot API on AWS"; }); // Slack Configuration SlackConfig slackConfig = new SlackConfig(); Configuration.GetSection("Slack").Bind(slackConfig); services.AddScoped <SlackAuthorizationActionFilter>(); services.AddSingleton(slackConfig); // Exchange Configuration ExchangeConfig exchangeConfig = new ExchangeConfig(); Configuration.GetSection("Exchange").Bind(exchangeConfig); services.AddScoped <ExchangeProvider>(); services.AddSingleton(exchangeConfig); services.Configure <IISServerOptions>(options => { options.AllowSynchronousIO = true; }); }
public static IAppBuilder UsePingOwin(this IAppBuilder appBuilder, PingOwinOptions options = null) { options = options ?? new PingOwinOptions(); var connectionString = $"Data Source={options.PathToDb}pingowin.db;Version=3;Pooling=True;Max Pool Size=100;"; var databaseSettings = new DbSettings(connectionString); var migrator = new Migrator(databaseSettings); migrator.Migrate(); var conf = new NancyOptions { Bootstrapper = new PingOwinWebBootstrapper(databaseSettings) }; appBuilder.UseNancy(conf); var pingConfiguration = new PingConfiguration { RequestTimeOut = new TimeSpan(0, 0, 0, 0, options.RequestTimeOut), WarnThreshold = options.WarnThreshold }; var notifierType = NotifierType.Konsole; var slackConfig = new SlackConfig(); var notifierFactory = new NotifierFactory(notifierType, slackConfig); var transformerFactory = new TransformerFactory(notifierType, Level.OK); var processor = IoCFactory.CreateProcessor(pingConfiguration, databaseSettings, notifierFactory, transformerFactory); var serviceRunner = new ServiceRunner(new ServiceRunnerOptions { PingIntervalInMillis = options.PingIntervalInMillis, RunBackgroundThread = options.StartService }, processor); serviceRunner.StartBackgroundThread(); return(appBuilder); }
public SlackService(IHttpClientFactory clientFactory, IOptions <SlackConfig> config) { _clientFactory = clientFactory; _config = config.Value; }
public SlackDispatcher(SlackConfig config) { _networkProvider = new NetworkProvider(); _config = config; }
public SlackClientWrapper(SlackConfig config) { _config = config; _client = new SlackClient(_config.WebhookURL); }
public SlackCommandController(HttpClient webClient, SlackConfig slackConfig, FogBugzConfig fogBugzConfig) { WebClient = webClient; SlackConfig = slackConfig; FogBugzConfig = fogBugzConfig; }
public AuthConfigurationRepository(SlackConfig slackConfig) { _slackConfig = slackConfig; }