Skip to main content

Twilio

Twilio event integrations receive webhook callbacks from the Twilio platform and trigger handler functions as call or message status changes occur. Use them to track call progress, monitor SMS delivery, and build real-time communication workflows without polling the Twilio API.

Creating a Twilio events service

note

The Twilio webhook listener must be reachable from the internet. For local development, use a tunneling tool such as ngrok to create a public URL for your local port. In production, deploy the integration to a publicly accessible host.

After starting the integration, configure the webhook URL in the Twilio Console under your phone number settings:

  • For SMS status callbacks: set the A MESSAGE COMES IN webhook to http://<your-host>:<port> with method HTTP POST.
  • For call status callbacks: set the STATUS CALLBACK URL to http://<your-host>:<port> with method HTTP POST.
  1. Click + Add Artifact in the canvas or click + next to Entry Points in the sidebar.

  2. In the Artifacts panel, select Twilio under Event Integration.

  3. In the creation form, fill in the following fields:

    Twilio Event Integration creation formTwilio Event Integration creation form
    FieldDescriptionDefault
    Event ChannelThe Twilio event channel to subscribe to. Select CallStatusService to handle call status events or SmsStatusService to handle SMS status events.Required
    Webhook Listener PortThe port on which the webhook listener accepts incoming requests from Twilio.8090

    Expand Advanced Configurations to set the listener name.

    FieldDescriptionDefault
    Listener NameIdentifier for the listener created with this service.twilioListener
  4. Click Create.

  5. WSO2 Integrator opens the service in the Service Designer. The canvas shows the attached listener pill and the Event Handlers section with all handlers for the selected channel pre-added.

    Service Designer showing the Twilio Event Integration canvasService Designer showing the Twilio Event Integration canvas

    All event handlers for the selected channel are added automatically. Click any handler to open it in the flow diagram view and implement the logic.

Service and listener configuration

In the Service Designer, click the Configure icon in the header to open the Twilio Event Integration Configuration panel.

Twilio Event Integration Configuration panelTwilio Event Integration Configuration panel

The configuration panel has two sections. The top section configures the service and the bottom section configures the attached listener.

Service configuration:

FieldDescription
Event ChannelThe Twilio event channel this service handles. Select CallStatusService or SmsStatusService.

Listener configuration (under Configuration for twilioListener):

FieldDescriptionDefault
NameIdentifier for the listener.twilioListener
Listen OnPort on which the listener accepts incoming webhook requests.8090

Click + Attach Listener to attach an additional listener to the same service.

Click Save Changes to apply updates.

Event handlers

When a Twilio Events service is created, WSO2 Integrator adds all handlers for the selected channel automatically. Click any handler in the Service Designer to open the flow diagram view and implement the processing logic.

CallStatusService handlers

The CallStatusService channel provides handlers for each Twilio call state.

HandlerTriggered when
onQueuedThe call has been created and is waiting to be dialed
onRingingThe call is ringing at the destination
onInProgressThe call has been answered and is active
onCompletedThe call ended normally
onBusyThe destination returned a busy signal
onFailedThe call could not be connected
onNoAnswerThe destination did not answer
onCanceledThe call was canceled before it was answered

SmsStatusService handlers

The SmsStatusService channel provides handlers for each Twilio SMS delivery state.

HandlerTriggered when
onAcceptedTwilio has accepted the message request
onQueuedThe message is queued for delivery
onSendingTwilio is in the process of sending the message
onSentThe message has been dispatched to the carrier
onFailedThe message could not be sent
onDeliveredThe carrier confirmed delivery to the recipient
onUndeliveredThe carrier received the message but could not deliver it
onReceivingAn inbound message has been received and is being processed
onReceivedAn inbound SMS message was fully received

Error handling

Service callbacks return error?. If a handler returns an error, the listener returns a non-2xx HTTP response to Twilio, which triggers Twilio's retry mechanism. Handle expected failures within the callback and return () (nil) to acknowledge the event without triggering a retry.

What's next

  • Kafka — consume messages from Apache Kafka topics
  • MQTT — subscribe to MQTT topics for IoT and lightweight messaging
  • Connections — reuse Twilio credentials across services
  • Twilio connector reference — full connector API reference