0

Forking stop

by
Published Apr 8, 2025

Stop forking a call. **Expected Webhooks (see [callback schema](https://developers.telnyx.com/api/call-control/stop-call-fork#callbacks) below):** - `call.fork.stopped`

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 stop
7
 * Stop forking a call.
8

9
**Expected Webhooks (see [callback schema](https://developers.telnyx.com/api/call-control/stop-call-fork#callbacks) below):**
10

11
- `call.fork.stopped`
12

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

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