Skip to content

Commit 552db07

Browse files
committed
feat: Async DTMF listener
1 parent c957b7f commit 552db07

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
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.1.0] - 2024-11-??
7+
## [1.1.0] - 2024-11-05
88

99
### Added
10-
- Custom template management for Verify API
1110
- Pricing API
11+
- Custom template management for Verify API
12+
- Asynchronous DTMF event listener endpoints in Voice API
1213

1314
## [1.0.0] - 2024-10-25
1415
First stable GA release

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,23 @@ class Voice internal constructor(private val client: VoiceClient) {
9999
*/
100100
fun sendDtmf(digits: String): DtmfResponse = client.sendDtmf(id, digits)
101101

102+
/**
103+
* Subscribe to real-time DTMF key presses on the call, where the input mode is [InputMode.ASYNCHRONOUS].
104+
*
105+
* @param eventUrl The publicly accessible URL to send DTMF events to,
106+
* which can be deserialised using [EventWebhook.fromJson].
107+
*
108+
* @since 1.1.0
109+
*/
110+
fun subscribeToDtmfEvents(eventUrl: String): Unit = client.addDtmfListener(id, eventUrl)
111+
112+
/**
113+
* Stop asynchronous DTMF events being sent to the URL configured in [subscribeToDtmfEvents].
114+
*
115+
* @since 1.1.0
116+
*/
117+
fun stopAsyncDtmfEvents(): Unit = client.removeDtmfListener(id)
118+
102119
/**
103120
* Play an audio file to the call.
104121
*

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,20 @@ class VoiceTest : AbstractTest() {
329329
assertEquals(callIdStr, response.uuid)
330330
}
331331

332+
@Test
333+
fun `subscribe to real-time DTMF events`() {
334+
mockPut(expectedUrl = "$callUrl/input/dtmf", status = 200,
335+
expectedRequestParams = mapOf("event_url" to listOf(eventUrl))
336+
)
337+
existingCall.subscribeToDtmfEvents(eventUrl)
338+
}
339+
340+
@Test
341+
fun `stop receiving real-time DTMF events`() {
342+
mockDelete(expectedUrl = "$callUrl/input/dtmf")
343+
existingCall.stopAsyncDtmfEvents()
344+
}
345+
332346
@Test
333347
fun `stream audio into call`() {
334348
val loop = 3

0 commit comments

Comments
 (0)