クイック返信ボタンの送信
このコードでは、WhatsApp でクイック返信ボタンを送信する方法を説明します。Vonageの カスタムオブジェクト 機能をご利用ください。WhatsApp開発者向けドキュメントをご参照ください。 メッセージ形式.
メッセージの受信者がクイック返信ボタンをクリックすると、Vonageは次のようにします。 POST 関連するデータをインバウンドメッセージのウェブフックURLに送信します。
例
各コード・スニペットで使用されているすべての変数の説明を以下に示します:
| キー | 説明 |
|---|---|
VONAGE_APPLICATION_ID | The Vonage Application ID. |
VONAGE_APPLICATION_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 |
WHATSAPP_NUMBER | The WhatsApp number that has been allocated to you by Vonage. For sandbox testing the number is 14157386102. |
VONAGE_WHATSAPP_NUMBER | Refer to |
VONAGE_NUMBER | Refer to |
TO_NUMBER | Replace with the number you are sending to. E.g. |
WHATSAPP_TEMPLATE_NAMESPACE | The namespace ID found in your WhatsApp Business Account. Only templates created in your own namespace will work. Using an template with a namespace outside of your own results in an error code 1022 being returned. |
WHATSAPP_TEMPLATE_NAME | The name of the template created in your WhatsApp Business Account. |
注: 先頭の + または 00 電話番号を入力する場合は、447700900000のように国番号から入力してください。
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-button-quick-reply.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 SendWhatsappQuickReplyButton and add the following code to the main method:
Write the code
Add the following to the main method of the SendWhatsappQuickReplyButton class:
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.whatsapp with the package containing SendWhatsappQuickReplyButton:
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 SendWhatsappQuickReplyButton and add the following code to the main method:
Write the code
Add the following to the main method of the SendWhatsappQuickReplyButton class:
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.whatsapp with the package containing SendWhatsappQuickReplyButton:
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-button-quick-reply.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-button-quick-reply.rb and add the following code:
Run your code
Save this file to your machine and run it:
試してみる
コードを実行すると、WhatsAppリマインダーメッセージが相手先電話番号に送信されます。メッセージには2つのクイック返信ボタンがあり、イベントに行くか行かないかを選択できます。ボタンが押されると以下のようなデータが受信用ウェブフックURLに送信されます:
この例では、受信者は「はい」ボタンをクリックした。