Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

send sms using twilio in node

const smsSid = process.env.SMS_SID
const smsAuthToken = process.env.SMS_AUTH_TOKEN
const twilio = require('twilio')(smsSid, smsAuthToken, {
    lazyLoading: true,
});

async sendBySms(phone, otp) {
        return await twilio.messages.create({
            to: phone,
            from: process.env.SMS_FROM_NUMBER,
            body: `Your codershouse OTP is ${otp}`,
        });
    }
Comment

send sms with twilio

function send_sms($number,$body)
{
    $ID = '1234567890abcdef1234567890abcdef12';
    $token = '1234567890abcdef1234567890abcdef';
    $service = 'AB1234567890abcdef1234567890abcdef';
    $url = 'https://api.twilio.com/2010-04-01/Accounts/' . $ID . '/Messages.json';

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);

    curl_setopt($ch, CURLOPT_HTTPAUTH,CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_USERPWD,$ID . ':' . $token);

    curl_setopt($ch, CURLOPT_POST,true);
    curl_setopt($ch, CURLOPT_POSTFIELDS,
        'To=' . rawurlencode('+' . $number) .
        '&MessagingServiceSid=' . $service .         // this is optionnel
        //'&From=' . rawurlencode('+18885550000') .  // this is required
        '&Body=' . rawurlencode($body));

    $resp = curl_exec($ch);
    curl_close($ch);
    return json_decode($resp,true);
}

/*
$ID and $token can be found under SMS / Dashboard / 'Show API Credentials' https://www.twilio.com/console/sms/dashboard

(Optional) $service can be found under SMS / Messaging Services / 'SID' https://www.twilio.com/console/sms/services

Comment out 'MessagingServiceSid=' and uncomment 'From=' to use direct sending from a single phone number

Finally, key information can be found buried in the kb here https://www.twilio.com/docs/sms/send-messages#send-a-message-with-an-image-url

*/
Comment

PREVIOUS NEXT
Code Example
Javascript :: biggest number javascript 
Javascript :: run code snippet 
Javascript :: async function 
Javascript :: form validation jquery input array 
Javascript :: node mac copy to clipboard 
Javascript :: react-select 
Javascript :: nodejs save blob file 
Javascript :: arrow functions in es6 
Javascript :: check fpr multiple values in an array jquery 
Javascript :: current date in mongodb 
Javascript :: html content in jspdf 
Javascript :: mac os chrome opne debug new tab 
Javascript :: jquery validate array input not working 
Javascript :: concat class name vue js 
Javascript :: how to include js file in react 
Javascript :: random function in javascript 
Javascript :: reverse sort array of objects 
Javascript :: express session 
Javascript :: Duplicate empty header occur in datatable when enabling scrollX or scrollY when using Google Chrome 
Javascript :: how to check if input is string javascript 
Javascript :: how to check if a date has passed javascript 
Javascript :: let var diferencia 
Javascript :: react native firebase community template 
Javascript :: Javascript - convert string value to lowercase 
Javascript :: Download excel using reactJS 
Javascript :: jquery datepicker 
Javascript :: how to install nuxtjs with tailwind css 
Javascript :: Add Image For React Native 
Javascript :: jquery remove multiple class 
Javascript :: load external javascript from console 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =