0

Forking start

by
Published Apr 8, 2025

Call forking allows you to stream the media from a call to a specific target in realtime.

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Forking start
7
 * Call forking allows you to stream the media from a call to a specific target in realtime.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	call_control_id: string,
12
	body: {
13
		rx?: string
14
		stream_type?: 'decrypted'
15
		tx?: string
16
		client_state?: string
17
		command_id?: string
18
	}
19
) {
20
	const url = new URL(`https://api.telnyx.com/v2/calls/${call_control_id}/actions/fork_start`)
21

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