音声メッセージを送信する
このコード・スニペットでは、Messages API を使って Facebook Messenger から音声メッセージを送信する方法を説明します。
このトピックに関するステップバイステップのガイドについては、チュートリアルをお読みください。 Messages APIを使ったFacebook Messengerメッセージの送信.
例
各コード・スニペットで使用されているすべての変数の説明を以下に示します:
| キー | 説明 |
|---|---|
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 class named SendMessengerAudio and add the following code to the main method:
Run your code
We can use the アプリケーション 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 class named SendMessengerAudio and add the following code to the main method:
Run your code
We can use the アプリケーション 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:
試してみる
コードを実行すると、音声メッセージがメッセンジャーの受信者に送信されます。