Skip to main content

Custom Bot integration with vCX

image.pngimage.png

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

A webhook to receive incoming messages

Incoming Message format

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

{
  "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"
        }
      ]
    }
  ]
}

Outgoing Messages to the user

format to send data to META using vCX

curl --location '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>
        }
    }
}'

Outgoing messages to vCX

format to send data to vCX as a bot response

to be sent to http://webhook.versal.one/<client-id>

{
  "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"
}