-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhandler.js
More file actions
34 lines (28 loc) · 897 Bytes
/
handler.js
File metadata and controls
34 lines (28 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';
var request = require('request');
var config = {
slack_domain : process.env.slack_domain,
slack_token : process.env.slack_token,
};
module.exports.invite = (event, context, callback) => {
var cb = function( data ) {
callback(null, { statusCode: 200, body: JSON.stringify( data ), headers: { "Access-Control-Allow-Origin" : "*" } } );
}
var data = JSON.parse(event.body);
if ( ! data.email ) {
return cb( { error : 'missing email parameter' } );
}
request.post({
url: 'https://'+ config.slack_domain + '/api/users.admin.invite',
form: {
email: data.email,
token: config.slack_token,
set_active: true
}
}, function(err, httpResponse, body) {
if ( err ) {
return cb( { error : err, body: body } );
}
cb( JSON.parse( body ) );
} );
};