1 | |
2 | type Telnyx = { |
3 | apiKey: string |
4 | } |
5 | |
6 | * Create an Ip connection |
7 | * Creates an IP connection. |
8 | */ |
9 | export async function main( |
10 | auth: Telnyx, |
11 | body: { |
12 | active?: false | true |
13 | anchorsite_override?: |
14 | | 'Latency' |
15 | | 'Chicago, IL' |
16 | | 'Ashburn, VA' |
17 | | 'San Jose, CA' |
18 | | 'Sydney, Australia' |
19 | | 'Amsterdam, Netherlands' |
20 | | 'London, UK' |
21 | | 'Toronto, Canada' |
22 | | 'Vancouver, Canada' |
23 | | 'Frankfurt, Germany' |
24 | connection_name?: string |
25 | transport_protocol?: 'UDP' | 'TCP' | 'TLS' |
26 | default_on_hold_comfort_noise_enabled?: false | true |
27 | dtmf_type?: 'RFC 2833' | 'Inband' | 'SIP INFO' |
28 | encode_contact_header_enabled?: false | true |
29 | encrypted_media?: 'SRTP' |
30 | onnet_t38_passthrough_enabled?: false | true |
31 | ios_push_credential_id?: string |
32 | android_push_credential_id?: string |
33 | webhook_event_url?: string |
34 | webhook_event_failover_url?: string |
35 | webhook_api_version?: '1' | '2' |
36 | webhook_timeout_secs?: number |
37 | rtcp_settings?: { |
38 | port?: 'rtcp-mux' | 'rtp+1' |
39 | capture_enabled?: false | true |
40 | report_frequency_secs?: number |
41 | } |
42 | inbound?: { |
43 | ani_number_format?: '+E.164' | 'E.164' | '+E.164-national' | 'E.164-national' |
44 | dnis_number_format?: '+e164' | 'e164' | 'national' | 'sip_username' |
45 | codecs?: string[] |
46 | default_routing_method?: 'sequential' | 'round-robin' |
47 | channel_limit?: number |
48 | generate_ringback_tone?: false | true |
49 | isup_headers_enabled?: false | true |
50 | prack_enabled?: false | true |
51 | privacy_zone_enabled?: false | true |
52 | sip_compact_headers_enabled?: false | true |
53 | sip_region?: 'US' | 'Europe' | 'Australia' |
54 | sip_subdomain?: string |
55 | sip_subdomain_receive_settings?: 'only_my_connections' | 'from_anyone' |
56 | timeout_1xx_secs?: number |
57 | timeout_2xx_secs?: number |
58 | shaken_stir_enabled?: false | true |
59 | } |
60 | outbound?: { |
61 | call_parking_enabled?: false | true |
62 | ani_override?: string |
63 | ani_override_type?: 'always' | 'normal' | 'emergency' |
64 | channel_limit?: number |
65 | instant_ringback_enabled?: false | true |
66 | generate_ringback_tone?: false | true |
67 | localization?: string |
68 | t38_reinvite_source?: |
69 | | 'telnyx' |
70 | | 'customer' |
71 | | 'disabled' |
72 | | 'passthru' |
73 | | 'caller-passthru' |
74 | | 'callee-passthru' |
75 | tech_prefix?: string |
76 | ip_authentication_method?: 'tech-prefixp-charge-info' | 'apiKey' |
77 | ip_authentication_apiKey?: string |
78 | outbound_voice_profile_id?: string |
79 | } |
80 | } |
81 | ) { |
82 | const url = new URL(`https://api.telnyx.com/v2/ip_connections`) |
83 |
|
84 | const response = await fetch(url, { |
85 | method: 'POST', |
86 | headers: { |
87 | 'Content-Type': 'application/json', |
88 | Authorization: 'Bearer ' + auth.apiKey |
89 | }, |
90 | body: JSON.stringify(body) |
91 | }) |
92 | if (!response.ok) { |
93 | const text = await response.text() |
94 | throw new Error(`${response.status} ${text}`) |
95 | } |
96 | return await response.json() |
97 | } |
98 |
|