0

Bridge calls

by
Published Apr 8, 2025

Bridge two call control calls. **Expected Webhooks (see [callback schema](https://developers.telnyx.com/api/call-control/bridge-call#callbacks) below):** - `call.bridged` for Leg A - `call.bridged` for Leg B

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Bridge calls
7
 * Bridge two call control calls.
8

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

11
- `call.bridged` for Leg A
12
- `call.bridged` for Leg B
13

14
 */
15
export async function main(
16
	auth: Telnyx,
17
	call_control_id: string,
18
	body: {
19
		call_control_id: string
20
		client_state?: string
21
		command_id?: string
22
		queue?: string
23
		video_room_id?: string
24
		video_room_context?: string
25
		park_after_unbridge?: string
26
		play_ringtone?: false | true
27
		ringtone?:
28
			| 'at'
29
			| 'au'
30
			| 'be'
31
			| 'bg'
32
			| 'br'
33
			| 'ch'
34
			| 'cl'
35
			| 'cn'
36
			| 'cz'
37
			| 'de'
38
			| 'dk'
39
			| 'ee'
40
			| 'es'
41
			| 'fi'
42
			| 'fr'
43
			| 'gr'
44
			| 'hu'
45
			| 'il'
46
			| 'in'
47
			| 'it'
48
			| 'jp'
49
			| 'lt'
50
			| 'mx'
51
			| 'my'
52
			| 'nl'
53
			| 'no'
54
			| 'nz'
55
			| 'ph'
56
			| 'pl'
57
			| 'pt'
58
			| 'ru'
59
			| 'se'
60
			| 'sg'
61
			| 'th'
62
			| 'tw'
63
			| 'uk'
64
			| 'us-old'
65
			| 'us'
66
			| 've'
67
			| 'za'
68
		record?: 'record-from-answer'
69
		record_channels?: 'single' | 'dual'
70
		record_format?: 'wav' | 'mp3'
71
		record_max_length?: number
72
		record_timeout_secs?: number
73
		record_track?: 'both' | 'inbound' | 'outbound'
74
		record_trim?: 'trim-silence'
75
		record_custom_file_name?: string
76
	}
77
) {
78
	const url = new URL(`https://api.telnyx.com/v2/calls/${call_control_id}/actions/bridge`)
79

80
	const response = await fetch(url, {
81
		method: 'POST',
82
		headers: {
83
			'Content-Type': 'application/json',
84
			Authorization: 'Bearer ' + auth.apiKey
85
		},
86
		body: JSON.stringify(body)
87
	})
88
	if (!response.ok) {
89
		const text = await response.text()
90
		throw new Error(`${response.status} ${text}`)
91
	}
92
	return await response.json()
93
}
94