-
-
Save adamgall/356388b31040eed8c7f32bde4968abb7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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