Send a Message with Failover
If a message sent with the Vonage Messages API is rejected, failover messages can be defined to be sent in its place. Failover can be done from any channel or message type to any other channel or message type, however the following example shows failover from RCS to SMS.
Example
Find the description for all variables used in each code snippet below:
| Key | Description |
|---|---|
VONAGE_APPLICATION_ID | The Vonage Application ID. |
VONAGE_PRIVATE_KEY_PATH | Private key path. |
TO_NUMBER | The number you are sending the to in E.164 format. For example |
RCS_SENDER_ID | The sender ID for the RCS message. |
JWT | Used to authenticate your request. See Authentication for more information, including how to generate a JWT. |
SMS_SENDER_ID | The alphanumeric string that represents the name or number of the organization sending the message. |
MESSAGES_API_URL | There are two versions of the API, each with their own endpoints. For production the previous Messages API endpoint was |
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 class named SendMessageWithFailover and add the following code to the main method:
Write the code
Add the following to the main method of the SendMessageWithFailover class:
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 with the package containing SendMessageWithFailover:
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:
Write the code
Add the following to the main method of the SendMessageWithFailover class:
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 with the package containing SendMessageWithFailover:
Try it out
When you run the code an RCS message is sent to the destination number; if that message is rejected, an SMS message will be sent in its place.