0

Request siprec session for a call

by
Published Apr 8, 2025

Starts siprec session 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 siprec session for a call
7
 * Starts siprec session 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
		ConnectorName?: string
15
		Track?: 'both_tracks' | 'inbound_track' | 'outbound_track'
16
		IncludeMetadataCustomHeaders?: false | true
17
		Secure?: false | true
18
		SessionTimeoutSecs?: number
19
		StatusCallback?: string
20
		StatusCallbackMethod?: 'GET' | 'POST'
21
	}
22
) {
23
	const url = new URL(
24
		`https://api.telnyx.com/v2/texml/Accounts/${account_sid}/Calls/${call_sid}/Siprec.json`
25
	)
26

27
	const response = await fetch(url, {
28
		method: 'POST',
29
		headers: {
30
			'Content-Type': 'application/x-www-form-urlencoded',
31
			Authorization: 'Bearer ' + auth.apiKey
32
		},
33
		body: new URLSearchParams(body as Record<string, string>)
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