0

Request recording for a call

by
Published Apr 8, 2025

Starts recording with specified parameters for call idientified by call_sid.

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Request recording for a call
7
 * Starts recording with specified parameters for call idientified by call_sid.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	account_sid: string,
12
	call_sid: string,
13
	body: {
14
		PlayBeep?: false | true
15
		RecordingStatusCallbackEvent?: string
16
		RecordingStatusCallback?: string
17
		RecordingStatusCallbackMethod?: 'GET' | 'POST'
18
		RecordingChannels?: 'single' | 'dual'
19
		RecordingTrack?: 'inbound' | 'outbound' | 'both'
20
	}
21
) {
22
	const url = new URL(
23
		`https://api.telnyx.com/v2/texml/Accounts/${account_sid}/Calls/${call_sid}/Recordings.json`
24
	)
25

26
	const response = await fetch(url, {
27
		method: 'POST',
28
		headers: {
29
			'Content-Type': 'application/x-www-form-urlencoded',
30
			Authorization: 'Bearer ' + auth.apiKey
31
		},
32
		body: new URLSearchParams(body as Record<string, string>)
33
	})
34
	if (!response.ok) {
35
		const text = await response.text()
36
		throw new Error(`${response.status} ${text}`)
37
	}
38
	return await response.json()
39
}
40