0

Create conference

by
Published Apr 8, 2025

Create a conference from an existing call leg using a `call_control_id` and a conference name.

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Create conference
7
 * Create a conference from an existing call leg using a `call_control_id` and a conference name.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	body: {
12
		call_control_id: string
13
		name: string
14
		beep_enabled?: 'always' | 'never' | 'on_enter' | 'on_exit'
15
		client_state?: string
16
		comfort_noise?: false | true
17
		command_id?: string
18
		duration_minutes?: number
19
		hold_audio_url?: string
20
		hold_media_name?: string
21
		max_participants?: number
22
		start_conference_on_create?: false | true
23
	}
24
) {
25
	const url = new URL(`https://api.telnyx.com/v2/conferences`)
26

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