Skip to content

Instantly share code, notes, and snippets.

@mandarg
Created January 20, 2021 14:24
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 mandarg/b7fa8a9e8ab8477a594f835ba7ae0aae to your computer and use it in GitHub Desktop.
Save mandarg/b7fa8a9e8ab8477a594f835ba7ae0aae to your computer and use it in GitHub Desktop.
Forward SMS to Twilio channel
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