Skip to content

Instantly share code, notes, and snippets.

@adamgall
Created Sep 9, 2019
Embed
What would you like to do?
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