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