Twilio is a cloud communications platform whose aim is to drive communications to and from your applications. In this blog, I have an introductory look at Twilio and explore how we can integrate it with APEX applications.
Twilio sees itself as, on the one hand, a software application and, on the other, a communications system - it acts as a bridge between the two. Its purpose is to improve communications to and from your applications, providing APIs that allow application developers to leverage at-scale communications.
Twilio offers numerous different products or channels for communication connectivity, including (but not limited to):
Twilio offers pre-built applications to help organisations with communication solutions. Alternatively, they also provide communications API that developers can employ to integrate communications into their business applications.
To take advantage of the Twilio API, they provide many Software Development Kits (SDKs), including modules for Node.js, PHP, .NET, Java, Python and more. In addition, there are REST APIs available.
The APIs provide a mechanism to allow your applications to perform the following functionality, for example:
To begin developing with Twilio for free, the first thing to do is set up a Twilio account, which you can do here by clicking the ‘Start for free’ button. In doing so, you will obtain access to the Twilio console. Here you can configure your Twilio account, including ‘purchasing’ a Twilio virtual phone number. This, effectively, becomes your ‘from’ phone number. The free trial allows $15 of transactions.
On creation of your account, you will be provided with an Account SID and Auth Token – used for connectivity with Twilio.
For free trial accounts, you will only be able to make calls or send SMS from your free trial account to numbers that are verified caller IDs on the account. So you may want to add an existing non-Twilio phone number as a Verified Caller ID in the console.
Twilio offers a Command Line Interface (CLI) to get started and practice using the API.
The Twilio CLI allows you to manage your Twilio resources from your terminal or command prompt.
A quick start guide to installing the CLI and logging into your Twilio account is available here.
Once you have installed the CLI, you can run the Twilio command from the command line to access Twilio. You will need to create a profile that links to your Twilio account (a useful resource for getting started is the video tutorial).
There is comprehensive API reference documentation available to help get started working with the API, providing sample code and the developer tools you need.
So, for example, under SMS > API Reference > Message Resource, we can quickly grab a code snippet that will allow us to create an SMS text message in the Twilio CLI.
By copying the snippet from the documentation into the CLI and amending the ‘from’ and ‘to’ telephone numbers, we can quickly generate a message, then use the CLI commands to interrogate the status of the message – successfully delivered.
A similarly simple command could be used to send a message via WhatsApp, but note you will need to activate your Twilio sandbox phone number for use with WhatsApp.
We can integrate our APEX applications with Twilio by making use of the REST API.
So, for example, to similarly send an outgoing SMS message from our APEX application, we need to make an HTTP POST to the Messages list resource URI:
The code snippet below shows the basic PL/SQL construct for sending an SMS message from within APEX.
Of course, to get started, this is a simple send of a text message. But the API will allow you to extend the communications functionality of your applications as outlined earlier.
Twilio offers a comprehensive set of tools for managing communications to and from your applications. If you find that the pricing for Twilio makes commercial sense, then with developer tools including the Console, a CLI and multiple APIs alongside comprehensive documentation, Twilio appears to be an accessible platform to get started in integrating an extensive range of communications into your applications.