$npx -y skills add team-telnyx/ai --skill telnyx-messaging-rubySend and receive SMS/MMS, handle opt-outs and delivery webhooks. Use for notifications, 2FA, or messaging apps.
| 1 | <!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. --> |
| 2 | |
| 3 | # Telnyx Messaging - 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 | response = client.messages.send_(to: "+18445550001", from: "+18005550101", text: "Hello from Telnyx!") |
| 30 | puts(response) |
| 31 | ``` |
| 32 | |
| 33 | Common error codes: `401` invalid API key, `403` insufficient permissions, |
| 34 | `404` resource not found, `422` validation error (check field formats), |
| 35 | `429` rate limited (retry with exponential backoff). |
| 36 | |
| 37 | ## Important Notes |
| 38 | |
| 39 | - **Phone numbers** must be in E.164 format (e.g., `+13125550001`). Include the `+` prefix and country code. No spaces, dashes, or parentheses. |
| 40 | - **Pagination:** Use `.auto_paging_each` for automatic iteration: `page.auto_paging_each { |item| puts item.id }`. |
| 41 | |
| 42 | ## Operational Caveats |
| 43 | |
| 44 | - The sending number must already be assigned to the correct messaging profile before you send traffic from it. |
| 45 | - US A2P long-code traffic must complete 10DLC registration before production sending or carriers will block or heavily filter messages. |
| 46 | - Delivery webhooks are asynchronous. Treat the send response as acceptance of the request, not final carrier delivery. |
| 47 | |
| 48 | ## Reference Use Rules |
| 49 | |
| 50 | Do not invent Telnyx parameters, enums, response fields, or webhook fields. |
| 51 | |
| 52 | - If the parameter, enum, or response field you need is not shown inline in this skill, read [references/api-details.md](references/api-details.md) before writing code. |
| 53 | - Before using any operation in `## Additional Operations`, read [the optional-parameters section](references/api-details.md#optional-parameters) and [the response-schemas section](references/api-details.md#response-schemas). |
| 54 | - Before reading or matching webhook fields beyond the inline examples, read [the webhook payload reference](references/api-details.md#webhook-payload-fields). |
| 55 | |
| 56 | ## Core Tasks |
| 57 | |
| 58 | ### Send an SMS |
| 59 | |
| 60 | Primary outbound messaging flow. Agents need exact request fields and delivery-related response fields. |
| 61 | |
| 62 | `client.messages.send_()` — `POST /messages` |
| 63 | |
| 64 | | Parameter | Type | Required | Description | |
| 65 | |-----------|------|----------|-------------| |
| 66 | | `to` | string (E.164) | Yes | Receiving address (+E.164 formatted phone number or short co... | |
| 67 | | `from` | string (E.164) | Yes | Sending address (+E.164 formatted phone number, alphanumeric... | |
| 68 | | `text` | string | Yes | Message body (i.e., content) as a non-empty string. | |
| 69 | | `messaging_profile_id` | string (UUID) | No | Unique identifier for a messaging profile. | |
| 70 | | `media_urls` | array[string] | No | A list of media URLs. | |
| 71 | | `webhook_url` | string (URL) | No | The URL where webhooks related to this message will be sent. | |
| 72 | | ... | | | +7 optional params in [references/api-details.md](references/api-details.md) | |
| 73 | |
| 74 | ```ruby |
| 75 | response = client.messages.send_(to: "+18445550001", from: "+18005550101", text: "Hello from Telnyx!") |
| 76 | puts(response) |
| 77 | ``` |
| 78 | |
| 79 | Primary response fields: |
| 80 | - `response.data.id` |
| 81 | - `response.data.to` |
| 82 | - `response.data.from` |
| 83 | - `response.data.text` |
| 84 | - `response.data.sent_at` |
| 85 | - `response.data.errors` |
| 86 | |
| 87 | ### Send an SMS with an alphanumeric sender ID |
| 88 | |
| 89 | Common sender variant that requires different request shape. |
| 90 | |
| 91 | `client.messages.send_with_alphanumeric_sender()` — `POST /messages/alphanumeric_sender_id` |
| 92 | |
| 93 | | Parameter | Type | Required | Description | |
| 94 | |-----------|------|----------|-------------| |
| 95 | | `from` | string (E.164) | Yes | A valid alphanumeric sender ID on the user's account. | |
| 96 | | `to` | string (E.164) | Yes | Receiving address (+E.164 formatted phone number or short co... | |
| 97 | | `text` | string | Yes | The message body. | |
| 98 | | `messaging_profile_id` | string (UUID) | Yes | The messaging profile ID to use. | |
| 99 | | `webhook_url` | string (URL) | No | Callback URL for delivery status updates. | |
| 100 | | `webhook_failover_url` | string (URL) | No | Failover callback URL for delivery status updates. | |
| 101 | | `use_profile_webhooks` | boolean | No | If true, use the messaging profile's webhook settings. | |
| 102 | |
| 103 | ```ruby |
| 104 | response = client.messages.send_with_alphanumeric_sender( |
| 105 | from: "MyCompany", |
| 106 | messaging_profile_id: "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", |
| 107 | text: "Hello from Telnyx!", |
| 108 | to: "+13125550001" |
| 109 | ) |
| 110 | |
| 111 | puts(response) |
| 112 | ``` |
| 113 | |
| 114 | Primary response fields: |
| 115 | - `response.data.id` |
| 116 | - `response.data.to` |
| 117 | - `response.data.from` |
| 118 | - `response.data.text` |
| 119 | - `response.data.sent_at` |
| 120 | - `response.data.errors` |
| 121 | |
| 122 | --- |
| 123 | |
| 124 | ### |