diff --git a/SNIPPETS.md b/SNIPPETS.md index 8b405b3..9b5393b 100644 --- a/SNIPPETS.md +++ b/SNIPPETS.md @@ -954,6 +954,22 @@ var response = client.getMessagesClient().sendMessage( ); System.out.println("Message sent successfully. ID: "+response.getMessageUuid()); ``` +### Send Message With Failover + +```java +var response = client.getMessagesClient().sendMessage( + RcsTextRequest.builder() + .from(RCS_SENDER_ID).to(MESSAGES_TO_NUMBER) + .text("This is an RCS message sent via the Vonage Messages API") + .failover(SmsTextRequest.builder() + .from(SMS_SENDER_ID).to(MESSAGES_TO_NUMBER) + .text("This is an SMS sent using the Vonage Messages API.") + .build() + ) + .build() +); +System.out.println(response); +``` ### Messenger #### Send Messenger Text diff --git a/src/main/java/com/vonage/quickstart/messages/SendMessageWithFailover.java b/src/main/java/com/vonage/quickstart/messages/SendMessageWithFailover.java new file mode 100644 index 0000000..8cf00db --- /dev/null +++ b/src/main/java/com/vonage/quickstart/messages/SendMessageWithFailover.java @@ -0,0 +1,49 @@ +/* + * Copyright 2025 Vonage + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.vonage.quickstart.messages; + +import com.vonage.client.VonageClient; +import com.vonage.client.messages.rcs.RcsTextRequest; +import com.vonage.client.messages.sms.SmsTextRequest; +import static com.vonage.quickstart.EnvironmentVariables.*; + +public class SendMessageWithFailover { + public static void main(String[] args) throws Exception { + VonageClient client = VonageClient.builder() + .applicationId(VONAGE_APPLICATION_ID) + .privateKeyPath(VONAGE_PRIVATE_KEY_PATH) + .build(); + + var response = client.getMessagesClient().sendMessage( + RcsTextRequest.builder() + .from(RCS_SENDER_ID).to(MESSAGES_TO_NUMBER) + .text("This is an RCS message sent via the Vonage Messages API") + .failover(SmsTextRequest.builder() + .from(SMS_SENDER_ID).to(MESSAGES_TO_NUMBER) + .text("This is an SMS sent using the Vonage Messages API.") + .build() + ) + .build() + ); + System.out.println(response); + } +}