Saltar al contenido principal

Webhooks

Webhooks are an efficient way to get real-time information and updates on message status changes. With webhooks, an HTTP POST request will be sent to the webhook URL you provided whenever a relevant event occurs.

Configuration From Panel

  1. Go to the reference panel and look for the New WebHook box.

  2. Enter the URL you want to send messages to.

  3. Add any headers you need to be sent to, for example, authenticate and identify the incoming message.

  4. Click on Save Settings and agree.

You can view and remove configured URLs from the WebHooks list.

Configuration From API

To add and update a webhook configuration from the API, make the following request:

curl --location --request POST 'https://apirest.whatsuy.com/references/hookconf'
--header 'Authorization: Bearer <token>'
--header 'Content-Type: application/json'
--data-raw '{
"id": "11111111",
"webhook": "https://ocex2.whatsuy.com/admin/index.php?route=whatsapp/common/webhook",
"headers": [
{
"key": "auth",
"value": "973827394"
},
{
"key": "reference",
"value": "11111111"
}
]
}'

The response will be as follows if the configuration is updated successfully:

{
"success": true,
"message": "Settings updated successfully",
"data": {}
}

Received Message Format

When the WhatsApp account receives or sends a message, a request will be made to the webhook URL with the configured headers and a body with a specific format depending on the type of message.

If an attachment (image, video, document or audio) is required to be downloaded, you can download it from the URL https://apirest.whatsuy.com/{fileUrl}.

The different types of messages can be: Text, Image, Video, Document or Audio. Each one will have a specific format with information relevant to that type of content.

Text

It's a simple text message. It includes details such as the reference, the sender, the status and the text of the message.

{
"ref": 11111111,
"remoteJid": "59891111111::single",
"mine": false,
"id": "BAE57F357C73558A",
"pushName": "WhatsUY Test Contact",
"verifiedBizName": "WhatsUYTest",
"messageTimestamp": 1663172439,
"type": "text",
"text": "Test Message",
"status": "PENDING"
}

Image

It is an image type message. It includes information about the image, such as its mimetype, size, dimensions, and a thumbnail.

{
"ref": 11111111,
"remoteJid": "59891111111::single",
"mine": false,
"id": "BAE57F357C73558A",
"pushName": "WhatsUY Test Contact",
"verifiedBizName": "WhatsUYTest",
"messageTimestamp": 1663172439,
"type": "image",
"mimetype": "image/jpeg",
"fileLength": 169584,
"height": 1640,
"width": 922,
"jpegThumbnail": "/9j/QABRAD...",
"caption": "Test IMG Message",
"fileUrl": "medias/11111111/F8186F2E",
"status": "PENDING"
}

Video

It is a video type message. It includes the information of the video, such as its mimetype, size, duration, dimensions, and a thumbnail.

{
"ref": 11111111,
"remoteJid": "59891111111::single",
"mine": false,
"id": "BAE57F357C73558A",
"pushName": "WhatsUY Test Contact",
"verifiedBizName": "WhatsUYTest",
"messageTimestamp": 1663172439,
"type": "video",
"mimetype": "video/mp4",
"fileLength": "907068",
"seconds": 3,
"height": 640,
"width": 352,
"jpegThumbnail": "/9j/QABAAD...",
"caption": "Test Video Message",
"fileUrl": "medias/11111111/Fr186F2E",
"status": "PENDING"
}

Document

It is a document type message. It includes the document's information, such as its mimetype, size, title, number of pages, and a thumbnail. In addition, it provides a URL to access the document file.

{
"ref": 11111111,
"remoteJid": "59891111111::single",
"mine": false,
"id": "BAE57F357C73558A",
"pushName": "WhatsUY Test Contact",
"verifiedBizName": "WhatsUYTest",
"messageTimestamp": 1663172439,
"type": "document",
"mimetype": "application/pdf",
"title": "docname.pdf",
"fileLength": "238627",
"pageCount": 3,
"jpegThumbnail": "/9j/QABAAD...",
"fileName": "docname.pdf",
"caption": "Test Message Docs",
"fileUrl": "medias/11111111/Fr186F2E",
"status": "PENDING"
}

