Created
January 20, 2021 14:24
-
-
Save mandarg/b7fa8a9e8ab8477a594f835ba7ae0aae to your computer and use it in GitHub Desktop.
Forward SMS to Twilio channel
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 got = require('got'); | |
// Summary Mostly follow the steps in https://github.com/twilio-labs/function-templates/tree/main/forward-message-sendgrid | |
// except substitute the Discord webhook for the sendgrid call | |
exports.handler = function(context, event, callback) { | |
// todo: put this in the environment | |
// Get a webhook URL like this: https://www.digitalocean.com/community/tutorials/how-to-use-discord-webhooks-to-get-notifications-for-your-website-status-on-ubuntu-18-04 | |
const discord_url = "<your discord webhook URL here"; | |
console.log(event.Body) | |
got.post(discord_url, { | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify({"username": "Spidey Bot", "content": `Text from ${event.From}: ${event.Body}`}) | |
}) | |
.then(response => { | |
let twiml = new Twilio.twiml.MessagingResponse(); | |
callback(null, twiml); | |
}) | |
.catch(err => { | |
callback(err); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment