/module-twilio

Primary LanguageBallerinaApache License 2.0Apache-2.0

Build Status

Twilio Connector

The Twilio connector allows you to send SMS, voice, and OTP messages through the Twilio REST API. You can also send user secrets via SMS or voice message, verify OTP, and add and delete users. It handles basic authentication.

Compatibility

Ballerina Language Version Twilio Basic API Version Twilio Authy API Version
0.990.0 2010-04-01 v1

Getting started

  1. Refer the Getting Started guide to download and install Ballerina.

  2. To use Twilio endpoint, you need to provide the following:

    • Account SId
    • Auth Token
    • Authy API Key

    Please note that, providing Authy API Key is required only if you are going to use Authy related APIs

  3. Create a new Ballerina project by executing the following command.

    <PROJECT_ROOT_DIRECTORY>$ ballerina init
  4. Import the Twilio module to your Ballerina program as follows.

    import ballerina/config;
    import ballerina/io;
    import wso2/twilio;
    
    public function main() {
        twilio:TwilioConfiguration twilioConfig = {
            accountSId: config:getAsString(ACCOUNT_SID),
            authToken: config:getAsString(AUTH_TOKEN),
            xAuthyKey: config:getAsString(AUTHY_API_KEY)
        };
        twilio:Client twilioClient = new(twilioConfig);
    
        var details = twilioClient->getAccountDetails();
        if (details is twilio:Account) {
            io:println(details);
        } else {
            //error
            io:println(details);
        }
    }