Oracle APEX Blog

Introduction to Integrating APEX with Twilio

Written by Philip Ratcliffe | Jun 21, 2023 11:14:41 AM

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.

What is Twilio?

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):

  • Send and receive text messages e.g. for SMS, WhatsApp, Chat
  • Deliver email messages at scale
  • Make, receive and monitor voice calls
  • Build real-time HD video applications using WebRTC (Web Real-Time Communication)
  • SIP Trunking to run cloud-based phone services for traditional landline systems
  • Connect Internet of Things devices to global cellular networks

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.

Twilio API

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:

SMS

  • Send and Receive SMS and MMS messages
  • Track delivery of sent messages
  • Schedule SMS messages to send later

Voice

  • Make and manage outgoing calls
  • Modify in-progress calls e.g. redirect, hang-up
  • Create conference calls, call queues
  • Take call recordings

Video

  • Capture, distribute, record, and render high-quality audio and video applications

Others

  • Phone verification to prevent account fraud
  • Conversational messages for Chat, WhatsApp
  • Two-factor authentication for online accounts/transactions
  • Proxy – phone number privacy for text voice

Getting Started with Twilio

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.

Twilio CLI

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).

Twilio Documentation

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.

Sending an SMS Message

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.

Integrating with APEX

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:

https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Messages.json

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.

Summary

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.

For more information, check out our APEX services, and if you liked this blog, check out our other APEX blogs here.