Skip to content

Commit d0eeecc

Browse files
committed
feat: Add Messages failover example
1 parent a95b80e commit d0eeecc

File tree

5 files changed

+84
-3
lines changed

5 files changed

+84
-3
lines changed

.env-example

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ VERIFY_TEMPLATE_NAME="verify"
130130
VERIFY_TEMPLATE_ID="bcdef09-8765-4321-8cde-0123456789ab"
131131
VERIFY_TEMPLATE_FRAGMENT_ID="aaaaaaaa-bbbb-4ccc-8ddd-0123456789ab"
132132

133+
# Video
134+
VIDEO_SESSION_ID="flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN"
135+
VIDEO_TOKEN="eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhcHBsaWNhdGlvbl9pZCI6ImFhYWFhYWFhLWJiYmItNGNjYy04ZGRkLTAxMjM0NTY3ODlhYiJ9.o3U506EejsS8D5Tob90FG1NC1cR69fh3pFOpxnyTHVFfgqI6NWuuN8lEwrS3Zb8bGxE_A9LyyUZ2y4uqLpyXRw"
136+
VIDEO_CONNECTION_ID="bcdef09-8765-4321-8cde-0123456789ab"
137+
VIDEO_STREAM_ID="bcdef09-8765-4321-8cde-0123456789ab"
138+
VIDEO_ARCHIVE_ID="aaaaaaaa-bbbb-4ccc-8ddd-0123456789ab"
139+
VIDEO_BROADCAST_ID="aaaaaaaa-bbbb-4ccc-8ddd-0123456789ab"
140+
133141
# Voice
134142
VOICE_CALL_ID="aaaaaaaa-bbbb-4ccc-8ddd-0123456789ab"
135143
VOICE_TO_NUMBER="447700900000"

SNIPPETS.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,24 @@ embeddedServer(Netty, port = 8000) {
202202
}.start(wait = true)
203203
```
204204

205+
### Send Message With Failover
206+
```kotlin
207+
val messageId = client.messages.send(
208+
rcsText {
209+
to(MESSAGES_TO_NUMBER)
210+
from(RCS_SENDER_ID)
211+
text("This is an RCS text message sent using the Messages API")
212+
failover(
213+
smsText {
214+
to(MESSAGES_TO_NUMBER)
215+
from(SMS_SENDER_ID)
216+
text("This is an SMS sent using the Vonage Messages API.")
217+
}
218+
)
219+
}
220+
)
221+
```
222+
205223
### RCS
206224
#### Send RCS Suggested Reply
207225
```kotlin

build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
project.setProperty("mainClassName", "AggregateSnippetsKt")
44

55
plugins {
6-
kotlin("jvm") version "2.1.+"
7-
id("io.ktor.plugin") version "3.0.+"
6+
kotlin("jvm") version "2.+"
7+
id("io.ktor.plugin") version "3.+"
88
}
99

1010
repositories {
@@ -13,7 +13,7 @@ repositories {
1313
}
1414

1515
dependencies {
16-
implementation("com.vonage:server-sdk-kotlin:2.+")
16+
implementation("com.vonage:server-sdk-kotlin:2.1.1")
1717
implementation("io.ktor:ktor-server-netty")
1818
implementation("io.ktor:ktor-serialization-jackson")
1919
implementation("io.github.cdimascio:dotenv-kotlin:6.+")

src/main/kotlin/com/vonage/quickstart/kt/EnvironmentVariables.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,14 @@ val VERIFY_TEMPLATE_NAME = envVar("VERIFY_TEMPLATE_NAME")
166166
val VERIFY_TEMPLATE_ID = envVar("VERIFY_TEMPLATE_ID")
167167
val VERIFY_TEMPLATE_FRAGMENT_ID = envVar("VERIFY_TEMPLATE_FRAGMENT_ID")
168168

169+
// Video
170+
val VIDEO_SESSION_ID = envVar("VIDEO_SESSION_ID")
171+
val VIDEO_TOKEN = envVar("VIDEO_TOKEN")
172+
val VIDEO_CONNECTION_ID = envVar("VIDEO_CONNECTION_ID")
173+
val VIDEO_STREAM_ID = envVar("VIDEO_STREAM_ID")
174+
val VIDEO_ARCHIVE_ID = envVar("VIDEO_ARCHIVE_ID")
175+
val VIDEO_BROADCAST_ID = envVar("VIDEO_BROADCAST_ID")
176+
169177
// Voice
170178
val VOICE_CALL_ID = envVar("VOICE_CALL_ID")
171179
val VOICE_TO_NUMBER = envVar("VOICE_TO_NUMBER")
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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.kt.messages
23+
24+
import com.vonage.client.kt.*
25+
import com.vonage.quickstart.kt.*
26+
27+
fun main() {
28+
val client = Vonage {
29+
applicationId(VONAGE_APPLICATION_ID)
30+
privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
31+
}
32+
33+
val messageId = client.messages.send(
34+
rcsText {
35+
to(MESSAGES_TO_NUMBER)
36+
from(RCS_SENDER_ID)
37+
text("This is an RCS text message sent using the Messages API")
38+
failover(
39+
smsText {
40+
to(MESSAGES_TO_NUMBER)
41+
from(SMS_SENDER_ID)
42+
text("This is an SMS sent using the Vonage Messages API.")
43+
}
44+
)
45+
}
46+
)
47+
}

0 commit comments

Comments
 (0)