受信メッセージを既読にする
このコードスニペットでは、WhatsApp 受信メッセージを read.メッセージを read をクリックすると、WhatsApp UIでそのメッセージに青いチェックマークが表示されます。
受信メッセージを既読にするには PATCH リクエストは、Vonage のサーバーに保存されているメッセージ・オブジェクトへのもので、UUID によって特定のメッセージを識別します。メッセージ・オブジェクトは地理的に配置されているので、リクエストには地理的な URL を使用する必要があります。 read.
重要: メッセージ未送信の場合、WhatsAppは初回メッセージ送信時にテンプレートを要求します。詳しくは WhatsAppトピックの理解.
例
各コード・スニペットで使用されているすべての変数の説明を以下に示します:
| キー | 説明 |
|---|---|
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. |
GEOSPECIFIC_MESSAGES_API_URL | The URL for the Geo-specific Messages API endpoint. One of |
GEOSPECIFIC_VONAGE_API_HOST | The hostname for the Geo-specific API endpoint. One of |
MESSAGE_UUID | The UUID of the specific message. |
注: 先頭の + または 00 電話番号を入力する場合は、447700900000のように国番号から入力してください。
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Write the code
Add the following to mark-as-read.sh:
curl -X PATCH "${GEOSPECIFIC_MESSAGES_API_URL}/${MESSAGES_MESSAGE_ID}" \
-H "Authorization: Bearer "$JWT\
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d $'{
"status": "read",
}'
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:
implementation 'com.vonage:server-sdk-kotlin:2.1.1'Create a class named MarkAsRead and add the following code to the main method:
val client = Vonage {
applicationId(VONAGE_APPLICATION_ID)
privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
}Write the code
Add the following to the main method of the MarkAsRead class:
client.messages.existingMessage(MESSAGES_MESSAGE_ID, MESSAGES_GEOSPECIFIC_API_HOST).markAsRead()Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Run the following gradle command to execute your application, replacing com.vonage.quickstart.kt.messages.whatsapp with the package containing MarkAsRead:
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:
implementation 'com.vonage:server-sdk:9.3.1'Create a class named MarkAsRead and add the following code to the main method:
VonageClient client = VonageClient.builder()
.applicationId(VONAGE_APPLICATION_ID)
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
.build();Write the code
Add the following to the main method of the MarkAsRead class:
client.getMessagesClient().ackInboundMessage(MESSAGES_MESSAGE_ID, ApiRegion.API_EU);Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Run the following gradle command to execute your application, replacing com.vonage.quickstart.messages.whatsapp with the package containing MarkAsRead:
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Install-Package VonageWrite the code
Add the following to MarkAsRead.cs:
var credentials = Credentials.FromAppIdAndPrivateKeyPath(VONAGE_APPLICATION_ID, VONAGE_PRIVATE_KEY_PATH);
var vonageClient = new VonageClient(credentials);
await vonageClient.MessagesClient.UpdateAsync(WhatsAppUpdateMessageRequest.Build(MESSAGES_MESSAGE_ID));Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
composer require vonage/clientCreate a file named send-file.php and add the following code:
$keypair = new \Vonage\Client\Credentials\Keypair(
file_get_contents(VONAGE_APPLICATION_PRIVATE_KEY_PATH),
VONAGE_APPLICATION_ID
);
$client = new \Vonage\Client($keypair);Write the code
Add the following to send-file.php:
$fileObject = new \Vonage\Messages\MessageObjects\FileObject(
'https://example.com/file.pdf',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.
pip install vonage python-dotenvWrite the code
Add the following to mark-as-read.py:
client.messages.mark_whatsapp_message_read("MESSAGES_MESSAGE_ID")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.
gem install vonageCreate a file named mark-as-read.rb and add the following code:
Run your code
Save this file to your machine and run it:
試してみる
コードを実行すると、指定された受信メッセージを既読にするリクエストが行われる。