Skip to content

Commit

Permalink
Update examples with new auth configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
SachinAkash01 committed Nov 18, 2024
1 parent 5b33842 commit 315a6c5
Show file tree
Hide file tree
Showing 27 changed files with 355 additions and 107 deletions.
16 changes: 0 additions & 16 deletions ballerina/Module.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,6 @@ twilio:ConnectionConfig twilioConfig = {
twilio:Client twilio = check new (twilioConfig);
```

As an alternative approach, you can authenticate with Account SID and Auth Token of your Twilio account. You can find your Account SID and Auth Token in your [Twilio console](https://console.twilio.com/)

```ballerina
configurable string accountSid = ?;
configurable string authToken = ?;
twilio:ConnectionConfig twilioConfig = {
auth: {
accountSid,
authToken
}
};
twilio:Client twilio = check new (twilioConfig);
```

### Step 3 - Invoke the connector operation

Invoke the sending SMS operation using the client as shown below:
Expand Down
16 changes: 0 additions & 16 deletions ballerina/Package.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,6 @@ twilio:ConnectionConfig twilioConfig = {
twilio:Client twilio = check new (twilioConfig);
```

As an alternative approach, you can authenticate with Account SID and Auth Token of your Twilio account. You can find your Account SID and Auth Token in your [Twilio console](https://console.twilio.com/)

```ballerina
configurable string accountSid = ?;
configurable string authToken = ?;
twilio:ConnectionConfig twilioConfig = {
auth: {
accountSid,
authToken
}
};
twilio:Client twilio = check new (twilioConfig);
```

### Step 3 - Invoke the connector operation

Invoke the sending SMS operation using the client as shown below:
Expand Down
87 changes: 84 additions & 3 deletions examples/accounts/create-sub-account/Create sub account.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,46 @@ This example demonstrates how to create a sub account under your Twilio account

## Prerequisites

### 1. Set up
Refer to the setup guide in [ReadMe](../../../README.md) for necessary credentials.
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:

### 2. Configuration
### Step 1: Create a Twilio account

Creating a Twilio account can be done by visiting [Twilio](https://www.twilio.com) 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](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-twilio/master/ballerina/resources/get-phone-number.png)

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

![Configure Phone Number](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-twilio/master/ballerina/resources/phone-number-config.png)

- 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.

3. Click Buy to purchase a phone number for your current project or sub-account.

![Search Results](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-twilio/master/ballerina/resources/search-phone-number.png)
> **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](https://www.twilio.com/guidelines/regulatory) 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](https://www.twilio.com/console).

![Twilio Credentials](https://raw.githubusercontent.com/ballerina-platform/module-ballerinax-twilio/master/ballerina/resources/get-credentails.png)

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](https://support.twilio.com/hc/en-us/articles/223136027-Auth-Tokens-and-How-to-Change-Them)

## Quickstart

### Configuration

Configure Twilio API credentials in Config.toml in the example directory:

Expand All @@ -16,6 +52,51 @@ accountSid="<Account Sid>"
authToken="<Auth Token>"
```

To use the `twilio` connector in your Ballerina application, modify the `.bal` file as follows:

### Step 1 - Import the module

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

```ballerina
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](https://ballerina.io/learn/by-example/configurable.html) to provide the necessary credentials):

```ballerina
configurable string accountSid = ?;
configurable string authToken = ?;
twilio:ConnectionConfig twilioConfig = {
auth: {
accountSid,
authToken
}
};
twilio:Client twilio = check new (twilioConfig);
```

### Step 3 - Invoke the connector operation

Invoke the sending SMS operation using the client as shown below:

```ballerina
public function main() returns error? {
twilio:Client twilio = check new (twilioConfig);
twilio:CreateAccountRequest subAccountReqest = {
FriendlyName: "Sample Sub Account"
};
twilio:Account subAccountInfo = check twilio->createAccount(subAccountReqest);
io:println(subAccountInfo.toString());
}
```

## Run the Example

Execute the following command to run the example:
Expand Down
7 changes: 4 additions & 3 deletions examples/accounts/fetch-account/Fetch account.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ This example demonstrates how to fetch account details for a Twilio account usin
## Prerequisites

### 1. Set up
Refer to the setup guide in [ReadMe](../../../README.md) for necessary credentials.
Refer to the setup guide in [Ballerina Central](https://central.ballerina.io/ballerinax/twilio/latest) for necessary credentials.

### 2. Configuration

Configure Twilio API credentials in Config.toml in the example directory:

```toml
accountSid="<Account Sid>"
authToken="<Auth Token>"
API_KEY="<API Key>"
API_SECRET="<API Secret>"
ACCOUNT_SID="<Account Sid>"
```

## Run the Example
Expand Down
8 changes: 5 additions & 3 deletions examples/accounts/fetch-account/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ import ballerina/io;
import ballerina/os;
import ballerinax/twilio;

configurable string apiKey = os:getEnv("API_KEY");
configurable string apiSecret = os:getEnv("API_SECRET");
configurable string accountSid = os:getEnv("ACCOUNT_SID");
configurable string authToken = os:getEnv("AUTH_TOKEN");

// Twilio configurations
twilio:ConnectionConfig twilioConfig = {
auth: {
accountSid,
authToken
apiKey,
apiSecret,
accountSid
}
};

Expand Down
7 changes: 4 additions & 3 deletions examples/accounts/fetch-balance/Fetch balance.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ This example demonstrates how to fetch account balance for a Twilio account usin
## Prerequisites

### 1. Set up
Refer to the setup guide in [ReadMe](../../../README.md) for necessary credentials.
Refer to the setup guide in [Ballerina Central](https://central.ballerina.io/ballerinax/twilio/latest) for necessary credentials.

### 2. Configuration

Configure Twilio API credentials in Config.toml in the example directory:

```toml
accountSid="<Account Sid>"
authToken="<Auth Token>"
API_KEY="<API Key>"
API_SECRET="<API Secret>"
ACCOUNT_SID="<Account Sid>"
```

## Run the Example
Expand Down
8 changes: 5 additions & 3 deletions examples/accounts/fetch-balance/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ import ballerina/io;
import ballerina/os;
import ballerinax/twilio;

configurable string apiKey = os:getEnv("API_KEY");
configurable string apiSecret = os:getEnv("API_SECRET");
configurable string accountSid = os:getEnv("ACCOUNT_SID");
configurable string authToken = os:getEnv("AUTH_TOKEN");

// Twilio configurations
twilio:ConnectionConfig twilioConfig = {
auth: {
accountSid,
authToken
apiKey,
apiSecret,
accountSid
}
};

Expand Down
7 changes: 4 additions & 3 deletions examples/accounts/list-accounts/List accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ This example demonstrates how to list down all the sub-accounts under a Twilio a
## Prerequisites

### 1. Set up
Refer to the setup guide in [ReadMe](../../../README.md) for necessary credentials.
Refer to the setup guide in [Ballerina Central](https://central.ballerina.io/ballerinax/twilio/latest) for necessary credentials.

### 2. Configuration

Configure Twilio API credentials in Config.toml in the example directory:

```toml
accountSid="<Account Sid>"
authToken="<Auth Token>"
API_KEY="<API Key>"
API_SECRET="<API Secret>"
ACCOUNT_SID="<Account Sid>"
```

## Run the Example
Expand Down
8 changes: 5 additions & 3 deletions examples/accounts/list-accounts/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ import ballerina/io;
import ballerina/os;
import ballerinax/twilio;

configurable string apiKey = os:getEnv("API_KEY");
configurable string apiSecret = os:getEnv("API_SECRET");
configurable string accountSid = os:getEnv("ACCOUNT_SID");
configurable string authToken = os:getEnv("AUTH_TOKEN");

// Twilio configurations
twilio:ConnectionConfig twilioConfig = {
auth: {
accountSid,
authToken
apiKey,
apiSecret,
accountSid
}
};

Expand Down
7 changes: 4 additions & 3 deletions examples/accounts/update-account/Update account.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ This example demonstrates how to update account details for a Twilio account usi
## Prerequisites

### 1. Set up
Refer to the setup guide in [ReadMe](../../../README.md) for necessary credentials.
Refer to the setup guide in [Ballerina Central](https://central.ballerina.io/ballerinax/twilio/latest) for necessary credentials.

### 2. Configuration

Configure Twilio API credentials in Config.toml in the example directory:

```toml
accountSid="<Account Sid>"
authToken="<Auth Token>"
API_KEY="<API Key>"
API_SECRET="<API Secret>"
ACCOUNT_SID="<Account Sid>"
```

## Run the Example
Expand Down
8 changes: 5 additions & 3 deletions examples/accounts/update-account/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ import ballerina/io;
import ballerina/os;
import ballerinax/twilio;

configurable string apiKey = os:getEnv("API_KEY");
configurable string apiSecret = os:getEnv("API_SECRET");
configurable string accountSid = os:getEnv("ACCOUNT_SID");
configurable string authToken = os:getEnv("AUTH_TOKEN");

// Twilio configurations
twilio:ConnectionConfig twilioConfig = {
auth: {
accountSid,
authToken
apiKey,
apiSecret,
accountSid
}
};

Expand Down
Loading

0 comments on commit 315a6c5

Please sign in to comment.