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 :: javascript max 
Javascript :: JS stack array backwards 
Javascript :: async arrow function in javascript 
Javascript :: mongoose number bigger 
Javascript :: link to website electron 
Javascript :: what is side effect 
Javascript :: async wait for axios reactjs 
Javascript :: Deploying Node.js Apps on Heroku 
Javascript :: express octet stream 
Javascript :: json data example 
Javascript :: generate angular component in a folder 
Javascript :: javascript ES6 Default Parameter Values 
Javascript :: node sudo nvm 
Javascript :: reverse integer in javascript 
Javascript :: file_get_contents in javascript 
Javascript :: uuid in node js 
Javascript :: make property read-only javascript 
Javascript :: react eslint prettier 
Javascript :: dinamically add checked to checkbox 
Javascript :: how to use a regex expression in kibana query 
Javascript :: volume slider javascript 
Javascript :: let var 
Javascript :: jquery recharger la page 
Javascript :: javascript createelement innerhtml 
Javascript :: javascript closure 
Javascript :: js add html element 
Javascript :: fetch json data into array 
Javascript :: json parse cause Unexpected token in JSON at position 550 
Javascript :: use inline and other styles react native 
Javascript :: concat strings shopify liquid 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =