# Twilio WhatsApp Integration

By integrating Twilio WhatsApp API, the platform allows your bot to respond to WhatsApp messages directly, and automate customer care, sales, support, and other business functions.

## Prerequisites

For the Twilio WhatsApp API Provider, we will need

* An Account SID&#x20;
* Auth Token
* A WhatsApp-enabled Number

When a user sends a message to your WhatsApp Enabled Number, your BotDistrikt bot will reply to them

### Create a Twilio Account

You can set up a new Twilio Account [here](https://www.twilio.com/try-twilio). After logging in for the first time and setting up your details, you will be taken to the Dashboard page.&#x20;

You will get your Account SID and the Auth Token from this page

{% hint style="success" %}
New accounts come with $15 worth of credits, which you can use to purchase a phone number
{% endhint %}

<figure><img src="https://2535542804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LirAdLo22OkAW9w3tvY%2Fuploads%2FijoH5lIbsD49mxezWtA3%2F1%20-%20Twilio.png?alt=media&#x26;token=ec7242a4-3376-43e7-aba5-5671e18d12cc" alt=""><figcaption><p>Twilio Console </p></figcaption></figure>

### Enable the WhatsApp Sandbox

Click on the **Messaging** tab and click on **Overview > Try WhatsApp**

<figure><img src="https://2535542804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LirAdLo22OkAW9w3tvY%2Fuploads%2FMxiip3WQiXAqO1peetk6%2F2%20-%20Twilio.png?alt=media&#x26;token=ca5b5eca-8201-4793-bd60-3d56e8cc5ee4" alt=""><figcaption><p>Twilio WhatsApp Sandbox</p></figcaption></figure>

Follow the instructions on this page

When your device is connected to the Sandbox, you will receive this message

<figure><img src="https://2535542804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LirAdLo22OkAW9w3tvY%2Fuploads%2FHqVblxBmaZGiIGYoBASY%2F5%20-%20Twilio.png?alt=media&#x26;token=a84de110-c333-455d-8cfb-3fe4c86cf660" alt="" width="375"><figcaption></figcaption></figure>

After you have successfully completed the above steps, return to the **Twilio  Messaging  > Try WhatsApp**. You will see this step.

<figure><img src="https://2535542804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LirAdLo22OkAW9w3tvY%2Fuploads%2FY4vNXazeOY3kmm3v2bmY%2F6%20-%20Twilio.png?alt=media&#x26;token=b8b42fe6-ab89-413d-a175-0764c75de090" alt=""><figcaption></figcaption></figure>

You are now ready to setup the Twilio WhatsApp API Provider on your BotDistrikt WhatsApp channel

## Setup

<figure><img src="https://2535542804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LirAdLo22OkAW9w3tvY%2Fuploads%2F7XDmNfJkr0K5RgrVF3Db%2F7%20-%20Twilio.png?alt=media&#x26;token=93022468-00b1-4562-981d-b13bb72f579a" alt=""><figcaption><p>BotDistrikt WhatsApp Integration</p></figcaption></figure>

We have our Account SID and Auth Token ready. We need to get the WhatsApp Enabled Number ready now.

On Twilio, click **Sandbox Settings** to get your WhatsApp Enabled Number.

<figure><img src="https://2535542804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LirAdLo22OkAW9w3tvY%2Fuploads%2FGVkXNYhl0TGNLrA3vR8L%2F8%20-%20Twilio.png?alt=media&#x26;token=03a54c3f-474f-4b71-8773-786d75e09380" alt=""><figcaption></figcaption></figure>

On BotDistrikt, fill in all 3 fields:

* An Account SID&#x20;
* Auth Token
* A WhatsApp Enabled Number

{% hint style="info" %}
For the WhatsApp Enabled number, make sure to remove the white spaces and add a **whatsapp:** prefix.&#x20;

For example, if the number you copy from Twilio is `+1 415 523 8886`, The number you will need to key into BotDistrikt is `whatsapp:+14155238886`&#x20;
{% endhint %}

<figure><img src="https://2535542804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LirAdLo22OkAW9w3tvY%2Fuploads%2FWhJdZBbmgU03bgMb4a8Z%2F9%20-%20Twilio.png?alt=media&#x26;token=8e953eda-c789-4d58-9988-d6b9200f828b" alt=""><figcaption></figcaption></figure>

Click **Link to WhatsApp**

When it is linked, take note of the **When A Message Comes In** and **Status Callback** endpoint URLs

<figure><img src="https://2535542804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LirAdLo22OkAW9w3tvY%2Fuploads%2FuFlVKqTzZex94sxa8Ate%2F10%20-%20Twilio.png?alt=media&#x26;token=42fc5ca9-633f-4370-95c6-7ef50bf11599" alt=""><figcaption></figcaption></figure>

Go Back to **Twilio**&#x20;

Click **Settings > WhatsApp Sandbox Settings** and paste the respective endpoint URLs there

<figure><img src="https://2535542804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LirAdLo22OkAW9w3tvY%2Fuploads%2Fhsm2e2zobSfmyI0h6vsX%2F11%20-%20Twilio.png?alt=media&#x26;token=3d371995-6789-49f0-8439-903b7ed0be3c" alt=""><figcaption></figcaption></figure>

Click **Save** on Twilio

Your BotDistrikt bot is now connected to WhatsApp through Twilio!

<figure><img src="https://2535542804-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LirAdLo22OkAW9w3tvY%2Fuploads%2FRYNRqfcN7RXc4GBZsxQH%2F12%20-%20Twilio.png?alt=media&#x26;token=8755840f-0c7a-40d5-825c-5c356ffd76b5" alt="" width="375"><figcaption><p>Whatsapp Chatbot Connected</p></figcaption></figure>
