In this section we are going to build a simple REST API that calls a “Programmable Voice call and SMS” via using Twilio APIs.
This example is based in one of the samples provided by Twilio (see below).
Original Calling clicktocall-node NodeJS project.
This is the orignal examples/tutorials provided by Twilio. See https://www.twilio.com/docs/tutorials/walkthrough/click-to-call/node/express for more information.
How It Works
This helps demonstrates how to initialize a call using the Twilio REST API and how to create a TwiML call logic using the Say verb. I am assuming to be using a Debian based Linux environment (e.g. Ubuntu 16.04)
Let’s go over the necessary steps to implement click-to-call
- A website visitor wants to connect to your organization. She submits a web form with her phone number to receive a call connecting her to your sales or support team.
- Your web application receives the submission form. An HTTP request is initiated from your application to Twilio to initiate an outbound call.
- Twilio receives the request and initiates a call to the user’s phone number.
- User receives the call.
- After the call connects, Twilio asks our application for TwiML instructions. Our TwiML instructs Twilio to connect the user to our sales or support teams.
Extending original Twilio based NodeJS clicktocall example
By now you should understand how the original Twilio sample works, if not get back and try these steps first. Now it is time to extend the original demo to allow the ability to also:
- Send SMS
Allow “Call Menus”, i.e. the end user will be able to to dial keys and gather such actions to the determine specific actions – For example:
- Integrate seamlessly with existing Salesforce APIs (https://solutionsanz.blog/2016/11/22/teaching-how-to-integrate-salesforce-with-ics/)
- Integrate seamlessly with existing Facebook APIs (https://solutionsanz.blog/2016/11/22/teaching-how-to-integrate-facebook-with-ics/)
- Integrate seamlessly to existing LinkedIn APIs (https://solutionsanz.blog/2016/11/22/teaching-how-to-integrate-linkedin-with-ics/)
- Establish group conference,
Follow the next steps to build this example:
- Go to the GitHub repository of this project (https://github.com/barackd222/s2v-iia-nodejs-voicesms-apis) and download the entire project (either clone or download zip file). If you decide to simply download the zip file, unzip it in a known location where you want to run your project.
Edit ~/.bashrc and set your account configuration values. Replace the values accordingly.
Ensure the variables are set properly:
echo $TWILIO_ACCOUNT_SID && echo $TWILIO_AUTH_TOKEN && echo $TWILIO_NUMBER
Make sure you see the values. Otherwise you will have to re-start your shell session.
Move within your project folder (make sure you are in the same location as in package.json) and install npm dependencies:
npm install body-parser
npm install http https
You also need body-parser module to [arse JSON payloads as part of the POST body:
Install body-parser (see https://scotch.io/tutorials/use-expressjs-to-get-url-and-post-parameters for more information)
|If you need to further use this module to easily parse JSON payload objects, in your code:
- Make sure all dependencies are installed successfully
Run the application:
The application will show you the port where it is running on.
- Open a browser window and go to http://[IP]:[Port]