1 | |
2 | type Telnyx = { |
3 | apiKey: string |
4 | } |
5 | |
6 | * Update a phone number with voice settings |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Telnyx, |
11 | id: string, |
12 | body: { |
13 | tech_prefix_enabled?: false | true |
14 | translated_number?: string |
15 | caller_id_name_enabled?: false | true |
16 | call_forwarding?: { |
17 | call_forwarding_enabled?: false | true |
18 | forwards_to?: string |
19 | forwarding_type?: 'always' | 'on_failure' |
20 | } |
21 | cnam_listing?: { |
22 | cnam_listing_enabled?: false | true |
23 | cnam_listing_details?: string |
24 | } |
25 | usage_payment_method?: 'pay-per-minute' | 'channel' |
26 | media_features?: { |
27 | rtp_auto_adjust_enabled?: false | true |
28 | accept_any_rtp_packets_enabled?: false | true |
29 | t38_fax_gateway_enabled?: false | true |
30 | } |
31 | call_recording?: { |
32 | inbound_call_recording_enabled?: false | true |
33 | inbound_call_recording_format?: 'wav' | 'mp3' |
34 | inbound_call_recording_channels?: 'single' | 'dual' |
35 | } |
36 | inbound_call_screening?: 'disabled' | 'reject_calls' | 'flag_calls' |
37 | } |
38 | ) { |
39 | const url = new URL(`https://api.telnyx.com/v2/phone_numbers/${id}/voice`) |
40 |
|
41 | const response = await fetch(url, { |
42 | method: 'PATCH', |
43 | headers: { |
44 | 'Content-Type': 'application/json', |
45 | Authorization: 'Bearer ' + auth.apiKey |
46 | }, |
47 | body: JSON.stringify(body) |
48 | }) |
49 | if (!response.ok) { |
50 | const text = await response.text() |
51 | throw new Error(`${response.status} ${text}`) |
52 | } |
53 | return await response.json() |
54 | } |
55 |
|