0

Gather using audio

by
Published Apr 8, 2025

Play an audio file on the call until the required DTMF signals are gathered to build interactive menus.

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Gather using audio
7
 * Play an audio file on the call until the required DTMF signals are gathered to build interactive menus.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	call_control_id: string,
12
	body: {
13
		audio_url?: string
14
		media_name?: string
15
		invalid_audio_url?: string
16
		invalid_media_name?: string
17
		minimum_digits?: number
18
		maximum_digits?: number
19
		maximum_tries?: number
20
		timeout_millis?: number
21
		terminating_digit?: string
22
		valid_digits?: string
23
		inter_digit_timeout_millis?: number
24
		client_state?: string
25
		command_id?: string
26
	}
27
) {
28
	const url = new URL(
29
		`https://api.telnyx.com/v2/calls/${call_control_id}/actions/gather_using_audio`
30
	)
31

32
	const response = await fetch(url, {
33
		method: 'POST',
34
		headers: {
35
			'Content-Type': 'application/json',
36
			Authorization: 'Bearer ' + auth.apiKey
37
		},
38
		body: JSON.stringify(body)
39
	})
40
	if (!response.ok) {
41
		const text = await response.text()
42
		throw new Error(`${response.status} ${text}`)
43
	}
44
	return await response.json()
45
}
46