Skip to content

Commit ffff17b

Browse files
committed
feat: InputAction.Builder#type boolean method
1 parent 6ea7007 commit ffff17b

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7-
## [1.0.0] - 2024-10-25 (expected)
7+
## [1.0.0] - 2024-10-25
88
First stable GA release
99

1010
### Added
1111
- `Voice.downloadRecording(String, Path)` method
12+
- `InputAction.Builder.type` Boolean overload method (preferable to the Collection method)
1213

1314
### Changed
1415
- `Sms.wasSuccessfullySent()` now an extension function rather than being part of the client

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<kotlin.compiler.languageVersion>2.0</kotlin.compiler.languageVersion>
4848
<kotlin.compiler.apiVersion>${kotlin.compiler.languageVersion}</kotlin.compiler.apiVersion>
4949
<kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
50-
<kotlin.lib.version>2.0.20</kotlin.lib.version>
50+
<kotlin.lib.version>2.0.21</kotlin.lib.version>
5151
<java.version>8</java.version>
5252
</properties>
5353

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,25 @@ fun InputAction.Builder.speech(settings: SpeechSettings.Builder.() -> Unit = {})
217217
fun InputAction.Builder.dtmf(settings: DtmfSettings.Builder.() -> Unit = {}): InputAction.Builder =
218218
dtmf(DtmfSettings.builder().apply(settings).build())
219219

220+
/**
221+
* Sets the input type(s). At least one must be specified (i.e. set to `true`).
222+
*
223+
* @param dtmf Whether to accept DTMF input.
224+
* @param speech Whether to accept speech input.
225+
*
226+
* @return The updated [InputAction.Builder].
227+
* @see InputAction.Builder.type(Collection)
228+
*/
229+
fun InputAction.Builder.type(dtmf: Boolean = false, speech: Boolean = false): InputAction.Builder {
230+
var type = mutableListOf<String>()
231+
if (dtmf) type.add("dtmf")
232+
if (speech) type.add("speech")
233+
if (type.isEmpty()) {
234+
throw IllegalArgumentException("At least one input type must be specified.")
235+
}
236+
return type(type)
237+
}
238+
220239
/**
221240
* Configure the behaviour of call recording transcription. If present (even if all settings are default),
222241
* transcription is activated. The [ConversationAction.Builder.record] parameter must also be set to `true`.

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import com.vonage.client.common.HttpMethod
1919
import com.vonage.client.voice.*
2020
import com.vonage.client.voice.ncco.*
2121
import org.junit.jupiter.api.Assertions.assertArrayEquals
22+
import org.junit.jupiter.api.assertThrows
2223
import java.nio.file.Files
2324
import java.util.*
2425
import kotlin.io.path.deleteExisting
@@ -596,11 +597,25 @@ class VoiceTest : AbstractTest() {
596597

597598
@Test
598599
fun `create call with input action required parameters only`() {
599-
val types = listOf("dtmf", "speech")
600600
testSingleNcco(
601-
additionalParams = mapOf("type" to types),
602-
ncco = inputAction { type(types) }
601+
additionalParams = mapOf("type" to listOf("dtmf", "speech")),
602+
ncco = inputAction { type(speech = true, dtmf = true) }
603603
)
604+
testSingleNcco(
605+
additionalParams = mapOf("type" to listOf("dtmf")),
606+
ncco = inputAction { type(dtmf = true) }
607+
)
608+
testSingleNcco(
609+
additionalParams = mapOf("type" to listOf("speech")),
610+
ncco = inputAction { type(speech = true) }
611+
)
612+
}
613+
614+
@Test
615+
fun `at least one type should be specified in inputAction`() {
616+
assertThrows<IllegalArgumentException> {
617+
inputAction { type() }
618+
}
604619
}
605620

606621
@Test

0 commit comments

Comments
 (0)