Skip to content

Instantly share code, notes, and snippets.

@Vigowebs
Created March 5, 2024 13:53
Show Gist options
  • Save Vigowebs/cf89ba263385a3524ab0ba8ff1df5770 to your computer and use it in GitHub Desktop.
Save Vigowebs/cf89ba263385a3524ab0ba8ff1df5770 to your computer and use it in GitHub Desktop.
Send SMS using Twilio
//Load the packages
const twilio = require("twilio");
require("dotenv").config();
//Initiate the twilio client with Account SID, token, Phone Number and Receiver Number
//You will find the Account SID and token in your Twilio account page
// for testing create a test phone number in Twilio
// for receiver update your mobile number
// Update all the 4 details in the .env file
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const phoneNumber = process.env.TWILIO_PHONE_NUMBER;
const receiver = process.env.RECEIVER_PHONE_NUMBER;
const client = twilio(accountSid, authToken);
//Send the SMS
client.messages
.create({
body: "Hello from Vigowebs",
from: phoneNumber,
to: receiver,
})
.then((message) => console.log(message.sid))
.catch((error) => console.log(error));
TWILIO_ACCOUNT_SID=<TWILIO_ACCOUNT_SID>
TWILIO_AUTH_TOKEN=<TWILIO_AUTH_TOKEN>
TWILIO_PHONE_NUMBER=<TWILIO_PHONE_NUMBER>
RECEIVER_PHONE_NUMBER=<RECEIVER_PHONE_NUMBER>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment