Module twilio
ballerinax/twilio Ballerina library
Overview
The Twilio API provides capability to access its platform for communications. These APIs connects the software layer and communications networks around the world to allow users to call and message anyone, globally.
This module supports Twilio Basic API version 2010-04-01.
Prerequisites
Before using this connector in your Ballerina application, complete the following:
- Create a Twilio account.
- Obtain tokens as follows:
-
Create a Twilio account.
-
Obtain a Twilio phone number.
!!! Tip
If you use a trail account, you may need to verify your recipient phone numbers before having any communication with them.
-
Obtain a Twilio Account Auth Token.
-
If you want to use WhatsApp service, Configure your Twilio phone number to use WhatsApp services. For instructions, see Twilio Documentation - Manage and Configure Your WhatsApp-enabled Twilio Numbers.
-
Configure the connector with obtained tokens.
Quickstart
To use the Twilio connector in your Ballerina application, update the .bal file as follows:
Step 1 - Import connector
Import the Twilio module to your Ballerina program as follows. You can use configurable variables to provide the necessary credentials.
import ballerinax/twilio;
Step 2 - Create a new connector instance
To create a new connector instance, add a configuration as follows:
configurable string accountSId = ?; configurable string authToken = ?; twilio:ConnectionConfig twilioConfig = { auth: { accountSId: accountSId, authToken: authToken } }; twilio:Client twilioClient = new (twilioConfig);
Step 3 - Invoke connector operation
- Invoke the connector operation using the client as follows:
public function main() returns error? { twilio:Account response = check twilioClient->getAccountDetails(); }
- Use
bal run
command to compile and run the Ballerina program.