$npx -y skills add team-telnyx/ai --skill telnyx-numbers-services-rubyConfigure voicemail, voice channels, and emergency (E911) services for your phone numbers. This skill provides Ruby SDK examples.
| 1 | <!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. --> |
| 2 | |
| 3 | # Telnyx Numbers Services - Ruby |
| 4 | |
| 5 | ## Installation |
| 6 | |
| 7 | ```bash |
| 8 | gem install telnyx |
| 9 | ``` |
| 10 | |
| 11 | ## Setup |
| 12 | |
| 13 | ```ruby |
| 14 | require "telnyx" |
| 15 | |
| 16 | client = Telnyx::Client.new( |
| 17 | api_key: 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 | ```ruby |
| 29 | begin |
| 30 | result = client.messages.send_(to: "+13125550001", from: "+13125550002", text: "Hello") |
| 31 | rescue Telnyx::Errors::APIConnectionError |
| 32 | puts "Network error — check connectivity and retry" |
| 33 | rescue Telnyx::Errors::RateLimitError |
| 34 | # 429: rate limited — wait and retry with exponential backoff |
| 35 | sleep(1) # Check Retry-After header for actual delay |
| 36 | rescue Telnyx::Errors::APIStatusError => e |
| 37 | puts "API error #{e.status}: #{e.message}" |
| 38 | if e.status == 422 |
| 39 | puts "Validation error — check required fields and formats" |
| 40 | end |
| 41 | end |
| 42 | ``` |
| 43 | |
| 44 | Common error codes: `401` invalid API key, `403` insufficient permissions, |
| 45 | `404` resource not found, `422` validation error (check field formats), |
| 46 | `429` rate limited (retry with exponential backoff). |
| 47 | |
| 48 | ## Important Notes |
| 49 | |
| 50 | - **Pagination:** Use `.auto_paging_each` for automatic iteration: `page.auto_paging_each { |item| puts item.id }`. |
| 51 | |
| 52 | ## List your voice channels for non-US zones |
| 53 | |
| 54 | Returns the non-US voice channels for your account. voice channels allow you to use Channel Billing for calls to your Telnyx phone numbers. Please check the Telnyx Support Articles section for full information and examples of how to utilize Channel Billing. |
| 55 | |
| 56 | `GET /channel_zones` |
| 57 | |
| 58 | ```ruby |
| 59 | page = client.channel_zones.list |
| 60 | |
| 61 | puts(page) |
| 62 | ``` |
| 63 | |
| 64 | Returns: `channels` (int64), `countries` (array[string]), `created_at` (string), `id` (string), `name` (string), `record_type` (enum: channel_zone), `updated_at` (string) |
| 65 | |
| 66 | ## Update voice channels for non-US Zones |
| 67 | |
| 68 | Update the number of Voice Channels for the Non-US Zones. This allows your account to handle multiple simultaneous inbound calls to Non-US numbers. Use this endpoint to increase or decrease your capacity based on expected call volume. |
| 69 | |
| 70 | `PUT /channel_zones/{channel_zone_id}` — Required: `channels` |
| 71 | |
| 72 | ```ruby |
| 73 | channel_zone = client.channel_zones.update("channel_zone_id", channels: 0) |
| 74 | |
| 75 | puts(channel_zone) |
| 76 | ``` |
| 77 | |
| 78 | Returns: `channels` (int64), `countries` (array[string]), `created_at` (string), `id` (string), `name` (string), `record_type` (enum: channel_zone), `updated_at` (string) |
| 79 | |
| 80 | ## List dynamic emergency addresses |
| 81 | |
| 82 | Returns the dynamic emergency addresses according to filters |
| 83 | |
| 84 | `GET /dynamic_emergency_addresses` |
| 85 | |
| 86 | ```ruby |
| 87 | page = client.dynamic_emergency_addresses.list |
| 88 | |
| 89 | puts(page) |
| 90 | ``` |
| 91 | |
| 92 | Returns: `administrative_area` (string), `country_code` (enum: US, CA, PR), `created_at` (string), `extended_address` (string), `house_number` (string), `house_suffix` (string), `id` (string), `locality` (string), `postal_code` (string), `record_type` (string), `sip_geolocation_id` (string), `status` (enum: pending, activated, rejected), `street_name` (string), `street_post_directional` (string), `street_pre_directional` (string), `street_suffix` (string), `updated_at` (string) |
| 93 | |
| 94 | ## Create a dynamic emergency address. |
| 95 | |
| 96 | Creates a dynamic emergency address. |
| 97 | |
| 98 | `POST /dynamic_emergency_addresses` — Required: `house_number`, `street_name`, `locality`, `administrative_area`, `postal_code`, `country_code` |
| 99 | |
| 100 | Optional: `created_at` (string), `extended_address` (string), `house_suffix` (string), `id` (string), `record_type` (string), `sip_geolocation_id` (string), `status` (enum: pending, activated, rejected), `street_post_directional` (string), `street_pre_directional` (string), `street_suffix` (string), `updated_at` (string) |
| 101 | |
| 102 | ```ruby |
| 103 | dynamic_emergency_address = client.dynamic_emergency_addresses.create( |
| 104 | administrative_area: "TX", |
| 105 | country_code: :US, |
| 106 | house_number: "600", |
| 107 | locality: "Austin", |
| 108 | postal_code: "78701", |
| 109 | street_name: "Congress" |
| 110 | ) |
| 111 | |
| 112 | puts(dynamic_emergency_address) |
| 113 | ``` |
| 114 | |
| 115 | Returns: `administrative_area` (string), `country_code` (enum: US, CA, PR), `created_at` (string), `extended_address` (string), `house_number` (string), `house_suffix` (string), `id` (string), `locality` (string), `postal_code` (string), `record_type` (string), `sip_geolocation_id` (string), `status` (enum: pending, activated, rejected), `street_name` (string), `street_post_directional` (string), `street_pre_directional` (string), `street_suffix` (string), `updated_at` (string) |
| 116 | |
| 117 | ## Get a dynamic emergency address |
| 118 | |
| 119 | Returns the dynamic emergency address based on the ID p |