# Custom Bot integration with vCX

[![image.png](https://docs.versalence.online/uploads/images/gallery/2024-12/scaled-1680-/RuBiECduGUo3hWCA-FlYimage.png)](https://docs.versalence.online/uploads/images/gallery/2024-12/RuBiECduGUo3hWCA-FlYimage.png)

Follow the steps to set up WhatsApp API using the manual method or embedded signup

<p class="callout info">A webhook to receive incoming messages</p>

<span style="background-color: rgb(191, 237, 210);">Incoming Message format</span>

Below is the format of incoming messages payload as received from META webhook and will be forwarded to your Bot webhook

```json
{
  "object": "whatsapp_business_account",
  "entry": [
    {
      "id": "xxxxxxxxxx",
      "changes": [
        {
          "value": {
            "messaging_product": "whatsapp",
            "metadata": {
              "display_phone_number": "xxxxxxxxxx",
              "phone_number_id": "xxxxxxxxxx"
            },
            "contacts": [
              {
                "profile": {
                  "name": "Sanjeev Reddy"
                },
                "wa_id": "xxxxxxxxxx"
              }
            ],
            "messages": [
              {
                "from": "xxxxxxxxxx",
                "id": "wamid.HBgMOTE5NzQxMzkxNzAwFQIAEhgUM0Y2OTU4Qzc0OEYyMkMzQ0NCOEIA",
                "timestamp": "1733564481",
                "text": {
                  "body": "hi"
                },
                "type": "text"
              }
            ]
          },
          "field": "messages"
        }
      ]
    }
  ]
}
```

<span style="background-color: rgb(191, 237, 210);">Outgoing Messages to the user</span>

format to send data to META using vCX

```bash
curl --location -X POST 'https://api.versal.one/<client-id>' \
--header 'Authorization: Bearer <client-token>' \
--header 'Content-Type: application/json' \
--data '{
    "purpose": "sendmessage",
    "message_data": {
        "messaging_product": "whatsapp",
        "recipient_type": "individual",
        "to": <recepient>,
        "type": "text",
        "text": {
            "body": <Message or response from Bot>
        }
    }
}'
```

<span style="background-color: rgb(191, 237, 210);">Outgoing messages to vCX</span>

format to send data to vCX as a bot response

```bash
curl --location -X POST 'https://webhook.versal.one/<client-id>' \
--header 'Authorization: Bearer <client-token>' \
--header 'Content-Type: application/json' \
--header 'User-Agent': 'Bot' \
--data '{
  "responsefrom": "Bot",
  "conversation": {
    "id": "0470d58f-ad45-4d16-b229-76476e598fed",
    "type": "text",
    "channel": "channel",
    "direction": "outgoing",
    "payload": {
      "type": "text",
      "text": "Hello! I am Bot, your virtual assistant",
      "markdown": true
    },
    "preview": "Hello! I am Bot, your virtual assistant",
    "incomingEventId": "48621030-b469-420e-b827-9b9b293ba312"
  },
  "phonenumber": "xxxxxxxxxx"
}'

```