0

SIPREC start

by
Published Apr 8, 2025

Start siprec session to configured in SIPREC connector SRS. **Expected Webhooks:** - `siprec.started` - `siprec.stopped` - `siprec.failed`

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * SIPREC start
7
 * Start siprec session to configured in SIPREC connector SRS. 
8

9
**Expected Webhooks:**
10

11
- `siprec.started`
12
- `siprec.stopped`
13
- `siprec.failed`
14

15
 */
16
export async function main(
17
	auth: Telnyx,
18
	call_control_id: string,
19
	body: {
20
		connector_name?: string
21
		siprec_track?: 'inbound_track' | 'outbound_track' | 'both_tracks'
22
		include_metadata_custom_headers?: false | true
23
		secure?: false | true
24
		session_timeout_secs?: number
25
		client_state?: string
26
	}
27
) {
28
	const url = new URL(`https://api.telnyx.com/v2/calls/${call_control_id}/actions/siprec_start`)
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