Webhook
Webhooks are user-defined HTTP callbacks that are triggered by specific events. Whenever a triggering event occurs, the WhatsApp Business API client sees the event, collects the data, and immediately sends a notification (HTTP request) to the WhatsApp URL specified in the application settings, updating the status of sent messages or indicating when you receive a message.It is important that your Webhook returns an HTTPS 200 OK response to notifications. Otherwise, the WhatsApp Business API client will consider that notification a failure and will retry after a delay.
Webhook Configuration
To receive notifications, the customer needs to register the Webhook URL on the number. Set/update the Webhook URL:webhook field is optional (it can be null to remove it) and has a maximum of 255 characters. If the Webhook URL is not set, notifications will not be delivered.
In addition to the main Webhook, you can configure a secondary webhook (
secondary_webhook). When set, it receives the same notifications as the main Webhook."Beep Beep!") to the configured URL:
It is important that your Webhook returns an HTTP 200 OK response to notifications. Otherwise, the notification will be considered a failure and there will be retry attempts.
Set notification settings
Positus numbers use the WhatsApp Cloud API. On the registered Webhook URL, the customer receives a normalized subset of Meta’s payload (without theentry/changes envelope). The delivered objects are the raw Cloud API objects.
| Name | object content |
|---|---|
| messages | Incoming message notifications |
| statuses | Message status updates |
| errors | Serious out-of-band errors |
Whenever possible, names will be kept constant across functions. (For example, all date and time stamps are named
timestamp.Notification Webhook format
An incoming message notification has the top-level{ "contacts": [...], "messages": [...] }. A status notification has the top-level { "statuses": [...], "contacts": [...] } (contacts is only present when the status is not failed).
Example (incoming text message)
Message status updates
In addition to incoming messages, the customer receives status notifications for the messages they sent. These notifications have the top-level{ "statuses": [...], "contacts": [...] }.
Example (delivered status)
status field can take the following values:
| Value | Description |
|---|---|
sent | The message was sent to the WhatsApp server. |
delivered | The message was delivered to the recipient’s device. |
read | The message was read by the recipient. |
failed | The message failed to send. |
status is failed, the status object includes an errors array with the failure details and contacts is not sent.
Example (failed status)
Notification errors
When out-of-band errors occur during the normal operation of the application, theerrors array will provide a description of the error. This type of error can be caused by temporary network connectivity errors, invalid credentials, management controllers with an unavailable status, and so on. If you receive an error, refer to Error and status messages for more information.
Example
The
errors object contains the following parameters:
| Field name | Description | Type |
|---|---|---|
| code | Error code | Numeric |
| title | Error title | String |
| details | Optional. Error details provided, if available/applicable | String |
| href | Optional. Details of the error location. | String |
Incoming message notifications
You receive a notification when your business receives a message. Themessages object section presents all the information that can be received about an incoming message.
Example: Incoming Text message
Example: Incoming static location message
Example: Incoming message with contacts
Incoming media message notifications
When a message with media is received, the notification sent to your Webhook contains a media object with the fields that identify the file. In the Cloud API, the media object only carriesid, mime_type, and sha256 (plus an optional caption for image, document, and video). There are no file or link fields.
To download the media, use the id in the download endpoint: GET https://api.positus.global/v2/whatsapp/numbers/{chave}/media/{id}.
Example: Incoming message with image
Example: Incoming message with document
Example: Incoming message with audio
In the Cloud API, audio messages (including voice messages) are delivered with the type
audio, not voice.Example: Incoming message with video
Example: Incoming message with sticker
Incoming replies to sent messages
Users can reply to a specific message on WhatsApp. So that the business understands the context of the reply to a message, we include thecontext object. This context object provides the id of the message the customer replied to and the WhatsApp ID of the sender of the original message.
Example: Customer replied to your message
Official WhatsApp Cloud API documentation
Positus uses the WhatsApp Cloud API and delivers the objects in the same format as Meta’s official standard. The complete and up-to-date documentation can be found at the link below:https://developers.facebook.com/docs/whatsapp/cloud-api/webhooks/components