1 | |
2 | type Telnyx = { |
3 | apiKey: string |
4 | } |
5 | |
6 | * Enqueue call |
7 | * Put the call in a queue. |
8 | */ |
9 | export async function main( |
10 | auth: Telnyx, |
11 | call_control_id: string, |
12 | body: { |
13 | queue_name: string |
14 | client_state?: string |
15 | command_id?: string |
16 | max_wait_time_secs?: number |
17 | max_size?: number |
18 | } |
19 | ) { |
20 | const url = new URL(`https://api.telnyx.com/v2/calls/${call_control_id}/actions/enqueue`) |
21 |
|
22 | const response = await fetch(url, { |
23 | method: 'POST', |
24 | headers: { |
25 | 'Content-Type': 'application/json', |
26 | Authorization: 'Bearer ' + auth.apiKey |
27 | }, |
28 | body: JSON.stringify(body) |
29 | }) |
30 | if (!response.ok) { |
31 | const text = await response.text() |
32 | throw new Error(`${response.status} ${text}`) |
33 | } |
34 | return await response.json() |
35 | } |
36 |
|