ballerinax/twilio.listener Ballerina library

2.2.1

Overview

The Twilio Listener connector allows you to listen to Twilio SMS and Call status change events.

  1. Listen to incoming message events and message status change callback events from the twilio SMS
  2. Listen to incoming call events and call status change callback events from the twilio Voice Call

This module supports Twilio Basic API 2010-04-01 version.

Prerequisites

Before using this connector in your Ballerina application, complete the following:

  • Create Twilio Account to obtain Account SID, Auth Token and Twilio phone number
  • Obtain tokens
  1. Create a twilio account and follow this link to obtain a twilio phone number. If you use a trail account, you may need to verify your recipient phone numbers before having any communication with them.

  2. Go to this follow this link to obtain twilio Account Auth Token.

  3. You need to provide port number where the twilio listener listens for any twilio events requests from Twilio service

  4. You also need to provide a callback url before running the listener with suffix "onChange" example: <YOUR_CALL_BACK_URL>/onChange

  • Configure the connector with obtained tokens
Quickstart

To use the twilio listener in your Ballerina application, update the .bal file as follows:

Note:

Callback URL registration method depends on the event type.

  1. Twilio SMS
  • Incoming Messages
    • Callback webhook URL has to be registered in the console under the particular Twilio number.
  • Status change events
    • Callback webhook URL has to be registered at the time of sending the SMS (from the client connector)
  1. Twilio Call
  • Incoming Call
    • Callback webhook URL has to be registered in the console under the particular Twilio number.
  • Status change events
    • Callback webhook URL has to be registered at the time of making the call (from the client connector)

Step 1 - Import listener

Copy
import ballerinax/twilio.'listener as twilioListener;

Step 2 - Create a new listener instance

Copy
configurable string & readonly twilioAuthToken = ?;
configurable string & readonly callbackUrl = ?;
configurable int & readonly port = ?;

listener twilioListener:Listener tListener = new (port, twilioAuthToken, callbackUrl);

Step 3 - Add a service

  1. Add a service with necessary remote functions as below
Copy
service / on tListener {
    remote function onSmsDelivered(twilioListener:SmsStatusChangeEvent event) returns error? {
        log:printInfo("Delivered", event);
    }
}
  1. Use bal run command to compile and run the Ballerina program.

You can find more samples here

Import

import ballerinax/twilio.listener;Copy

Metadata

Released date: almost 2 years ago

Version: 2.2.1

License: Apache-2.0


Compatibility

Platform: java11

Ballerina version: 2201.0.1


Pull count

Total: 1562841

Current verison: 1754


Weekly downloads


Source repository


Keywords

Communication/Call & SMS

Cost/Paid


Contributors

Other versions

See more...