> For the complete documentation index, see [llms.txt](https://docs.3dolphins.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.3dolphins.ai/bot-settings/dialog-flows/untitled-1/defined-entity-bot-response/whatsapp-flows/data-exchange.md).

# Data Exchange

**Data exchange** is used to enable the exchange of data between your system and Meta within the WhatsApp Flow process.

To create a data exchange, navigate to the **Bot Settings** menu and select **Dialog Flows**. You can create the required **Intention** and **Entity** as described on the previous page. Then, at the **Prompt Response** stage, select **'WhatsApp Flows'** and complete the **Attach WhatsApp Flows** form as shown in the image below.

{% hint style="info" %}
The **Flow Action** field must be set to data\_exchange.
{% endhint %}

<figure><img src="https://765826444-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYDAnLjpg2T8z2BplJOS%2Fuploads%2Ffx9TDlRxhqm7nyZLnTi0%2Fwhatsapp%20flow%20add%20dialog%20censored.png?alt=media&amp;token=e33bd876-92b3-4b26-aec3-c98499da6dbc" alt=""><figcaption><p>Attach Whatsapp Flows</p></figcaption></figure>

**Component Explanation:**

<table><thead><tr><th width="317.16668701171875">Component</th><th>Description</th></tr></thead><tbody><tr><td>Title</td><td>The main title that appears in the WhatsApp message when the flow is sent to the customer.</td></tr><tr><td>Body</td><td>The main content of the message that explains the purpose of the flow and provides guidance to the customer.</td></tr><tr><td>Flows ID</td><td>The ID from <strong>Meta Business Suite</strong> used to connect a previously created WhatsApp Flow.</td></tr><tr><td>Flows CTA</td><td>This is text that will displayed on the form button to customers.</td></tr><tr><td>Flows Action</td><td><p>A field to define the action for data exchange that will be sent to Meta.<br></p><p><strong>Note:</strong></p><ul><li><strong>data_exchange</strong> = Indicates the data from flows will be sent to Meta for each step form.</li><li><strong>navigate</strong> = No data exchange occurs because the page has been predefined from the beginning, as defined in the flow screen ID.</li></ul></td></tr><tr><td>Flows Screen ID </td><td><p>An Screen ID that directs customers straight to the Flows step after clicking the CTA button.</p><p></p><p><strong>Note:</strong><br>Required if using <strong>navigate</strong> within Flows Action.</p></td></tr><tr><td>Fallback Message</td><td>This is the message that will be sent to the customer if the WhatsApp Flow cannot be executed.</td></tr></tbody></table>

In the process flow, you are required to add an **MVEL node** named handler, which functions to handle data requests from WhatsApp when a user clicks the flow, as shown in the image below.

<figure><img src="https://765826444-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYDAnLjpg2T8z2BplJOS%2Fuploads%2Fx8HI63igRHRsIJDfzAJj%2Fwhatsapp%20flow%20handler%20censored.png?alt=media&amp;token=2e92c087-185a-4ad9-9afe-e927f49e20e9" alt=""><figcaption><p>Handler Process Flow</p></figcaption></figure>

It is also necessary to add **flowData** for each data element requested by Meta. This **flowData** contains information sent from the flow, including the **last accessed page**, the **currently active page**, the **flow name**, the **flow ID**, and the **flow completion status** (whether the flow has been completed or not).

<figure><img src="https://765826444-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYDAnLjpg2T8z2BplJOS%2Fuploads%2F5eASHcDCt0LG0yGUv2AV%2Fwhastapp%20flow%20censored.jpg?alt=media&amp;token=266a7664-7788-42d3-8ac0-918b1f86799a" alt=""><figcaption><p>flowData</p></figcaption></figure>

Each final node that will be sent to WhatsApp must include the following script:

```javascript
//Membuat dataObject yang di perlukan
JSONObject flowData = new JSONObject();
flowData.put("last_page", "4");
flowData.put("current_page", "1");
flowData.put("flow_id", "xxxxxxxxx");
flowData.put("flow_name", "Example flow name");
flowData.put("completed", "false");

// Mengubah dataObject ke string dan menambahkan escape karakter 4 kali
String flowDataString = flowData.toString().replace("\"", "\\\\\"");

// Menyusun finalData dengan escape karakter
String finalData = "{" +
    "\\\\\"flow_data\\\\\":" + flowDataString + "," +
    "\\\\\"version\\\\\":\\\\\"" + v + "\\\\\"," +
    "\\\\\"screen\\\\\":\\\\\"" + sc + "\\\\\"," +
    "\\\\\"data\\\\\":" + dataString +
    "}";
```

The final step is configuring the **endpoint** in the **Business WhatsApp Flow** to enable data exchange with the flow.

{% hint style="info" %}
The endpoint consists of **{EndPointChannel}/{ChannelId}/flow/{urlWebhook}**.
{% endhint %}

<figure><img src="https://765826444-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYDAnLjpg2T8z2BplJOS%2Fuploads%2FtF1l2yxKCqzXjC4azovB%2Fimage.png?alt=media&amp;token=a92e2dcb-5208-42b5-b7a0-00b8d5afcf9a" alt=""><figcaption><p>Configuration of Endpoints in Business WhatsApp Flow</p></figcaption></figure>

The endpoint configuration in the process flow can be seen in the image below.

<figure><img src="https://765826444-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYDAnLjpg2T8z2BplJOS%2Fuploads%2F4vWEN2LwiuinoIzuvx01%2Fimage.png?alt=media&amp;token=ba6fc048-30e0-4b30-a124-3fb3e9d16050" alt=""><figcaption><p>Endpoint</p></figcaption></figure>
