# How to configure Twilio

You can configure B2CORE to use the [Twilio](https://www.twilio.com/) communication platform to deliver 2FA codes via SMS or make phone calls to your clients via the B2CORE Back Office.

{% hint style="success" %}

### Key points

* For phone calls, you can select which active Twilio number to use if your account has multiple numbers. This allows you to choose the most suitable local number, increasing the chances of successful contact and enhancing client trust.
* Outgoing calls made from the B2CORE Back Office via Twilio can also be recorded, with the recordings saved in your Twilio account for later playback.
  {% endhint %}

The following information is required to configure a connection to Twilio via the Back Office:

* Twilio account SID
* Twilio authentication token
* Twilio phone number
* TwiML App SID

## How to sign up with Twilio

This instruction describes how to sign up with Twilio and obtain the required information to connect to Twilio via the Back Office.

{% hint style="info" %}
This instruction is created based on the latest version of Twilio as of this writing. Due to possible changes to the procedures described here, we suggest that you consult the official [Twilio Help Center](https://help.twilio.com/) or contact their support in case you have any questions.
{% endhint %}

{% stepper %}
{% step %}
Go to the [Twilio](https://www.twilio.com/) website and sign up to create a new account.

By default, a free trial account is created.
{% endstep %}

{% step %}
Sign in to your account and upgrade it to go live by clicking the **Upgrade** link.

Once the account is upgraded, your Twilio account SID and authentication token are generated automatically.
{% endstep %}

{% step %}
Obtain a Twilio phone number by following the instructions provided in these articles:

* [How to Search for and Buy a Twilio Phone Number from Console](https://support.twilio.com/hc/en-us/articles/223135247-How-to-Search-for-and-Buy-a-Twilio-Phone-Number-from-Console)
* [Twilio Phone Number Types and Their Capabilities](https://support.twilio.com/hc/en-us/articles/223135367-Twilio-Phone-Number-Types-and-Their-Capabilities)
  {% endstep %}

{% step %}
Create a TwiML App by following these steps:

* Go to the [TwiML Apps page](https://console.twilio.com/?frameUrl=/console/voice/twiml/apps). This page is available after signing in to your Twilio account.
* Click **Create new TwiML App**.
* Fill out the TwiML App form:
  * In the **Friendly Name** field, specify a name for your app.

**Voice Configuration**

* In the **Request URL** field, specify a URL for your voice app webhook, such as:

  `api.company.name.com/api/v1/voice/twilio-webhook`
* In the **Request Method** dropdown, select **HTTP POST**.

**Messaging Configuration**

* In the **Request URL** field, specify a URL for your messaging app webhook, which is a URL of your B2CORE Back Office.
* In the **Request Method** dropdown, select **HTTP POST**.
  {% endstep %}

{% step %}
Click **Create** to create the app.
{% endstep %}
{% endstepper %}

Once the app is created, your TwiML App SID is generated automatically.

Use the obtained Twilio account SID, authentication token, phone number and TwiML App SID to configure a connection to Twilio via the B2CORE Back Office.

## How to configure Twilio as a 2FA SMS provider

You can configure Twilio to deliver 2FA codes to your clients via SMS.

Before configuring Twilio as a 2FA SMS provider, make sure that you have obtained the following required information:

* Twilio account SID
* Twilio authentication token
* Twilio phone number

To learn how to obtain the required information, refer to [How to sign up with Twilio](#how-to-sign-up-with-twilio).

To configure Twilio as a 2FA SMS provider:

{% stepper %}
{% step %}
Navigate to **System** > **SMS Providers**. and then click **+Create** in the upper-right corner of the page.
{% endstep %}

{% step %}
Click **+Create** in the upper-right page corner.
{% endstep %}

{% step %}
In the displayed popup, fill in the following fields:

* In the **Name** field, enter a name that you want to use for the configuration (such as `twilio_sms`).
* In the **Caption** field, enter a caption that will be applied to the configuration in the Back Office (such as `Twilio SMS`).
* In the **Provider** dropdown, select **Twilio**.
  {% endstep %}

{% step %}
Click **Save** to save the configuration.
{% endstep %}

{% step %}
On the **Edit provider** page, specify the following connection settings:

* In the **API sid** field, specify your Twilio account SID.
* In the **API secret** field, specify your Twilio authentication token.
* In the **Sender phone number** field, specify your Twilio phone number.
  {% endstep %}

{% step %}
Make sure that the **Enabled** field is set to **Yes**.
{% endstep %}

{% step %}
Click **Save**.
{% endstep %}
{% endstepper %}

Twilio can now be used to deliver 2FA codes via SMS. To learn more, refer to [How to set up 2FA with SMS](https://docs.b2core.b2broker.com/manage-system-settings/how-to-set-up-2fa#how-to-set-up-2fa-with-sms).

## How to configure Twilio as a phone service provider

Twilio can be configured to make phone calls to your clients via the Back Office.

Before configuring Twilio as a phone service provider, make sure that you have obtained the following required information:

* Twilio account SID
* Twilio authentication token
* Twilio phone number
* TwiML App SID

To learn how to obtain the required information, refer to [How to sign up with Twilio](#how-to-sign-up-with-twilio).

To configure Twilio to make phone calls:

{% stepper %}
{% step %}
Navigate to **System** > **External Connections**.
{% endstep %}

{% step %}
Click **+Create** in the upper-right page corner.
{% endstep %}

{% step %}
On the **Create connection** page, fill in the following fields:

* In the **Name** field, enter a name that you want to use for the connection.
* In the **Caption** field, enter a caption that will be applied to the connection in the Back Office.
* In the **Provider** dropdown, select **TwilioVoice**.
  {% endstep %}

{% step %}
Click **Save** to save the connection.

The **Twilio** connection will appear in the list of external connections.
{% endstep %}

{% step %}
Click the **Edit** button to open the connection details.
{% endstep %}

{% step %}
On the **Edit connection** page, fill in the following settings:

* In the **Account SID** field, specify your Twilio account SID.
* In the **Auth token** field, specify your Twilio authentication token.
* In the **TwiML App SID** field, specify your TwiML App SID.
  {% endstep %}

{% step %}
Check the connection status.

If the connection is inactive (**No** is displayed in the **Enabled** dropdown), set the **Enabled** dropdown to **Yes**.
{% endstep %}

{% step %}
Click **Save** to apply the changes.
{% endstep %}
{% endstepper %}

Twilio can now be used to make phone calls to your clients via the Back Office.

## How to test the Twilio phone service operation

After you have configured a connection to Twilio for making phone calls via the Back Office, you can make a call to one of your clients to test the connection.

To make a call:

{% stepper %}
{% step %}
Navigate to **Clients** > **General**.
{% endstep %}

{% step %}
Select the client and click the **Edit** button.
{% endstep %}

{% step %}
Go to the **Contacts** tab.
{% endstep %}

{% step %}
Click the phone button ![phone-button](https://514898401-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGoRxAprhHu1goANW7FXt%2Fuploads%2Fgit-blob-07d1962d1195ccbb22e2b7eb32c46bb6b83be9df%2Fphone-button.png?alt=media) displayed in the **Phones** section to dial a specified client's phone number using Twilio.
{% endstep %}

{% step %}
If you have several active Twilio numbers, you can select the number you want to use for calling in the displayed popup.
{% endstep %}
{% endstepper %}

If no error message is displayed in the Back Office, the Twilio connection is configured properly.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.b2core.b2broker.com/how-to-articles/manage-communication-platforms/how-to-configure-twilio.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
