Module twilio

dilans/twilio

5.0.0

Overview

Twilio is a cloud communications platform that allows software developers to programmatically make and receive phone calls, send and receive text messages, and perform other communication functions using its web service APIs.

The Ballerina Twilio connector currently supports the Twilio Basic API version 2010-04-01, enabling users to leverage these communication capabilities within their Ballerina applications.

Setting up the Twilio

Before using the ballerinax-twilio connector you must have access to Twilio API, If you do not have access to Twilio API please complete the following steps:

Step 1: Create a Twilio account.

Creating a Twilio account can be done by visiting Twilio and clicking the "Try Twilio for Free" button.

Step 2: Obtain a Twilio phone number.

All trial projects can provision a free trial phone number for testing. Here's how to get started.

Notice: Trial project phone number selection may be limited. You must upgrade your Twilio project to provision more than one phone number, or to provision a number that is not available to trial projects.

  1. Access the Buy a Number page in the Console. Get Phone Number

  2. Enter the criteria for the phone number you need, and then click Search. Configure Phone Number

  • Country: Select the desired country from the drop-down menu.
  • Number or Location: Select the desired option to search by digits/phrases, or a specific City or Region.
  • Capabilities: Select your service needs for this number.
  1. Click Buy to purchase a phone number for your current project or sub-account. Search Results

Notice: Many countries require identity documentation for Phone Number compliance. Requests to provision phone numbers with these regulations will be required to select or add the required documentation after clicking Buy in Console. To see which countries and phone number types are affected by these requirements, please see twilio's Phone Number Regulations site.

Step 3: Obtain a Twilio Account SID with Auth Token.

Twilio uses two credentials to determine which account an API request is coming from: The Account SID, which acts as a username, and the Auth Token which acts as a password. You can find your account SID and auth token in your Twilio console.

Twilio Credentails

Your account's Auth Token is hidden by default. Click show to display the token, and hide to conceal it again. For further information click here

Sample

This sample demonstrates a scenario where the Twilio connector is used to send a text message to a phone number.

Step 1 - Import the package

Import the Twilio package into your Ballerina program as shown below:

Copy
import ballerinax/twilio;

Step 2 - Create a new connector instance

To create a new connector instance, add a configuration as follows (You can use configurable variables to provide the necessary credentials):

Copy
configurable string accountSID= ?;
configurable string authToken = ?;

twilio:ConnectionConfig twilioConfig = {
    auth: {
        username: accountSID,
        password: authToken
    }
};

twilio:Client twilio = check new (twilioConfig);

Step 3 - Invoke the connector operation

  1. Invoke the connector operation using the client as shown below:
Copy
public function main() returns error? {
    twilio:Client twilio = check new (twilioConfig);

    twilio:CreateMessageRequest messageRequest = {
        To: "+XXXXXXXXXXX",
        From: "+XXXXXXXXXXX",
        Body: "Hello from Ballerina"
    };

    twilio:Message response = check twilio->createMessage(accountSID, messageRequest);

    io:println("Message Status: ", response?.status);
}
  1. Use bal run command to compile and run the Ballerina program.

You can find more samples here

Import

import dilans/twilio;Copy

Metadata

Released date: 10 months ago

Version: 5.0.0

License: Apache-2.0


Compatibility

Platform: any

Ballerina version: 2201.8.2

GraalVM compatible: Yes


Pull count

Total: 0

Current verison: 0


Weekly downloads


Source repository


Keywords

Communication/Call & SMS

Cost/Paid


Contributors

Other versions

See more...