$npx -y skills add team-telnyx/ai --skill telnyx-messaging-profiles-rubyCreate and manage messaging profiles with number pools, sticky sender, and geomatch features. Configure short codes for high-volume messaging. This skill provides Ruby SDK examples.
| 1 | <!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. --> |
| 2 | |
| 3 | # Telnyx Messaging Profiles - 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 messaging profiles |
| 53 | |
| 54 | `GET /messaging_profiles` |
| 55 | |
| 56 | ```ruby |
| 57 | page = client.messaging_profiles.list |
| 58 | |
| 59 | puts(page) |
| 60 | ``` |
| 61 | |
| 62 | Returns: `ai_assistant_id` (string | null), `alpha_sender` (string | null), `created_at` (date-time), `daily_spend_limit` (string), `daily_spend_limit_enabled` (boolean), `enabled` (boolean), `health_webhook_url` (url), `id` (uuid), `mms_fall_back_to_sms` (boolean), `mms_transcoding` (boolean), `mobile_only` (boolean), `name` (string), `number_pool_settings` (object | null), `organization_id` (string), `record_type` (enum: messaging_profile), `redaction_enabled` (boolean), `redaction_level` (integer), `resource_group_id` (string | null), `smart_encoding` (boolean), `updated_at` (date-time), `url_shortener_settings` (object | null), `v1_secret` (string), `webhook_api_version` (enum: 1, 2, 2010-04-01), `webhook_failover_url` (url), `webhook_url` (url), `whitelisted_destinations` (array[string]) |
| 63 | |
| 64 | ## Create a messaging profile |
| 65 | |
| 66 | `POST /messaging_profiles` — Required: `name`, `whitelisted_destinations` |
| 67 | |
| 68 | Optional: `ai_assistant_id` (string | null), `alpha_sender` (string | null), `daily_spend_limit` (string), `daily_spend_limit_enabled` (boolean), `enabled` (boolean), `health_webhook_url` (url), `mms_fall_back_to_sms` (boolean), `mms_transcoding` (boolean), `mobile_only` (boolean), `number_pool_settings` (object | null), `resource_group_id` (string | null), `smart_encoding` (boolean), `url_shortener_settings` (object | null), `webhook_api_version` (enum: 1, 2, 2010-04-01), `webhook_failover_url` (url), `webhook_url` (url) |
| 69 | |
| 70 | ```ruby |
| 71 | messaging_profile = client.messaging_profiles.create(name: "My name", whitelisted_destinations: ["US"]) |
| 72 | |
| 73 | puts(messaging_profile) |
| 74 | ``` |
| 75 | |
| 76 | Returns: `ai_assistant_id` (string | null), `alpha_sender` (string | null), `created_at` (date-time), `daily_spend_limit` (string), `daily_spend_limit_enabled` (boolean), `enabled` (boolean), `health_webhook_url` (url), `id` (uuid), `mms_fall_back_to_sms` (boolean), `mms_transcoding` (boolean), `mobile_only` (boolean), `name` (string), `number_pool_settings` (object | null), `organization_id` (string), `record_type` (enum: messaging_profile), `redaction_enabled` (boolean), `redaction_level` (integer), `resource_group_id` (string | null), `smart_encoding` (boolean), `updated_at` (date-time), `url_shortener_settings` (object | null), `v1_secret` (string), `webhook_api_version` (enum: 1, 2, 2010-04-01), `webhook_failover_url` (url), `webhook_url` (url), `whitelisted_destinations` (array[string]) |
| 77 | |
| 78 | ## Retrieve a messaging profile |
| 79 | |
| 80 | `GET /messaging_profiles/{id}` |
| 81 | |
| 82 | ```ruby |
| 83 | messaging_profile = client.messaging_profiles.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") |
| 84 | |
| 85 | puts(messaging_profile) |
| 86 | ``` |
| 87 | |
| 88 | Returns: `ai_assistant_id` (string | null), `alpha_sender` (string | null), `created_at` (date-time), `daily_spend_limit` (string), `daily_spend_limit_enabled` (boolean), `enabled` (boolean), `health_webhook_url` (url), `id` (uuid), `mms_fall_back_to_sms` (boolean), `mms_transcoding` (boolean), `mobile_only` (boolean), `name` (string), `number_pool_settings` (object | null), `organization_id` (string), `record_type` (enum: messaging_profile), `redaction_enabled` (boolean), `redaction_leve |