-
Notifications
You must be signed in to change notification settings - Fork 4
/
handler.js
39 lines (31 loc) · 972 Bytes
/
handler.js
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
35
36
37
38
39
'use strict';
var request = require('request');
var services = require('./services/index')
// POST: /events or
// POST: /events?url=your_team_connector_url
module.exports.hello = (event, context, callback) => {
const body = JSON.parse(event.body);
let payload = services(body)
let paramsIncomingURL = null
if (event['queryStringParameters'] != null)
paramsIncomingURL = event['queryStringParameters']['url']
let channelWebhookURL = paramsIncomingURL || process.env.channel_incoming_webhook_url
if (payload){
request.post(channelWebhookURL, { json: payload },
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log('Success!: ', body)
} else {
console.log(error, body)
}
}
);
}
const response = {
statusCode: 200,
body: JSON.stringify({
message: 'Your function executed successfully!'
}),
};
callback(null, response);
};