Created
March 5, 2024 13:53
-
-
Save Vigowebs/cf89ba263385a3524ab0ba8ff1df5770 to your computer and use it in GitHub Desktop.
Send SMS using Twilio
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
//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)); |
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
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