0

Join a conference

by
Published Apr 8, 2025

Join an existing call leg to a conference.

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Join a conference
7
 * Join an existing call leg to a conference.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	id: string,
12
	body: {
13
		call_control_id: string
14
		client_state?: string
15
		command_id?: string
16
		end_conference_on_exit?: false | true
17
		soft_end_conference_on_exit?: false | true
18
		hold?: false | true
19
		hold_audio_url?: string
20
		hold_media_name?: string
21
		mute?: false | true
22
		start_conference_on_enter?: false | true
23
		supervisor_role?: 'barge' | 'monitor' | 'none' | 'whisper'
24
		whisper_call_control_ids?: string[]
25
		beep_enabled?: 'always' | 'never' | 'on_enter' | 'on_exit'
26
	}
27
) {
28
	const url = new URL(`https://api.telnyx.com/v2/conferences/${id}/actions/join`)
29

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