Enviar un mensaje de reacción

En este fragmento de código aprenderá a enviar un mensaje de reacción de WhatsApp utilizando Messages API. Los mensajes de WhatsApp reaction te permite reaccionar, mediante un emoji, a un mensaje entrante que hayas recibido.

Así como el to y from Numbers, este tipo de mensaje requiere dos datos clave:

  • En message_uuid del mensaje al que se desea reaccionar. Estará presente en el cuerpo del mensaje entrante recibido.
  • En emoji utilizado como reacción. Puede ser el propio carácter emoji, por ejemplo 😀.

IMPORTANTE: Si un cliente no le ha enviado un mensaje antes, la primera vez que envíe un mensaje a un usuario, WhatsApp exigirá que el mensaje contenga una plantilla. Esto se explica con más detalle en la Entender el tema de WhatsApp.

Ejemplo

A continuación encontrará la descripción de todas las variables utilizadas en cada fragmento de código:

ClaveDescripción
JWT

Used to authenticate your request. See Authentication for more information, including how to generate a JWT.

VONAGE_APPLICATION_ID

The Vonage Application ID.

VONAGE_PRIVATE_KEY_PATH

Private key path.

MESSAGES_API_URL

There are two versions of the API, each with their own endpoints. For production the previous Messages API endpoint was https://api.nexmo.com/v0.1/messages, the new one is https://api.nexmo.com/v1/messages. For sandbox testing the Messages API endpoint is https://messages-sandbox.nexmo.com/v0.1/messages or https://messages-sandbox.nexmo.com/v1/messages, depending on which version you have set in the sandbox dashboard.

WHATSAPP_NUMBER

The WhatsApp number that has been allocated to you by Vonage. For sandbox testing the number is 14157386102.

TO_NUMBER

Replace with the number you are sending to. E.g. 447700900001

MESSAGE_UUID

The UUID of the specific message.

EMOJI

The emoji to send in the message.

NOTA: No utilice un + o 00 cuando introduzca un número de teléfono, empiece por el prefijo del país, por ejemplo, 447700900000.

Requisitos previos

Si no tiene una solicitud, puede crear uno. Asegúrese también de configure sus webhooks.

Escriba el código

Añada lo siguiente a send-reaction.sh:

Ver fuente completa

Ejecute su código

Guarde este archivo en su máquina y ejecútelo:

bash send-reaction.sh

Pruébalo

Al ejecutar el código, se envía un mensaje de reacción de WhatsApp al número de destino.