Build a Modern Hotline with Twilio Programmable Voice and Sync

June 23, 2022
Written by

Modern Hotline Voice Hero

In this article, you will unlock the powers of using a Twilio Programmable Voice's conference bridge to connect your loved ones in a single phone call. This blog post could work for Healthcare, Corporate, or Educational Institutions – I’ll show you all the steps you’ll need to connect a list of numbers in a single conference call.

Prerequisites

To get you started with this article, you need the following

  • Twilio phone number

    A number that connects the institution with its emergency contacts through a conference call.
  • Twilio Studio access

    A visual builder to create, edit, and manage communication workflows in Twilio Studio. Our low-code/no-code application builder makes complex implementations extremely easy.  
  • Twilio Sync services

    Twilio Sync is Twilio's state synchronization service, offering two-way real-time communication between browsers, mobiles, and the cloud. Using Sync helps you avoid building all the real-time infrastructure.
  • Twilio Cli

    Twilio-CLI allows you to manage your Twilio resources from your terminal or command prompt.

Architecture

The following diagram shows what we’re building today. An Admin of an institution – pictured on the left – will use a variety of Twilio services to connect users to a conference bridge.

In today’s tutorial, we will build a hotline for a school to quickly conference a number of parents.

Architecture of a modern conference line using Twilio

Implementation

Clone the following project. Navigate to the folder /twilio/serverless and run the following commands.

npm install
twilio serverless:deploy

This command returns the following output:

Deployment Details
Domain: serverless-xxx-dev.twil.io
Service:
   serverless (ZS4907bbxxxxxxxxxx8cd698424398)
Environment:
   dev (ZEc6244950xxxxxxxxxa198e1aea163)
Build SID:
   ZBc27bee97xxxxxxxxxx5b2e48ce0a3b
Runtime:
   node14
View Live Logs:
   https://www.twilio.com/console/functions/editor/ZS4907bbdxxxxxxxca8cd698424398/environment/ZEc624xxxxxxxxx198e1aea163
Functions:
   [protected] https://serverless-xxx-dev.twil.io/studio/execution/create
   [protected] https://serverless-xxx-dev.twil.io/sync/document/read
Assets:

Save the information generated with the domain name; in our case, it is serverless-xxx-dev.twil.io.

Create a Studio Flow

Open the Twilio Studio executions page from the Twilio Console, create a new Studio Flow, and import /twilio/studio/Parent-Hotline-Outbound.json.

Call the number purchased to grab the flow SID from the logs. Flow SID can also be derived from the REST API.

Next, create a new Studio Flow and import /twilio/studio/Parent-Hotline-Inbound.json from the git repository. Open the SetGlobalVariables widget to configure the key/value pairs for the following variables:

SYNC_SERVICE_SID
PARENT_HOTLINE_OUTBOUND_FLOW_SID
SERVERLESS_DOMAIN_NAME

The SERVERLESS_DOMAIN_NAME value is set to the domain name generated by the serverless CLI code above; in our case, it is serverless-xxx-dev.twil.io. SYNC_SERVICE_SID can be obtained and set from the previous studio's Parent-Hotline-Outbound Flow SID. And finally, SYNC_SERVICE_SID by adding a sync service.

Create a Sync Service” to store near & dear phone numbers

Open the Sync console by navigating through the explore products menu in the Twilio console.

  • Create a new Sync Service, then create a new Sync Document.
  • Add the following fields to the document:
    • Unique Name: Twilio Phone Number
    • Document Data: {"Parents":["+1XXXXXXXXXX","+1XXXXXXXXXX"]}

Upon completion of the Sync service in the console, the Sync ID is generated. Use it to set SYNC_SERVICE_SID in the Studio execution above. This completes the initial setup process and ensures that the Studio execution is published and saved.

Understanding the Studio Flows

  1. Parent-Hotline-Outbound
Make an outbound conference call with Twilio Studio


In this execution, when the institution, such as a school, calls a Twilio number, we trigger a RESTful API call. We grab the institution number and create a conference bridge with the institution and the Twilio number. 
  • Parent-Hotline-Inbound

    Since there is an incoming call to the Twilio number, we have another separate Studio Flow that grabs a few parameters such as SYNC_SERVICE_SID, which is a service to store all the near and dear phone numbers. (In our example, it's the parent's number).

    Also, we set the values of the serverless Sync domain to obtain the Sync records and parents' phone numbers and, finally, the conference flow ID to connect the institution to the parents.
Receive an inbound call to trigger a conference using Twilio Studio

 

As you see in the diagram above, we are looping through the Sync document to fetch individual phone numbers by making an HTTP request to the sync service. This would call both the parents and add them to the bridge so that the teacher and institution can contact the parents of a child to update their health condition or remind them of early pick-up, or anything else that requires group communications.   

Testing

Testing is straightforward –  dial the Twilio number, and see if the bridge connects all the numbers listed in the Sync document to a conference call.

Conclusion

Congratulations! You’ve now built  a conference bridge that solves the problem of linear calling when a mass call needs to be placed. And it’s not just limited to schools – for example, say a hospital needed to call all a patient's family and friends in one go, they could use this solution to debrief everyone on a single call. Similarly, it would help if a school wanted to connect with both the parents of a child or a business wanted to relay a message to a few employees. A conference bridge is an awesome companion.

Try this solution and lessen your CTA time calling linearly.  We can’t wait to see what you build!

Biography

Anthony Wong is a Principal Solutions Engineer at Twilio. He’s focused on building integration between Twilio and companies like Salesforce, so adoption is one-click away. He can be found at anwong [at] twilio.com

Pooja Srinath is a Principal Solutions Engineer at Twilio. She's focused on learning new software technologies that help create solutions, address use cases, and build apps solving some of the industry's toughest requirements. Pooja uses Twilio's powerful communication tools & APIs to build these ideas. She can be found at psrinath [at] twilio.com