1 | |
2 | type Telnyx = { |
3 | apiKey: string |
4 | } |
5 | |
6 | * Create a call control application |
7 | * Create a call control application. |
8 | */ |
9 | export async function main( |
10 | auth: Telnyx, |
11 | body: { |
12 | application_name: string |
13 | webhook_event_url: string |
14 | active?: false | true |
15 | anchorsite_override?: '"Latency"' | '"Chicago, IL"' | '"Ashburn, VA"' | '"San Jose, CA"' |
16 | dtmf_type?: 'RFC 2833' | 'Inband' | 'SIP INFO' |
17 | first_command_timeout?: false | true |
18 | first_command_timeout_secs?: number |
19 | inbound?: { |
20 | channel_limit?: number |
21 | shaken_stir_enabled?: false | true |
22 | sip_subdomain?: string |
23 | sip_subdomain_receive_settings?: 'only_my_connections' | 'from_anyone' |
24 | } |
25 | outbound?: { channel_limit?: number; outbound_voice_profile_id?: string } |
26 | webhook_api_version?: '1' | '2' |
27 | webhook_event_failover_url?: string |
28 | webhook_timeout_secs?: number |
29 | } |
30 | ) { |
31 | const url = new URL(`https://api.telnyx.com/v2/call_control_applications`) |
32 |
|
33 | const response = await fetch(url, { |
34 | method: 'POST', |
35 | headers: { |
36 | 'Content-Type': 'application/json', |
37 | Authorization: 'Bearer ' + auth.apiKey |
38 | }, |
39 | body: JSON.stringify(body) |
40 | }) |
41 | if (!response.ok) { |
42 | const text = await response.text() |
43 | throw new Error(`${response.status} ${text}`) |
44 | } |
45 | return await response.json() |
46 | } |
47 |
|