Skip to content

Commit 6dc0124

Browse files
committed
feat: Call.Builder.to* methods
1 parent 40291d1 commit 6dc0124

File tree

2 files changed

+84
-1
lines changed

2 files changed

+84
-1
lines changed

src/main/kotlin/com/vonage/client/kt/Voice.kt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.vonage.client.kt
22

3-
import com.vonage.client.users.channels.Websocket.ContentType
43
import com.vonage.client.voice.*
54
import com.vonage.client.voice.ncco.*
65
import java.net.URI
@@ -135,3 +134,20 @@ fun connectToSip(uri: String, customHeaders: Map<String, Any>? = null, userToUse
135134
}
136135
return connectAction(builder.build(), properties)
137136
}
137+
138+
fun Call.Builder.toPstn(number: String, dtmfAnswer: String? = null): Call.Builder =
139+
to(com.vonage.client.voice.PhoneEndpoint(number, dtmfAnswer))
140+
141+
fun Call.Builder.toSip(uri: String, customHeaders: Map<String, Any>? = null,
142+
userToUserHeader: String? = null): Call.Builder =
143+
to(com.vonage.client.voice.SipEndpoint(uri, customHeaders, userToUserHeader))
144+
145+
fun Call.Builder.toWebSocket(uri: String, contentType: String? = null,
146+
headers: Map<String, Any>? = null): Call.Builder =
147+
to(com.vonage.client.voice.WebSocketEndpoint(uri, contentType, headers))
148+
149+
fun Call.Builder.toVbc(extension: String): Call.Builder =
150+
to(com.vonage.client.voice.VbcEndpoint(extension))
151+
152+
fun Call.Builder.toApp(user: String): Call.Builder =
153+
to(com.vonage.client.voice.AppEndpoint(user))

src/test/kotlin/com/vonage/client/kt/VoiceTest.kt

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,19 @@ class VoiceTest : AbstractTest() {
207207
assertEquals(conversationId, callEvent.conversationUuid)
208208
}
209209

210+
private fun testCreateCallToSingleEndpoint(toParams: Map<String, Any>,
211+
toBuilder: Call.Builder.() -> Call.Builder) {
212+
testCreateCall(mapOf(
213+
"random_from_number" to true,
214+
"answer_url" to listOf(onAnswerUrl),
215+
"answer_method" to "GET",
216+
"to" to listOf(toParams)
217+
)) {
218+
fromRandomNumber(true); answerUrl(onAnswerUrl)
219+
toBuilder()
220+
}
221+
}
222+
210223
private fun testSingleNcco(additionalParams: Map<String, Any> = mapOf(), ncco: Action) {
211224
val requestParams = mapOf(
212225
"random_from_number" to true,
@@ -392,6 +405,60 @@ class VoiceTest : AbstractTest() {
392405
}
393406
}
394407

408+
@Test
409+
fun `create call to PSTN`() {
410+
val baseMap = mapOf("type" to phoneType, "number" to toNumber)
411+
testCreateCallToSingleEndpoint(baseMap) {
412+
toPstn(toNumber)
413+
}
414+
415+
testCreateCallToSingleEndpoint(baseMap + mapOf("dtmfAnswer" to dtmf)) {
416+
toPstn(toNumber, dtmf)
417+
}
418+
}
419+
420+
@Test
421+
fun `create call to App`() {
422+
testCreateCallToSingleEndpoint(mapOf("type" to "app", "user" to user)) {
423+
toApp(user)
424+
}
425+
}
426+
427+
@Test
428+
fun `create call to VBC`() {
429+
testCreateCallToSingleEndpoint(mapOf("type" to "vbc", "extension" to vbcExt)) {
430+
toVbc(vbcExt)
431+
}
432+
}
433+
434+
@Test
435+
fun `create call to SIP`() {
436+
val baseMap = mapOf("type" to "sip", "uri" to sipUri)
437+
testCreateCallToSingleEndpoint(baseMap) {
438+
toSip(sipUri)
439+
}
440+
441+
testCreateCallToSingleEndpoint(baseMap + mapOf(
442+
"headers" to customHeaders, "standard_headers" to mapOf("User-to-User" to userToUserHeader)
443+
)) {
444+
toSip(sipUri, customHeaders, userToUserHeader)
445+
}
446+
}
447+
448+
@Test
449+
fun `create call to WebSocket`() {
450+
val baseMap = mapOf("type" to "websocket", "uri" to websocketUri)
451+
testCreateCallToSingleEndpoint(baseMap) {
452+
toWebSocket(websocketUri)
453+
}
454+
455+
testCreateCallToSingleEndpoint(baseMap + mapOf(
456+
"content-type" to wsContentType, "headers" to customHeaders
457+
)) {
458+
toWebSocket(websocketUri, wsContentType, customHeaders)
459+
}
460+
}
461+
395462
@Test
396463
fun `create call to all endpoint types with all fields and answer url`() {
397464
val answerUrl = "https://example.com/answer"

0 commit comments

Comments
 (0)