0

Recording start

by
Published Apr 8, 2025

Start recording the call. Recording will stop on call hang-up, or can be initiated via the Stop Recording command. **Expected Webhooks (see [callback schema](https://developers.telnyx.com/api/call-control/start-call-record#callbacks) below):** - `call.recording.saved`

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Recording start
7
 * Start recording the call. Recording will stop on call hang-up, or can be initiated via the Stop Recording command.
8

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

11
- `call.recording.saved`
12

13
 */
14
export async function main(
15
	auth: Telnyx,
16
	call_control_id: string,
17
	body: {
18
		format: 'wav' | 'mp3'
19
		channels: 'single' | 'dual'
20
		client_state?: string
21
		command_id?: string
22
		play_beep?: false | true
23
		max_length?: number
24
		timeout_secs?: number
25
		recording_track?: 'both' | 'inbound' | 'outbound'
26
		trim?: 'trim-silence'
27
		custom_file_name?: string
28
		transcription?: false | true
29
		transcription_engine?: 'A' | 'B'
30
		transcription_language?:
31
			| 'af'
32
			| 'sq'
33
			| 'am'
34
			| 'ar'
35
			| 'hy'
36
			| 'az'
37
			| 'eu'
38
			| 'bn'
39
			| 'bs'
40
			| 'bg'
41
			| 'my'
42
			| 'ca'
43
			| 'yue'
44
			| 'zh'
45
			| 'hr'
46
			| 'cs'
47
			| 'da'
48
			| 'nl'
49
			| 'en'
50
			| 'et'
51
			| 'fil'
52
			| 'fi'
53
			| 'fr'
54
			| 'gl'
55
			| 'ka'
56
			| 'de'
57
			| 'el'
58
			| 'gu'
59
			| 'iw'
60
			| 'hi'
61
			| 'hu'
62
			| 'is'
63
			| 'id'
64
			| 'it'
65
			| 'ja'
66
			| 'jv'
67
			| 'kn'
68
			| 'kk'
69
			| 'km'
70
			| 'ko'
71
			| 'lo'
72
			| 'lv'
73
			| 'lt'
74
			| 'mk'
75
			| 'ms'
76
			| 'ml'
77
			| 'mr'
78
			| 'mn'
79
			| 'ne'
80
			| 'no'
81
			| 'fa'
82
			| 'pl'
83
			| 'pt'
84
			| 'pa'
85
			| 'ro'
86
			| 'ru'
87
			| 'rw'
88
			| 'sr'
89
			| 'si'
90
			| 'sk'
91
			| 'sl'
92
			| 'ss'
93
			| 'st'
94
			| 'es'
95
			| 'su'
96
			| 'sw'
97
			| 'sv'
98
			| 'ta'
99
			| 'te'
100
			| 'th'
101
			| 'tn'
102
			| 'tr'
103
			| 'ts'
104
			| 'uk'
105
			| 'ur'
106
			| 'uz'
107
			| 've'
108
			| 'vi'
109
			| 'xh'
110
			| 'zu'
111
			| 'he'
112
			| 'la'
113
			| 'mi'
114
			| 'cy'
115
			| 'br'
116
			| 'sn'
117
			| 'yo'
118
			| 'so'
119
			| 'oc'
120
			| 'be'
121
			| 'tg'
122
			| 'sd'
123
			| 'yi'
124
			| 'fo'
125
			| 'ht'
126
			| 'ps'
127
			| 'tk'
128
			| 'nn'
129
			| 'mt'
130
			| 'sa'
131
			| 'lb'
132
			| 'bo'
133
			| 'tl'
134
			| 'mg'
135
			| 'as'
136
			| 'tt'
137
			| 'haw'
138
			| 'ln'
139
			| 'ha'
140
			| 'ba'
141
			| 'jw'
142
			| 'auto_detect'
143
		transcription_profanity_filter?: false | true
144
		transcription_speaker_diarization?: false | true
145
		transcription_min_speaker_count?: number
146
		transcription_max_speaker_count?: number
147
	}
148
) {
149
	const url = new URL(`https://api.telnyx.com/v2/calls/${call_control_id}/actions/record_start`)
150

151
	const response = await fetch(url, {
152
		method: 'POST',
153
		headers: {
154
			'Content-Type': 'application/json',
155
			Authorization: 'Bearer ' + auth.apiKey
156
		},
157
		body: JSON.stringify(body)
158
	})
159
	if (!response.ok) {
160
		const text = await response.text()
161
		throw new Error(`${response.status} ${text}`)
162
	}
163
	return await response.json()
164
}
165