Skip to content

Instantly share code, notes, and snippets.

@adamgall
Created September 9, 2019 18:47
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 adamgall/356388b31040eed8c7f32bde4968abb7 to your computer and use it in GitHub Desktop.
Save adamgall/356388b31040eed8c7f32bde4968abb7 to your computer and use it in GitHub Desktop.
const https = require('https');
const querystring = require('querystring');
const url = require('url');
const spongebob = text => {
const og = [...text.toLowerCase()];
for (let i = 0; i < og.length; i++) {
if (Math.random() > 0.5) og[i] = og[i].toUpperCase();
}
return og.join('');
};
exports.handler = function(event, context, callback) {
// 1
callback(null, { statusCode: 200, body: '' });
// 2
const query = querystring.parse(event.body);
const originalMessage = query.text;
const responseInfo = url.parse(query.response_url)
// 3
const delayedSpongebob = JSON.stringify({
text: spongebob(originalMessage),
response_type: "in_channel"
});
// 4
const req = https.request({
hostname: responseInfo.host,
port: 443,
path: responseInfo.path,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': delayedSpongebob.length
}
});
req.write(delayedSpongebob);
req.end();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment