0

Gather

by
Published Apr 8, 2025

Gather DTMF signals to build interactive menus. You can pass a list of valid digits. The `Answer` command must be issued before the `gather` command. **Expected Webhooks (see [callback schema](https://developers.telnyx.com/api/call-control/gather-call#callbacks) below):** - `call.dtmf.received` (you may receive many of these webhooks) - `call.gather.ended`

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
7
 * Gather DTMF signals to build interactive menus.
8

9
You can pass a list of valid digits. The `Answer` command must be issued before the `gather` command.
10

11
**Expected Webhooks (see [callback schema](https://developers.telnyx.com/api/call-control/gather-call#callbacks) below):**
12

13
- `call.dtmf.received` (you may receive many of these webhooks)
14
- `call.gather.ended`
15

16
 */
17
export async function main(
18
	auth: Telnyx,
19
	call_control_id: string,
20
	body: {
21
		minimum_digits?: number
22
		maximum_digits?: number
23
		timeout_millis?: number
24
		inter_digit_timeout_millis?: number
25
		initial_timeout_millis?: number
26
		terminating_digit?: string
27
		valid_digits?: string
28
		gather_id?: string
29
		client_state?: string
30
		command_id?: string
31
	}
32
) {
33
	const url = new URL(`https://api.telnyx.com/v2/calls/${call_control_id}/actions/gather`)
34

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