Mark an Inbound Message as Read
In this code snippet you learn how to mark an inbound WhatsApp message as read. Marking a message as read will mean that blue check-marks will show against that message in the WhatsApp UI instead of grey check-marks.
Marking an inbound message as read is done by sending a PATCH request to the message object stored on Vonage's servers, identifying the specific message by its UUID. Since message objects are geo-located, a geo-specific URL must be used for the request; this will be present in the body of the inbound message to be marked as read.
IMPORTANT: If a customer has not messaged you first, then the first time you send a message to a user, WhatsApp requires that the message contains a template. This is explained in more detail in the Understanding WhatsApp topic.
Example
Find the description for all variables used in each code snippet below:
| Key | Description |
|---|---|
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. |
NOTE: Don't use a leading + or 00 when entering a phone number, start with the country code, for example, 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.
Add the following to build.gradle:
Create a file named MarkAsRead 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.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:
Create a file named MarkAsRead 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.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.
Prerequisites
If you do not have an application you can create one. Make sure you also configure your webhooks.
Create a file named send-file.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 mark-as-read.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 a request is made to mark the specified inbound message as read.