Skip to content

Instantly share code, notes, and snippets.

@justinyoo
Created May 14, 2016 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinyoo/59f2643f884971db4e06b01be8978c72 to your computer and use it in GitHub Desktop.
Save justinyoo/59f2643f884971db4e06b01be8978c72 to your computer and use it in GitHub Desktop.
Integrating Slack with AWS Lambda & Azure Functions
'use strict';
let https = require('https');
/**
* Pass the data to send as `event.data`, and the request options as
* `event.options`. For more information see the HTTPS module documentation
* at https://nodejs.org/api/https.html.
*
* Will succeed with the response body.
*/
exports.handler = (event, context, callback) => {
const req = https.request(event.options, (res) => {
let body = '';
console.log('Status:', res.statusCode);
console.log('Headers:', JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', (chunk) => body += chunk);
res.on('end', () => {
console.log('Successfully processed HTTPS response');
// If we know it's JSON, parse it
if (res.headers['content-type'] === 'application/json') {
body = JSON.parse(body);
}
callback(null, body);
});
});
req.on('error', callback);
req.write(JSON.stringify(event.data));
req.end();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment