1 | |
2 | type Telnyx = { |
3 | apiKey: string |
4 | } |
5 | |
6 | * Update a batch of numbers |
7 | * Creates a new background job to update a batch of numbers. At most one thousand numbers can be updated per API call. At least one of the updateable fields must be submitted. |
8 | */ |
9 | export async function main( |
10 | auth: Telnyx, |
11 | filter_has_bundle_: string | undefined, |
12 | filter_tag_: string | undefined, |
13 | filter_connection_id_: string | undefined, |
14 | filter_phone_number_: string | undefined, |
15 | filter_status_: |
16 | | 'purchase_pending' |
17 | | 'purchase_failed' |
18 | | 'port_pending' |
19 | | 'active' |
20 | | 'deleted' |
21 | | 'port_failed' |
22 | | 'emergency_only' |
23 | | 'ported_out' |
24 | | 'port_out_pending' |
25 | | undefined, |
26 | filter_voice_connection_name__contains_: string | undefined, |
27 | filter_voice_usage_payment_method_: 'pay-per-minute' | 'channel' | undefined, |
28 | filter_billing_group_id_: string | undefined, |
29 | filter_emergency_address_id_: string | undefined, |
30 | filter_customer_reference_: string | undefined, |
31 | body: { |
32 | phone_numbers: string[] |
33 | tags?: string[] |
34 | external_pin?: string |
35 | customer_reference?: string |
36 | connection_id?: string |
37 | billing_group_id?: string |
38 | hd_voice_enabled?: false | true |
39 | voice?: { |
40 | tech_prefix_enabled?: false | true |
41 | translated_number?: string |
42 | caller_id_name_enabled?: false | true |
43 | call_forwarding?: { |
44 | call_forwarding_enabled?: false | true |
45 | forwards_to?: string |
46 | forwarding_type?: 'always' | 'on_failure' |
47 | } |
48 | cnam_listing?: { |
49 | cnam_listing_enabled?: false | true |
50 | cnam_listing_details?: string |
51 | } |
52 | usage_payment_method?: 'pay-per-minute' | 'channel' |
53 | media_features?: { |
54 | rtp_auto_adjust_enabled?: false | true |
55 | accept_any_rtp_packets_enabled?: false | true |
56 | t38_fax_gateway_enabled?: false | true |
57 | } |
58 | call_recording?: { |
59 | inbound_call_recording_enabled?: false | true |
60 | inbound_call_recording_format?: 'wav' | 'mp3' |
61 | inbound_call_recording_channels?: 'single' | 'dual' |
62 | } |
63 | inbound_call_screening?: 'disabled' | 'reject_calls' | 'flag_calls' |
64 | } |
65 | } |
66 | ) { |
67 | const url = new URL(`https://api.telnyx.com/v2/phone_numbers/jobs/update_phone_numbers`) |
68 | for (const [k, v] of [ |
69 | ['filter[has_bundle]', filter_has_bundle_], |
70 | ['filter[tag]', filter_tag_], |
71 | ['filter[connection_id]', filter_connection_id_], |
72 | ['filter[phone_number]', filter_phone_number_], |
73 | ['filter[status]', filter_status_], |
74 | ['filter[voice.connection_name][contains]', filter_voice_connection_name__contains_], |
75 | ['filter[voice.usage_payment_method]', filter_voice_usage_payment_method_], |
76 | ['filter[billing_group_id]', filter_billing_group_id_], |
77 | ['filter[emergency_address_id]', filter_emergency_address_id_], |
78 | ['filter[customer_reference]', filter_customer_reference_] |
79 | ]) { |
80 | if (v !== undefined && v !== '' && k !== undefined) { |
81 | url.searchParams.append(k, v) |
82 | } |
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 |
|