$npx -y skills add team-telnyx/ai --skill telnyx-messaging-javaSend 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 - Java |
| 4 | |
| 5 | ## Installation |
| 6 | |
| 7 | ```text |
| 8 | <!-- Maven --> |
| 9 | <dependency> |
| 10 | <groupId>com.telnyx.sdk</groupId> |
| 11 | <artifactId>telnyx</artifactId> |
| 12 | <version>6.82.0</version> |
| 13 | </dependency> |
| 14 | |
| 15 | // Gradle |
| 16 | implementation("com.telnyx.sdk:telnyx:6.82.0") |
| 17 | ``` |
| 18 | |
| 19 | ## Setup |
| 20 | |
| 21 | ```java |
| 22 | import com.telnyx.sdk.client.TelnyxClient; |
| 23 | import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient; |
| 24 | |
| 25 | TelnyxClient client = TelnyxOkHttpClient.fromEnv(); |
| 26 | ``` |
| 27 | |
| 28 | All examples below assume `client` is already initialized as shown above. |
| 29 | |
| 30 | ## Error Handling |
| 31 | |
| 32 | All API calls can fail with network errors, rate limits (429), validation errors (422), |
| 33 | or authentication errors (401). Always handle errors in production code: |
| 34 | |
| 35 | ```java |
| 36 | import com.telnyx.sdk.models.messages.MessageSendParams; |
| 37 | import com.telnyx.sdk.models.messages.MessageSendResponse; |
| 38 | MessageSendParams params = MessageSendParams.builder() |
| 39 | .to("+18445550001") |
| 40 | .from("+18005550101") |
| 41 | .text("Hello from Telnyx!") |
| 42 | .build(); |
| 43 | MessageSendResponse response = client.messages().send(params); |
| 44 | ``` |
| 45 | |
| 46 | Common error codes: `401` invalid API key, `403` insufficient permissions, |
| 47 | `404` resource not found, `422` validation error (check field formats), |
| 48 | `429` rate limited (retry with exponential backoff). |
| 49 | |
| 50 | ## Important Notes |
| 51 | |
| 52 | - **Phone numbers** must be in E.164 format (e.g., `+13125550001`). Include the `+` prefix and country code. No spaces, dashes, or parentheses. |
| 53 | - **Pagination:** List methods return a page. Use `.autoPager()` for automatic iteration: `for (var item : page.autoPager()) { ... }`. For manual control, use `.hasNextPage()` and `.nextPage()`. |
| 54 | |
| 55 | ## Operational Caveats |
| 56 | |
| 57 | - The sending number must already be assigned to the correct messaging profile before you send traffic from it. |
| 58 | - US A2P long-code traffic must complete 10DLC registration before production sending or carriers will block or heavily filter messages. |
| 59 | - Delivery webhooks are asynchronous. Treat the send response as acceptance of the request, not final carrier delivery. |
| 60 | |
| 61 | ## Reference Use Rules |
| 62 | |
| 63 | Do not invent Telnyx parameters, enums, response fields, or webhook fields. |
| 64 | |
| 65 | - 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. |
| 66 | - 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). |
| 67 | - Before reading or matching webhook fields beyond the inline examples, read [the webhook payload reference](references/api-details.md#webhook-payload-fields). |
| 68 | |
| 69 | ## Core Tasks |
| 70 | |
| 71 | ### Send an SMS |
| 72 | |
| 73 | Primary outbound messaging flow. Agents need exact request fields and delivery-related response fields. |
| 74 | |
| 75 | `client.messages().send()` — `POST /messages` |
| 76 | |
| 77 | | Parameter | Type | Required | Description | |
| 78 | |-----------|------|----------|-------------| |
| 79 | | `to` | string (E.164) | Yes | Receiving address (+E.164 formatted phone number or short co... | |
| 80 | | `from` | string (E.164) | Yes | Sending address (+E.164 formatted phone number, alphanumeric... | |
| 81 | | `text` | string | Yes | Message body (i.e., content) as a non-empty string. | |
| 82 | | `messagingProfileId` | string (UUID) | No | Unique identifier for a messaging profile. | |
| 83 | | `mediaUrls` | array[string] | No | A list of media URLs. | |
| 84 | | `webhookUrl` | string (URL) | No | The URL where webhooks related to this message will be sent. | |
| 85 | | ... | | | +7 optional params in [references/api-details.md](references/api-details.md) | |
| 86 | |
| 87 | ```java |
| 88 | import com.telnyx.sdk.models.messages.MessageSendParams; |
| 89 | import com.telnyx.sdk.models.messages.MessageSendResponse; |
| 90 | |
| 91 | MessageSendParams params = MessageSendParams.builder() |
| 92 | .to("+18445550001") |
| 93 | .from("+18005550101") |
| 94 | |
| 95 | .text("Hello from Telnyx!") |
| 96 | .build(); |
| 97 | MessageSendResponse response = client.messages().send(params); |
| 98 | ``` |
| 99 | |
| 100 | Primary response fields: |
| 101 | - `response.data.id` |
| 102 | - `response.data.to` |
| 103 | - `response.data.from` |
| 104 | - `response.data.text` |
| 105 | - `response.data.sentAt` |
| 106 | - `response.data.errors` |
| 107 | |
| 108 | ### Send an SMS with an alphanumeric sender ID |
| 109 | |
| 110 | Common sender variant that requires different request shape. |
| 111 | |
| 112 | `client.messages().sendWithAlphanumericSender()` — `POST /messages/alphanumeric_sender_id` |
| 113 | |
| 114 | | Parameter | Type | Required | Description | |
| 115 | |-----------|------|----------|-------------| |
| 116 | | `from` | string (E.164) | Yes | A valid alphanumeric sender ID on the user's account. | |
| 117 | | `to` | string (E.164) | Yes | Receiving address (+E.164 formatted phone number or short co... | |
| 118 | | `text` | string | Yes | The message body. | |
| 119 | | `messagingProfileId` | string (UUID) | Yes | The |