0

Leave a conference

by
Published Apr 8, 2025

Removes a call leg from a conference and moves it back to parked state. **Expected Webhooks (see [callback schema](https://developers.telnyx.com/api/call-control/leave-conference#callbacks) below):** - `conference.participant.left`

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Leave a conference
7
 * Removes a call leg from a conference and moves it back to parked state. 
8

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

11
- `conference.participant.left`
12

13
 */
14
export async function main(
15
	auth: Telnyx,
16
	id: string,
17
	body: {
18
		call_control_id: string
19
		command_id?: string
20
		beep_enabled?: 'always' | 'never' | 'on_enter' | 'on_exit'
21
	}
22
) {
23
	const url = new URL(`https://api.telnyx.com/v2/conferences/${id}/actions/leave`)
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