From 77d404f269010fdf97aa678dccb3880e0fd056fc Mon Sep 17 00:00:00 2001 From: Sina Madani Date: Tue, 2 Jul 2024 06:47:14 +0100 Subject: [PATCH] feat: Default Voice lambdas --- src/main/kotlin/com/vonage/client/kt/Voice.kt | 24 +++++++++---------- .../kotlin/com/vonage/client/kt/VoiceTest.kt | 20 ++++++++++++++++ 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/com/vonage/client/kt/Voice.kt b/src/main/kotlin/com/vonage/client/kt/Voice.kt index 9f6c8b0..1339151 100644 --- a/src/main/kotlin/com/vonage/client/kt/Voice.kt +++ b/src/main/kotlin/com/vonage/client/kt/Voice.kt @@ -59,7 +59,7 @@ fun CallsFilter.Builder.dateStart(dateStart: String): CallsFilter.Builder = fun CallsFilter.Builder.dateEnd(dateEnd: String): CallsFilter.Builder = dateEnd(Date.from(Instant.parse(dateEnd))) -fun Call.Builder.advancedMachineDetection(amd: AdvancedMachineDetection.Builder.() -> Unit): Call.Builder = +fun Call.Builder.advancedMachineDetection(amd: AdvancedMachineDetection.Builder.() -> Unit = {}): Call.Builder = advancedMachineDetection(AdvancedMachineDetection.builder().apply(amd).build()) fun InputAction.Builder.speech(settings: SpeechSettings.Builder.() -> Unit): InputAction.Builder = @@ -73,33 +73,33 @@ fun InputAction.Builder.dtmf(timeout: Int? = null, maxDigits: Int? = null, submi return dtmf(dtmfSettings) } -fun ConversationAction.Builder.transcription(settings: TranscriptionSettings.Builder.() -> Unit): ConversationAction.Builder = - transcription(TranscriptionSettings.builder().apply(settings).build()) +fun ConversationAction.Builder.transcription(settings: TranscriptionSettings.Builder.() -> Unit = {}): + ConversationAction.Builder = transcription(TranscriptionSettings.builder().apply(settings).build()) -fun RecordAction.Builder.transcription(settings: TranscriptionSettings.Builder.() -> Unit): RecordAction.Builder = +fun RecordAction.Builder.transcription(settings: TranscriptionSettings.Builder.() -> Unit = {}): RecordAction.Builder = transcription(TranscriptionSettings.builder().apply(settings).build()) -fun ConnectAction.Builder.advancedMachineDetection(amd: AdvancedMachineDetection.Builder.() -> Unit): ConnectAction.Builder = - advancedMachineDetection(AdvancedMachineDetection.builder().apply(amd).build()) +fun ConnectAction.Builder.advancedMachineDetection(amd: AdvancedMachineDetection.Builder.() -> Unit = {}): + ConnectAction.Builder = advancedMachineDetection(AdvancedMachineDetection.builder().apply(amd).build()) -fun recordAction(properties: RecordAction.Builder.() -> Unit): RecordAction = +fun recordAction(properties: RecordAction.Builder.() -> Unit = {}): RecordAction = RecordAction.builder().apply(properties).build() -fun talkAction(text: String, properties: TalkAction.Builder.() -> Unit): TalkAction = +fun talkAction(text: String, properties: TalkAction.Builder.() -> Unit = {}): TalkAction = TalkAction.builder(text).apply(properties).build() -fun streamAction(streamUrl: String, properties: StreamAction.Builder.() -> Unit): StreamAction = +fun streamAction(streamUrl: String, properties: StreamAction.Builder.() -> Unit = {}): StreamAction = StreamAction.builder(streamUrl).apply(properties).build() fun notifyAction(eventUrl: String, payload: Map? = null, eventMethod: EventMethod? = null): NotifyAction = NotifyAction.builder(payload, eventUrl).eventMethod(eventMethod).build() -fun inputAction(properties: InputAction.Builder.() -> Unit): InputAction = +fun inputAction(properties: InputAction.Builder.() -> Unit = {}): InputAction = InputAction.builder().apply(properties).build() -fun conversationAction(name: String, properties: ConversationAction.Builder.() -> Unit): ConversationAction = +fun conversationAction(name: String, properties: ConversationAction.Builder.() -> Unit = {}): ConversationAction = ConversationAction.builder(name).apply(properties).build() fun connectAction(endpoint: com.vonage.client.voice.ncco.Endpoint, - properties: ConnectAction.Builder.() -> Unit): ConnectAction = + properties: ConnectAction.Builder.() -> Unit = {}): ConnectAction = ConnectAction.builder(endpoint).apply(properties).build() diff --git a/src/test/kotlin/com/vonage/client/kt/VoiceTest.kt b/src/test/kotlin/com/vonage/client/kt/VoiceTest.kt index 21fc7ee..bde8234 100644 --- a/src/test/kotlin/com/vonage/client/kt/VoiceTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/VoiceTest.kt @@ -2,6 +2,7 @@ package com.vonage.client.kt import com.vonage.client.common.HttpMethod import com.vonage.client.voice.* +import com.vonage.client.voice.PhoneEndpoint import com.vonage.client.voice.ncco.* import java.net.URI import java.time.Instant @@ -346,6 +347,25 @@ class VoiceTest : AbstractTest() { assertEqualsSampleCallsPage(voiceClient.listCalls()) } + @Test + fun `create TTS call with required parameters only`() { + val ssmlText = "I can speak fast." + testCreateCall(mapOf( + "random_from_number" to true, + "to" to listOf(mapOf( + "type" to phoneType, + "number" to toNumber + )), + "ncco" to listOf(mapOf( + "action" to "talk", + "text" to ssmlText + )) + )) { + fromRandomNumber(true); to(PhoneEndpoint(toNumber)) + ncco(talkAction(ssmlText)) + } + } + @Test fun `create call to all endpoint types with all fields and answer url`() { val answerUrl = "https://example.com/answer"