Send an Audio Message
In this code snippet you learn how to send an Audio message through Facebook Messenger using the Messages API.
For a step-by-step guide to this topic, you can read our tutorial Sending Facebook Messenger messages with the Messages API.
Example
Find the description for all variables used in each code snippet below:
| Key | Description |
|---|---|
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 |
MESSAGES_API_URL | There are two versions of the API, each with their own endpoints. For production the previous Messages API endpoint was |
FB_SENDER_ID | Your Page ID. The |
VONAGE_FB_SENDER_ID | Refer to |
FROM_ID | Refer to |
FB_RECIPIENT_ID | The PSID of the user you want to reply to. The |
TO_ID | Refer to |
AUDIO_URL | The link to the audio file to send. Must be MP3 format for Messenger. |
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Run your code
Save this file to your machine and run it:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Create a file named send-audio.js and add the following code:
Run your code
Save this file to your machine and run it:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Add the following to build.gradle:
Create a file named SendMessengerAudio and add the following code to the main method:
Run your code
We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.kt.messages.messenger with the package containing SendMessengerAudio:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Add the following to build.gradle:
Create a file named SendMessengerAudio and add the following code to the main method:
Run your code
We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.messages.messenger with the package containing SendMessengerAudio:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Create a file named send-audio.php and add the following code:
Run your code
Save this file to your machine and run it:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Run your code
Save this file to your machine and run it:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Create a file named send-audio.rb and add the following code:
Run your code
Save this file to your machine and run it:
Try it out
When you run the code an audio message is sent to the Messenger recipient.