Enviar un mensaje de vídeo

En este fragmento de código aprenderás a enviar un mensaje de vídeo a través de Facebook Messenger utilizando la Messages API.

Para obtener una guía paso a paso sobre este tema, puede leer nuestro tutorial Envío de mensajes de Facebook Messenger con Messages API.

Ejemplo

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

ClaveDescripción
VONAGE_APPLICATION_ID

The Vonage Application ID.

VONAGE_APPLICATION_PRIVATE_KEY_PATH

Private key path.

VONAGE_PRIVATE_KEY_PATH

Private key path.

BASE_URL

For production use the base URL is https://api.nexmo.com/. For sandbox testing the base URL is https://messages-sandbox.nexmo.com/.

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.

FB_SENDER_ID

Your Page ID. The FB_SENDER_ID is the same as the to.id value you received in the inbound messenger event on your Inbound Message Webhook URL. For sandbox testing this is 107083064136738.

VONAGE_FB_SENDER_ID

Refer to FB_SENDER_ID above

FROM_ID

Refer to FB_SENDER_ID above

FB_RECIPIENT_ID

The PSID of the user you want to reply to. The FB_RECIPIENT_ID is the PSID of the Facebook User you are messaging. This value is the from.id value you received in the inbound messenger event on your Inbound Message Webhook URL.

TO_ID

Refer to FB_RECIPIENT_ID above.

VIDEO_URL

The link to the video to send. Messenger supports MP4 (.mp4) file format only.

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-video.sh:

curl -X POST "${MESSAGES_API_URL}" \
  -H "Authorization: Bearer "$JWT\
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -d $'{
    "to": "'${MESSENGER_RECIPIENT_ID}'",
    "from": "'${MESSENGER_SENDER_ID}'",
    "channel": "messenger",
    "message_type": "video",
    "video": {
      "url": "'${MESSAGES_VIDEO_URL}'"
    }
  }'

Ver fuente completa

Ejecute su código

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

bash send-video.sh

Pruébalo

Al ejecutar el código se envía un mensaje de vídeo al destinatario de Messenger.