top of page
Twilio Integration

Twilio Integration

Integrate with Twilio to make voice calls and send SMS messages

Intermediate.png

Advanced

6K

Published:

August 26, 2020

Girl Enjoying her Drink

by

Anchor 1
Hire a Developer

Example Description

In this example, we integrate the Twilio 3rd-party service with our site, allowing site agents to make phone calls and send SMS messages directly from the browser.

 

Note: To use this example, you must first create an account on Twilio as described here.

Example Code

Tab 1

.

Tab 2

.

Tab 3

.

This code solution can be complicated.

How We Built It

Collections


For this example we added a CountryCodes collection that contains country names, country calling codes, and ISO3166_1_Alpha_3  3-letter country codes. The collection populates the Country Code dropdown for selecting a country when setting your Twilio details on the site.

 

Page Elements


We added a form with 3 sections:

  • Twilio settings: A dropdown for selecting the country and text inputs for setting Twilio account details.

  • Make a call: 2 text inputs for the caller and recipient’s phone numbers.

  • Send SMS: 2 text inputs for the recipient’s phone number and the message text.

 

Code

 

Note: For the sake of simplicity, this example's auth token and SID are entered on the client-side. To prevent exposure of private information, always store site secrets in the Secrets Manager. Then use the Secrets API to securely retrieve secrets for use in your code.


Our site code does the following:

  1. Populate the Twilio settings dropdown with the countries from the collection.

  2. When a site visitor clicks the Set button, validate the inputs, store the account details, and enable the Call and Send buttons.

  3. When a site visitor clicks the Call button, get the Twilio account data that was set, validate the inputs, call the ‘makeCall()’ backend function, and handle success or error messages.

  4. In the backend, use the ‘phone’ npm to validate the phone numbers and convert them to ISO3166 format, and use the ‘twilio’ npm to make the call.

    Note: The Twilio service first calls the “To” (calling) number. After answering, the server calls the “From” (recipient) number and then connects the 2 with each other.
     

  5. When a site visitor clicks the Send button, get the Twilio account data that was set, validate the inputs, call the ‘sendSms()’ backend function, and handle success or error messages.

  6. In the backend, use the ‘phone’ npm to validate the phone number and convert it to ISO3166 format, and use the ‘twilio’ npm to send the SMS.

 

npm packages


  • phone: For validating the phone number and formatting it in the E.164 standard

  • twilio: Twilio helper library

APIs We Used

Non-code example.

Non-code example.

Non-code example.

Related Articles

Hire a Developer

Velo solutions are powerful tools, but building them on your own can be challenging. Let an experienced Velo development shop build it for you, so you can keep working on your site or business.

Related Examples

Did this help?

Yes

|

No

Thanks for your feedback!

Detect Image Labels

Detect Image Labels

Use Google’s vision NPM module to detect an image’s labels.

Intermediate.png

Advanced

Save Data to a Google Sheet Using npm

Save Data to a Google Sheet Using npm

Reveal sections of a hidden video on hover.

Intermediate.png

Intermediate

Send Email with the SendGrid npm Interface

Send Email with the SendGrid npm Interface

Use the SendGrid NPM library to send an email.

Intermediate.png

Intermediate

Anchor 2

This website was designed with Velo by Wix

bottom of page