Audio

Es un mensaje de tipo audio. Incluye la información del audio, como su mimetype, tamaño y duración. También proporciona una representación de la forma de onda del audio y una URL para acceder al archivo de audio.

{
"reference": 11111111,
"remoteJid": "59891111111::single",
"mine": false,
"id": "BAE57F357C73558A",
"pushName": "WhatsUY Test Contact",
"verifiedBizName": "WhatsUY Test",
"messageTimestamp": 1663172439,
"type": "audio",
"mimetype": "audio/ogg; codecs=opus",
"fileLength": "11971",
"seconds": 5,
"waveform": "AAABDTs6Iw4AAAAADRkYERcUFRgaEgQfEQcDFyUcGB4VGhEBAAAAAw4hKyQXAAAAAAAAAAAAAAAAAQMCBQAAAA==",
"fileUrl": "medias/11111111/Fr186F2E",
"status": "PENDING"
}

En todos estos formatos de mensaje, reference es el identificador de la conversación, remoteJid es el identificador del contacto, mine indica si el mensaje fue enviado por nosotros, pushName y verifiedBizName son nombres asociados al contacto, messageTimestamp es el sello de tiempo del mensaje, type es el tipo de mensaje y status es el estado actual del mensaje.

Formato De Cambio De Estado Recibido

Además de los mensajes, los cambios de estado también se enviarán a la URL de webhook configurada. Los posibles estados son: FAIL, PENDING, SENDING, DELIVERED, READ y PLAYED.

El formato de cambio de estado será similar a este:

{
"reference": 11111111,
"remoteJid": "59891111111::single",
"mine": false,
"id": "BAE57F357C73558A",
"pushName": "WhatsUY Test Contact",
"verifiedBizName": "WhatsUY Test",
"messageTimestamp": 1663172439,
"status": "DELIVERED"
}

De esta manera, puedes realizar un seguimiento del estado de los mensajes y actuar en consecuencia según tus necesidades.

Audio

It is an audio type message. It includes information about the audio, such as its mimetype, size, and duration. It also provides a waveform representation of the audio and a URL to access the audio file.

{
"ref": 11111111,
"remoteJid": "59891111111::single",
"mine": false,
"id": "BAE57F357C73558A",
"pushName": "WhatsUY Test Contact",
"verifiedBizName": "WhatsUYTest",
"messageTimestamp": 1663172439,
"type": "audio",
"mimetype": "audio/ogg; codecs=opus",
"fileLength": "11971",
"seconds": 5,
"waveform": "AAABDTs6Iw4AAAAADRkYERcUFRgaEgQfEQcDFyUcGB4VGhEBAAAAAw4hKyQXAAAAAAAAAAAAAAAAAAQMCBQAAAA==",
"fileUrl": "medias/11111111/Fr186F2E",
"status": "PENDING"
}

In all these message formats, reference is the identifier of the conversation, remoteJid is the identifier of the contact, mine indicates whether the message was sent by us, pushName and verifiedBizName are names associated with the contact , messageTimestamp is the timestamp of the message, type is the type of message, and status is the current status of the message.

Status Change Format Received

In addition to messages, status changes will also be sent to the configured webhook URL. The possible states are: FAIL, PENDING, SENDING, DELIVERED, READ and PLAYED.

The status change format will be similar to this:

{
"ref": 11111111,
"remoteJid": "59891111111::single",
"mine": false,
"id": "BAE57F357C73558A",
"pushName": "WhatsUY Test Contact",
"verifiedBizName": "WhatsUYTest",
"messageTimestamp": 1663172439,
"status": "DELIVERED"
}

In this way, you can keep track of the status of the messages and act accordingly according to your needs.