0

Send DTMF

by
Published Apr 8, 2025

Sends DTMF tones from this leg. DTMF tones will be heard by the other end of the call. **Expected Webhooks:** There are no webhooks associated with this command.

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Send DTMF
7
 * Sends DTMF tones from this leg. DTMF tones will be heard by the other end of the call.
8

9
**Expected Webhooks:**
10

11
There are no webhooks associated with this command.
12

13
 */
14
export async function main(
15
	auth: Telnyx,
16
	call_control_id: string,
17
	body: {
18
		digits: string
19
		duration_millis?: number
20
		client_state?: string
21
		command_id?: string
22
	}
23
) {
24
	const url = new URL(`https://api.telnyx.com/v2/calls/${call_control_id}/actions/send_dtmf`)
25

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