1 | |
2 | type Telnyx = { |
3 | apiKey: string |
4 | } |
5 | |
6 | * List all call recordings |
7 | * Returns a list of your call recordings. |
8 | */ |
9 | export async function main( |
10 | auth: Telnyx, |
11 | filter_conference_id_: string | undefined, |
12 | filter_created_at__gte_: string | undefined, |
13 | filter_created_at__lte_: string | undefined, |
14 | filter_call_leg_id_: string | undefined, |
15 | filter_call_session_id_: string | undefined, |
16 | filter_from_: string | undefined, |
17 | filter_to_: string | undefined, |
18 | filter_connection_id_: string | undefined, |
19 | page_number_: string | undefined, |
20 | page_size_: string | undefined |
21 | ) { |
22 | const url = new URL(`https://api.telnyx.com/v2/recordings`) |
23 | for (const [k, v] of [ |
24 | ['filter[conference_id]', filter_conference_id_], |
25 | ['filter[created_at][gte]', filter_created_at__gte_], |
26 | ['filter[created_at][lte]', filter_created_at__lte_], |
27 | ['filter[call_leg_id]', filter_call_leg_id_], |
28 | ['filter[call_session_id]', filter_call_session_id_], |
29 | ['filter[from]', filter_from_], |
30 | ['filter[to]', filter_to_], |
31 | ['filter[connection_id]', filter_connection_id_], |
32 | ['page[number]', page_number_], |
33 | ['page[size]', page_size_] |
34 | ]) { |
35 | if (v !== undefined && v !== '' && k !== undefined) { |
36 | url.searchParams.append(k, v) |
37 | } |
38 | } |
39 | const response = await fetch(url, { |
40 | method: 'GET', |
41 | headers: { |
42 | Authorization: 'Bearer ' + auth.apiKey |
43 | }, |
44 | body: undefined |
45 | }) |
46 | if (!response.ok) { |
47 | const text = await response.text() |
48 | throw new Error(`${response.status} ${text}`) |
49 | } |
50 | return await response.json() |
51 | } |
52 |
|