Making Phone calls with the help of Twilio in Node.js application
In today's applications we need functionalities to make calls and receive calls. You need to meet the below requirements before we start.
Set up a free Twilio account.
Node.js
A phone to test the project.
First step is to set up a new Node.js Project. In a new directory open a terminal or command prompt and type the following commands.
mkdir nodejs-phone-call cd nodejs-phone-call
Then install Twilio Node Helper Library with the following command line.
npm install twilio
Your Node.js project needs your Twilio credentials like Account SID and Auth Token. Create a .env file in your project and add these credentials in it. Set TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN as environment variables to store the values. Then buy a Twilio number. You can provide instructions using Twilio markup language TwiML. When someone makes a call to your Twilio number, Twilio looks up the URL associated with your number and sends a request to the URL. Twilio will follow the instructions sent using TwiML. You can host TwiML through Twilio in a TwiML Bin. To create a new TwiML Bin click create new TwiML Bin button. You will be redirected to a new page where you can configure your bin. You should give a name to your bin first then copy and paste the following TwiML into the TwiML field .
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>Hello, from Node.js!</Say>
</Response>
Then click the create button and copy the URL. To make a phone call, create a new JavaScript file in the Nodejs-phone -call directory which you created at the beginning. Paste the following code in the JavaScript file.
require('dotenv').config();
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);
client.calls
.create({
from:'<YOUR_TWILIO_PHONE_NUMBER>',
to:'<YOUR_PHONE_NUMBER>',
url: '<YOUR_TWIML_BIN_URL>'
})
.then(call => console.log(call.sid));
Update the above code with Twilio Phone number, personal phone number, URL you copied from TwiML bin.
Run the script using the below given command.
node make-call.js
Ace Reid
22 Mar 2023
For treatment of sexual health, hair loss treatments, and wellness. CialisvsViagra [url=https://www.ultrapharmrx.com/]CialisvsViagra[/url]
Ace Reid
22 Mar 2023
Cialis vs Viagra blackhatway
sam smith
16 Apr 2023
I just want the whole world to know about this spell caster I met two weeks ago, I cannot say everything he has done for me my wife left me 3 years ago left with my kids I was going through online when I meant this wonderful man's testimony online I decided to give it a try and my wife is back to me now and we are happily married again cause is too much to put in writing all I can say is thank you very much am very happy Contact him today on oseremenspelltemple@gmail.com or whatsapp him on +2348136482342. www.facebook.com/Dr-odion-spell-temple-110513923938220
Sadiq Sabir
25 Jul 2024
These is apparently just like definitely great. Most of these modest items are designed through the use of variety of base consciousness. I love these significantly. Smart hemp gummies
Sadiq Sabir
25 Jul 2024
This type of looks entirely finest. These tiny details are usually made along with a lot of foundation details. I prefer in which a lot. manup gummies
Sadiq Sabir
25 Jul 2024
The looks really great. Most of these smaller details are usually created employing wide range of heritage knowledge. I would like all of it substantially. NOVA PLATAFORMA