diff --git a/api/config.js b/api/config.js index 204f993..5ce2bc4 100644 --- a/api/config.js +++ b/api/config.js @@ -81,6 +81,7 @@ overrides['REDIS_HOST'] = 'redis.host'; overrides['REDIS_PORT'] = 'redis.port'; overrides['RATELIMIT_COUNT'] = 'limit.count'; overrides['RATELIMIT_WINDOW'] = 'limit.window'; +overrides['SLACK_SECRET'] = 'slack.secret'; handleEnvironmentOverrides(config, overrides); handleAWSOverrides(config); @@ -92,6 +93,7 @@ if (!config.isProduction) { requireds.delete(overrides['GITHUB_MOBILE_REDIRECT']); requireds.delete(overrides['RATELIMIT_COUNT']); requireds.delete(overrides['RATELIMIT_WINDOW']); + requireds.delete(overrides['SLACK_SECRET']); } handleEnvironmentRequireds(config, requireds); diff --git a/api/v1/controllers/CheckInController.js b/api/v1/controllers/CheckInController.js index b7d0105..91335e8 100644 --- a/api/v1/controllers/CheckInController.js +++ b/api/v1/controllers/CheckInController.js @@ -1,6 +1,8 @@ const bodyParser = require('body-parser'); const _ = require('lodash'); +const request = require('request-promise'); +const config = require('ctx').config(); const services = require('../services'); const middleware = require('../middleware'); const requests = require('../requests'); @@ -8,6 +10,8 @@ const roles = require('../utils/roles'); const router = require('express').Router(); +const SLACK_INVITE_URI = 'https://slack.com/api/users.admin.invite'; + function updateCheckInByUserId(req, res, next) { req.body.userId = req.params.id; delete req.body.credentialsRequested; @@ -57,6 +61,18 @@ function createCheckIn(req, res, next) { req.body.userId = req.params.id; services.CheckInService .createCheckIn(req.body) + .tap((model) => services.UserService.findUserById(model.checkin.get('userId')) + .then((user) => request({ + method: 'POST', + uri: SLACK_INVITE_URI, + headers: { + Authorization: 'Bearer ' + config.slack.secret + }, + formData: { + email: user.get('email') + } + }) + )) .then((response) => { response.checkin = response.checkin.toJSON(); if (!_.isNil(response.credentials)) { diff --git a/config/development.json.template b/config/development.json.template index 771bdf6..e4c539d 100644 --- a/config/development.json.template +++ b/config/development.json.template @@ -106,5 +106,8 @@ "limit": { "count": 50, "window": 60 + }, + "slack": { + "secret": "secret-slack-token" } } diff --git a/config/production.json.template b/config/production.json.template index f3dde0d..9404ed0 100644 --- a/config/production.json.template +++ b/config/production.json.template @@ -106,5 +106,8 @@ "limit": { "count": 50, "window": 60 + }, + "slack": { + "secret": "secret-slack-token" } }