Skip to content

Commit 0247b8a

Browse files
authored
feat: Add Messages failover example (#122)
1 parent 415be14 commit 0247b8a

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

SNIPPETS.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,22 @@ var response = client.getMessagesClient().sendMessage(
954954
);
955955
System.out.println("Message sent successfully. ID: "+response.getMessageUuid());
956956
```
957+
### Send Message With Failover
958+
959+
```java
960+
var response = client.getMessagesClient().sendMessage(
961+
RcsTextRequest.builder()
962+
.from(RCS_SENDER_ID).to(MESSAGES_TO_NUMBER)
963+
.text("This is an RCS message sent via the Vonage Messages API")
964+
.failover(SmsTextRequest.builder()
965+
.from(SMS_SENDER_ID).to(MESSAGES_TO_NUMBER)
966+
.text("This is an SMS sent using the Vonage Messages API.")
967+
.build()
968+
)
969+
.build()
970+
);
971+
System.out.println(response);
972+
```
957973
### Messenger
958974
#### Send Messenger Text
959975

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2025 Vonage
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*/
22+
package com.vonage.quickstart.messages;
23+
24+
import com.vonage.client.VonageClient;
25+
import com.vonage.client.messages.rcs.RcsTextRequest;
26+
import com.vonage.client.messages.sms.SmsTextRequest;
27+
import static com.vonage.quickstart.EnvironmentVariables.*;
28+
29+
public class SendMessageWithFailover {
30+
public static void main(String[] args) throws Exception {
31+
VonageClient client = VonageClient.builder()
32+
.applicationId(VONAGE_APPLICATION_ID)
33+
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
34+
.build();
35+
36+
var response = client.getMessagesClient().sendMessage(
37+
RcsTextRequest.builder()
38+
.from(RCS_SENDER_ID).to(MESSAGES_TO_NUMBER)
39+
.text("This is an RCS message sent via the Vonage Messages API")
40+
.failover(SmsTextRequest.builder()
41+
.from(SMS_SENDER_ID).to(MESSAGES_TO_NUMBER)
42+
.text("This is an SMS sent using the Vonage Messages API.")
43+
.build()
44+
)
45+
.build()
46+
);
47+
System.out.println(response);
48+
}
49+
}

0 commit comments

Comments
 (0)