Picture the situation. You are working on a task that requires you to immediately connect to an on-call employee. You dial their phone number, but it hits their voicemail. Who do you call to resolve the situation?
This use case is not uncommon in organisations that utilise shifts or rosters for their workforce management, and it usually results in the employee having to manually search an on-call roster document for another phone number to call. This process is fine for some use cases, but imagine that the situation was time-critical and needed an immediate response, where every minute and second was critical. Would you want this process to be manual? Probably not.
So what can we do? We can build an automated notification solution using Twilio Programmable Voice, Twilio SMS and Twilio Functions.
Prerequisites
If you are following along and want to implement this solution, you will need to have the following prerequisites:
- A Twilio account and Twilio phone number
- Twilio Serverless Toolkit installed
- Update Geo Restrictions to allow for outbound calls to your country of choice
- An additional phone number to use as primary/secondary on-call. You can use the same number for primary/secondary.
You can see the full code on GitHub.
Introduction
Organisations in various industries make use of on-call rosters to respond to events and emergencies outside of working hours. On-call employees are usually expected to be available at any time and with short notice. Clinicians, engineers, emergency services frequently using on-call systems.
An on-call system typically consists of a user interface, where an administrator updates the roster, and a notification mechanism. The inbound event to trigger a notification to the on-call person could be a sensor (IoT), a high severity ticket (webhook), a person in distress (SMS), or a patient contacting a clinician (call).
In this blog post, we will use a call as an example of the inbound event. We will focus on the notification mechanism with the on-call roster hosted in Twilio functions environmental variables. For a more advanced solution that allows you to create rules to automatically adjust your roster, you can consider expanding the solution by using Google Sheets or Microsoft Sharepoint. For Sheets you could explore the use of macros/formulas, and for Sharepoint you could use MS flow to automate the roster updates.
Consider the following use case:
Clinical laboratories usually consist of a number of medical technologists who all work on the analysis of specimens. However, there are certain cases where the expertise of a specialised clinician is required. A medical technologist has to access a portal and can manually call the first person, the secondary etc. on the roster. Wouldn’t it be easier to dial one number and automatically be able to speak to the ‘best’ available person?
Additionally, what if we could also detect when the primary on-call clinician is not available so we can automatically call the secondary, the tertiary, etc. This raises a few different edge cases that could also occur during the process, such as if the primary call hit voicemail, was busy, declined the call or the call timed out.
To detect voicemail we could use Twilio Answering Machine Detection (AMD) and for the rest we evaluate the status callback. The optional StatusCallbackEvent parameter lets you specify which call progress events Twilio will act on. You can use this parameter to tell Twilio to send information to the StatusCallback URL you specified when a call is initiated, ringing, answered, or completed.
The call flow will be as follows:
For the purposes of this tutorial, we would also like to record the calls for compliance and training purposes.
Dependencies and configuration for your build
Download the code and install the dependencies: