$npx -y skills add team-telnyx/ai --skill telnyx-numbers-config-javascriptConfigure phone number settings including caller ID, call forwarding, messaging enablement, and connection assignments. This skill provides JavaScript SDK examples.
| 1 | <!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. --> |
| 2 | |
| 3 | # Telnyx Numbers Config - JavaScript |
| 4 | |
| 5 | ## Installation |
| 6 | |
| 7 | ```bash |
| 8 | npm install telnyx |
| 9 | ``` |
| 10 | |
| 11 | ## Setup |
| 12 | |
| 13 | ```javascript |
| 14 | import Telnyx from 'telnyx'; |
| 15 | |
| 16 | const client = new Telnyx({ |
| 17 | apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted |
| 18 | }); |
| 19 | ``` |
| 20 | |
| 21 | All examples below assume `client` is already initialized as shown above. |
| 22 | |
| 23 | ## Error Handling |
| 24 | |
| 25 | All API calls can fail with network errors, rate limits (429), validation errors (422), |
| 26 | or authentication errors (401). Always handle errors in production code: |
| 27 | |
| 28 | ```javascript |
| 29 | try { |
| 30 | const result = await client.messages.send({ to: '+13125550001', from: '+13125550002', text: 'Hello' }); |
| 31 | } catch (err) { |
| 32 | if (err instanceof Telnyx.APIConnectionError) { |
| 33 | console.error('Network error — check connectivity and retry'); |
| 34 | } else if (err instanceof Telnyx.RateLimitError) { |
| 35 | // 429: rate limited — wait and retry with exponential backoff |
| 36 | const retryAfter = err.headers?.['retry-after'] || 1; |
| 37 | await new Promise(r => setTimeout(r, retryAfter * 1000)); |
| 38 | } else if (err instanceof Telnyx.APIError) { |
| 39 | console.error(`API error ${err.status}: ${err.message}`); |
| 40 | if (err.status === 422) { |
| 41 | console.error('Validation error — check required fields and formats'); |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | ``` |
| 46 | |
| 47 | Common error codes: `401` invalid API key, `403` insufficient permissions, |
| 48 | `404` resource not found, `422` validation error (check field formats), |
| 49 | `429` rate limited (retry with exponential backoff). |
| 50 | |
| 51 | ## Important Notes |
| 52 | |
| 53 | - **Phone numbers** must be in E.164 format (e.g., `+13125550001`). Include the `+` prefix and country code. No spaces, dashes, or parentheses. |
| 54 | - **Pagination:** List methods return an auto-paginating iterator. Use `for await (const item of result) { ... }` to iterate through all pages automatically. |
| 55 | |
| 56 | ## Bulk update phone number profiles |
| 57 | |
| 58 | `POST /messaging_numbers_bulk_updates` — Required: `messaging_profile_id`, `numbers` |
| 59 | |
| 60 | Optional: `assign_only` (boolean) |
| 61 | |
| 62 | ```javascript |
| 63 | const messagingNumbersBulkUpdate = await client.messagingNumbersBulkUpdates.create({ |
| 64 | messaging_profile_id: '00000000-0000-0000-0000-000000000000', |
| 65 | numbers: ['+18880000000', '+18880000001', '+18880000002'], |
| 66 | }); |
| 67 | |
| 68 | console.log(messagingNumbersBulkUpdate.data); |
| 69 | ``` |
| 70 | |
| 71 | Returns: `failed` (array[string]), `order_id` (uuid), `pending` (array[string]), `record_type` (enum: messaging_numbers_bulk_update), `success` (array[string]) |
| 72 | |
| 73 | ## Retrieve bulk update status |
| 74 | |
| 75 | `GET /messaging_numbers_bulk_updates/{order_id}` |
| 76 | |
| 77 | ```javascript |
| 78 | const messagingNumbersBulkUpdate = await client.messagingNumbersBulkUpdates.retrieve('order_id'); |
| 79 | |
| 80 | console.log(messagingNumbersBulkUpdate.data); |
| 81 | ``` |
| 82 | |
| 83 | Returns: `failed` (array[string]), `order_id` (uuid), `pending` (array[string]), `record_type` (enum: messaging_numbers_bulk_update), `success` (array[string]) |
| 84 | |
| 85 | ## List mobile phone numbers with messaging settings |
| 86 | |
| 87 | `GET /mobile_phone_numbers/messaging` |
| 88 | |
| 89 | ```javascript |
| 90 | // Automatically fetches more pages as needed. |
| 91 | for await (const messagingListResponse of client.mobilePhoneNumbers.messaging.list()) { |
| 92 | console.log(messagingListResponse.id); |
| 93 | } |
| 94 | ``` |
| 95 | |
| 96 | Returns: `country_code` (string), `created_at` (date-time), `features` (object), `id` (string), `messaging_product` (string), `messaging_profile_id` (string | null), `organization_id` (string), `phone_number` (string), `record_type` (enum: messaging_phone_number, messaging_settings), `tags` (array[string]), `traffic_type` (string), `type` (enum: longcode), `updated_at` (date-time) |
| 97 | |
| 98 | ## Retrieve a mobile phone number with messaging settings |
| 99 | |
| 100 | `GET /mobile_phone_numbers/{id}/messaging` |
| 101 | |
| 102 | ```javascript |
| 103 | const messaging = await client.mobilePhoneNumbers.messaging.retrieve('550e8400-e29b-41d4-a716-446655440000'); |
| 104 | |
| 105 | console.log(messaging.data); |
| 106 | ``` |
| 107 | |
| 108 | Returns: `country_code` (string), `created_at` (date-time), `features` (object), `id` (string), `messaging_product` (string), `messaging_profile_id` (string | null), `organization_id` (string), `phone_number` (string), `record_type` (enum: messaging_phone_number, messaging_settings), `tags` (array[string]), `traffic_type` (string), `type` (enum: longcode), `updated_at` (date-time) |
| 109 | |
| 110 | ## List phone numbers |
| 111 | |
| 112 | `GET /phone_numbers` |
| 113 | |
| 114 | ```javascript |
| 115 | // Automatically fetches more pages as needed. |
| 116 | for await (const phoneNumberDetailed of client.phoneNumbers.list()) { |
| 117 | console.log(phoneNumberDetailed.id); |
| 118 | } |
| 119 | ``` |
| 120 | |
| 121 | Returns: `billing_group_id` (string | null), `call_forwarding_enabled` (boolean), `call_recording_enabled` (boolean), `caller_id_name_enabled` (boolean), `cnam_listing_enabled` (boolean), `connection_id` (string | null), `connection_name` (string | null), |