Forward SMS Message to Discord Using Twilio
Step 1: Create a Discord Channel
Start by click on this icon on your Discord app.
Go through the steps and name your server.
Next, find a channel you would like to send messages to. Click on this icon to "Edit Channel".
In "Integrations", create a webhook.
Name the bot, hit save, and save the webhook URL for later.
Step 2: Twilio Setup
Create an account or sign into Twilio, and deploy this application.
Once deployed, click "Go to live application", and click the "Edit this application" button.
Under Settings -> Environment Variables, add a new key named DISCORD_WEBHOOK_URL and paste in your webhook.
Under Settings -> Dependencies, add module got 11.8.3
(Be sure to use this version!)
Go to Functions and select your function file.
Delete the boilerplate code and add the follow snippet:
// Make sure the function is async!
exports.handler = async function (context, event, callback) {
const twiml = new Twilio.twiml.MessagingResponse();
const { default: got } = await import('got');
const url = context.DISCORD_WEBHOOK_URL;
const options = {
json: {
username: "Your Bot Name",
avatar_url: "",
content: `${event.Body}`
}
}
got.post(url, options)
.then(function(response) {
console.log(response.body)
});
};
Now, click Save and then Deploy All.
Step 3: Deploy and Test
Try sending a text message to your Twilio phone number and you should receive the text in your Discord channel.
And there you go, you have successfully forwarded SMS messages to a Discord channel!