1 | |
2 | type Telnyx = { |
3 | apiKey: string |
4 | } |
5 | |
6 | * Dial |
7 | * Dial a number or SIP URI from a given connection. |
8 | */ |
9 | export async function main( |
10 | auth: Telnyx, |
11 | body: { |
12 | to: string | string[] |
13 | from: string |
14 | from_display_name?: string |
15 | connection_id: string |
16 | audio_url?: string |
17 | media_name?: string |
18 | preferred_codecs?: string |
19 | timeout_secs?: number |
20 | time_limit_secs?: number |
21 | answering_machine_detection?: |
22 | | 'premium' |
23 | | 'detect' |
24 | | 'detect_beep' |
25 | | 'detect_words' |
26 | | 'greeting_end' |
27 | | 'disabled' |
28 | answering_machine_detection_config?: { |
29 | total_analysis_time_millis?: number |
30 | after_greeting_silence_millis?: number |
31 | between_words_silence_millis?: number |
32 | greeting_duration_millis?: number |
33 | initial_silence_millis?: number |
34 | maximum_number_of_words?: number |
35 | maximum_word_length_millis?: number |
36 | silence_threshold?: number |
37 | greeting_total_analysis_time_millis?: number |
38 | greeting_silence_duration_millis?: number |
39 | } |
40 | conference_config?: { |
41 | id?: string |
42 | conference_name?: string |
43 | early_media?: false | true |
44 | end_conference_on_exit?: false | true |
45 | soft_end_conference_on_exit?: false | true |
46 | hold?: false | true |
47 | hold_audio_url?: string |
48 | hold_media_name?: string |
49 | mute?: false | true |
50 | start_conference_on_enter?: false | true |
51 | start_conference_on_create?: false | true |
52 | supervisor_role?: 'barge' | 'monitor' | 'none' | 'whisper' |
53 | whisper_call_control_ids?: string[] |
54 | beep_enabled?: 'always' | 'never' | 'on_enter' | 'on_exit' |
55 | } |
56 | custom_headers?: { name: string; value: string }[] |
57 | billing_group_id?: string |
58 | client_state?: string |
59 | command_id?: string |
60 | link_to?: string |
61 | media_encryption?: 'disabled' | 'SRTP' |
62 | sip_auth_username?: string |
63 | sip_auth_password?: string |
64 | sip_headers?: { name: 'User-to-User'; value: string }[] |
65 | sip_transport_protocol?: 'UDP' | 'TCP' | 'TLS' |
66 | sound_modifications?: { |
67 | pitch?: number |
68 | semitone?: number |
69 | octaves?: number |
70 | track?: string |
71 | } |
72 | stream_url?: string |
73 | stream_track?: 'inbound_track' | 'outbound_track' | 'both_tracks' |
74 | stream_bidirectional_mode?: 'mp3' | 'rtp' |
75 | stream_bidirectional_codec?: 'PCMU' | 'PCMA' | 'G722' |
76 | stream_bidirectional_target_legs?: 'both' | 'self' | 'opposite' |
77 | send_silence_when_idle?: false | true |
78 | webhook_url?: string |
79 | webhook_url_method?: 'POST' | 'GET' |
80 | record?: 'record-from-answer' |
81 | record_channels?: 'single' | 'dual' |
82 | record_format?: 'mp3' | 'wav' |
83 | record_max_length?: number |
84 | record_timeout_secs?: number |
85 | record_track?: 'both' | 'inbound' | 'outbound' |
86 | record_trim?: 'trim-silence' |
87 | record_custom_file_name?: string |
88 | enable_dialogflow?: false | true |
89 | dialogflow_config?: { |
90 | analyze_sentiment?: false | true |
91 | partial_automated_agent_reply?: false | true |
92 | } |
93 | transcription?: false | true |
94 | transcription_config?: { |
95 | transcription_engine?: 'A' | 'B' |
96 | language?: |
97 | | 'af' |
98 | | 'sq' |
99 | | 'am' |
100 | | 'ar' |
101 | | 'hy' |
102 | | 'az' |
103 | | 'eu' |
104 | | 'bn' |
105 | | 'bs' |
106 | | 'bg' |
107 | | 'my' |
108 | | 'ca' |
109 | | 'yue' |
110 | | 'zh' |
111 | | 'hr' |
112 | | 'cs' |
113 | | 'da' |
114 | | 'nl' |
115 | | 'en' |
116 | | 'et' |
117 | | 'fil' |
118 | | 'fi' |
119 | | 'fr' |
120 | | 'gl' |
121 | | 'ka' |
122 | | 'de' |
123 | | 'el' |
124 | | 'gu' |
125 | | 'iw' |
126 | | 'hi' |
127 | | 'hu' |
128 | | 'is' |
129 | | 'id' |
130 | | 'it' |
131 | | 'ja' |
132 | | 'jv' |
133 | | 'kn' |
134 | | 'kk' |
135 | | 'km' |
136 | | 'ko' |
137 | | 'lo' |
138 | | 'lv' |
139 | | 'lt' |
140 | | 'mk' |
141 | | 'ms' |
142 | | 'ml' |
143 | | 'mr' |
144 | | 'mn' |
145 | | 'ne' |
146 | | 'no' |
147 | | 'fa' |
148 | | 'pl' |
149 | | 'pt' |
150 | | 'pa' |
151 | | 'ro' |
152 | | 'ru' |
153 | | 'rw' |
154 | | 'sr' |
155 | | 'si' |
156 | | 'sk' |
157 | | 'sl' |
158 | | 'ss' |
159 | | 'st' |
160 | | 'es' |
161 | | 'su' |
162 | | 'sw' |
163 | | 'sv' |
164 | | 'ta' |
165 | | 'te' |
166 | | 'th' |
167 | | 'tn' |
168 | | 'tr' |
169 | | 'ts' |
170 | | 'uk' |
171 | | 'ur' |
172 | | 'uz' |
173 | | 've' |
174 | | 'vi' |
175 | | 'xh' |
176 | | 'zu' |
177 | | 'he' |
178 | | 'la' |
179 | | 'mi' |
180 | | 'cy' |
181 | | 'br' |
182 | | 'sn' |
183 | | 'yo' |
184 | | 'so' |
185 | | 'oc' |
186 | | 'be' |
187 | | 'tg' |
188 | | 'sd' |
189 | | 'yi' |
190 | | 'fo' |
191 | | 'ht' |
192 | | 'ps' |
193 | | 'tk' |
194 | | 'nn' |
195 | | 'mt' |
196 | | 'sa' |
197 | | 'lb' |
198 | | 'bo' |
199 | | 'tl' |
200 | | 'mg' |
201 | | 'as' |
202 | | 'tt' |
203 | | 'haw' |
204 | | 'ln' |
205 | | 'ha' |
206 | | 'ba' |
207 | | 'jw' |
208 | | 'auto_detect' |
209 | interim_results?: false | true |
210 | enable_speaker_diarization?: false | true |
211 | min_speaker_count?: number |
212 | max_speaker_count?: number |
213 | client_state?: string |
214 | transcription_tracks?: string |
215 | command_id?: string |
216 | } |
217 | } |
218 | ) { |
219 | const url = new URL(`https://api.telnyx.com/v2/calls`) |
220 |
|
221 | const response = await fetch(url, { |
222 | method: 'POST', |
223 | headers: { |
224 | 'Content-Type': 'application/json', |
225 | Authorization: 'Bearer ' + auth.apiKey |
226 | }, |
227 | body: JSON.stringify(body) |
228 | }) |
229 | if (!response.ok) { |
230 | const text = await response.text() |
231 | throw new Error(`${response.status} ${text}`) |
232 | } |
233 | return await response.json() |
234 | } |
235 |
|