$npx -y skills add team-telnyx/ai --skill telnyx-messaging-hosted-rubySet up hosted SMS numbers, toll-free verification, and RCS messaging. Use when migrating numbers or enabling rich messaging features. This skill provides Ruby SDK examples.
| 1 | <!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. --> |
| 2 | |
| 3 | # Telnyx Messaging Hosted - 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 | - **Phone numbers** must be in E.164 format (e.g., `+13125550001`). Include the `+` prefix and country code. No spaces, dashes, or parentheses. |
| 51 | - **Pagination:** Use `.auto_paging_each` for automatic iteration: `page.auto_paging_each { |item| puts item.id }`. |
| 52 | |
| 53 | ## Send an RCS message |
| 54 | |
| 55 | `POST /messages/rcs` — Required: `agent_id`, `to`, `messaging_profile_id`, `agent_message` |
| 56 | |
| 57 | Optional: `mms_fallback` (object), `sms_fallback` (object), `type` (enum: RCS), `webhook_url` (url) |
| 58 | |
| 59 | ```ruby |
| 60 | response = client.messages.rcs.send_( |
| 61 | agent_id: "Agent007", |
| 62 | agent_message: {}, |
| 63 | messaging_profile_id: "550e8400-e29b-41d4-a716-446655440000", |
| 64 | to: "+13125551234" |
| 65 | ) |
| 66 | |
| 67 | puts(response) |
| 68 | ``` |
| 69 | |
| 70 | Returns: `body` (object), `direction` (string), `encoding` (string), `from` (object), `id` (string), `messaging_profile_id` (string), `organization_id` (string), `received_at` (date-time), `record_type` (string), `to` (array[object]), `type` (string), `wait_seconds` (float) |
| 71 | |
| 72 | ## Generate RCS deeplink |
| 73 | |
| 74 | Generate a deeplink URL that can be used to start an RCS conversation with a specific agent. |
| 75 | |
| 76 | `GET /messages/rcs/deeplinks/{agent_id}` |
| 77 | |
| 78 | ```ruby |
| 79 | response = client.messages.rcs.generate_deeplink("agent_id") |
| 80 | |
| 81 | puts(response) |
| 82 | ``` |
| 83 | |
| 84 | Returns: `url` (string) |
| 85 | |
| 86 | ## List all RCS agents |
| 87 | |
| 88 | `GET /messaging/rcs/agents` |
| 89 | |
| 90 | ```ruby |
| 91 | page = client.messaging.rcs.agents.list |
| 92 | |
| 93 | puts(page) |
| 94 | ``` |
| 95 | |
| 96 | Returns: `agent_id` (string), `agent_name` (string), `created_at` (date-time), `enabled` (boolean), `profile_id` (uuid), `updated_at` (date-time), `user_id` (string), `webhook_failover_url` (url), `webhook_url` (url) |
| 97 | |
| 98 | ## Retrieve an RCS agent |
| 99 | |
| 100 | `GET /messaging/rcs/agents/{id}` |
| 101 | |
| 102 | ```ruby |
| 103 | rcs_agent_response = client.messaging.rcs.agents.retrieve("550e8400-e29b-41d4-a716-446655440000") |
| 104 | |
| 105 | puts(rcs_agent_response) |
| 106 | ``` |
| 107 | |
| 108 | Returns: `agent_id` (string), `agent_name` (string), `created_at` (date-time), `enabled` (boolean), `profile_id` (uuid), `updated_at` (date-time), `user_id` (string), `webhook_failover_url` (url), `webhook_url` (url) |
| 109 | |
| 110 | ## Modify an RCS agent |
| 111 | |
| 112 | `PATCH /messaging/rcs/agents/{id}` |
| 113 | |
| 114 | Optional: `profile_id` (uuid), `webhook_failover_url` (url), `webhook_url` (url) |
| 115 | |
| 116 | ```ruby |
| 117 | rcs_agent_response = client.messaging.rcs.agents.update("550e8400-e29b-41d4-a716-446655440000") |
| 118 | |
| 119 | puts(rcs_agent_response) |
| 120 | ``` |
| 121 | |
| 122 | Returns: `agent_id` (string), `agent_name` (string), `created_at` (date-time), `enabled` (boolean), `profile_id` (uuid), `updated_at` (date-time), `user_id` (string), `webhook_failover_url` (url), `webhook_url` (url) |
| 123 | |
| 124 | ## Check RCS capabilities (batch) |
| 125 | |
| 126 | `POST /messaging/rcs/bulk_capabilities` — Required: `agent_id`, `phone_numbers` |
| 127 | |
| 128 | ```ruby |
| 129 | response = client.messaging.rcs.list_bulk_capabilities(agent_id: "TestAgent", phone_numbers: ["+13125551234"]) |
| 130 | |
| 131 | puts(response) |
| 132 | ``` |
| 133 | |
| 134 | Returns: `agent_id` (string), `agent_name` (string), `features` (array[string]), `phone_number` (string), `record_type` (enum: rcs.capabilities) |
| 135 | |
| 136 | ## Check RCS capabilities |
| 137 | |
| 138 | `GET /messaging/rcs/capabilities/{agent_id}/{phone_number}` |
| 139 | |
| 140 | ```ruby |
| 141 | response = client.messaging.rcs.retrieve_capabilities("phone_number", agent_id: "550e8400-e29b-41d4-a716-446655440000") |
| 142 | |
| 143 | puts(response) |
| 144 | ``` |
| 145 | |
| 146 | Returns: `agent_id` (string), `agent_name` (string), `features` (array[string]), `phone_number` (string), `record_type` (enum: rcs.capabilities) |
| 147 | |
| 148 | ## Add RCS test number |
| 149 | |
| 150 | Adds a test phone number to an RCS agent fo |