$npx -y skills add team-telnyx/ai --skill telnyx-messaging-profiles-javaCreate and manage messaging profiles with number pools, sticky sender, and geomatch features. Configure short codes for high-volume messaging. This skill provides Java SDK examples.
| 1 | <!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. --> |
| 2 | |
| 3 | # Telnyx Messaging Profiles - Java |
| 4 | |
| 5 | ## Installation |
| 6 | |
| 7 | ```text |
| 8 | <!-- Maven --> |
| 9 | <dependency> |
| 10 | <groupId>com.telnyx.sdk</groupId> |
| 11 | <artifactId>telnyx</artifactId> |
| 12 | <version>6.36.0</version> |
| 13 | </dependency> |
| 14 | |
| 15 | // Gradle |
| 16 | implementation("com.telnyx.sdk:telnyx:6.36.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.errors.TelnyxServiceException; |
| 37 | |
| 38 | try { |
| 39 | var result = client.messages().send(params); |
| 40 | } catch (TelnyxServiceException e) { |
| 41 | System.err.println("API error " + e.statusCode() + ": " + e.getMessage()); |
| 42 | if (e.statusCode() == 422) { |
| 43 | System.err.println("Validation error — check required fields and formats"); |
| 44 | } else if (e.statusCode() == 429) { |
| 45 | // Rate limited — wait and retry with exponential backoff |
| 46 | Thread.sleep(1000); |
| 47 | } |
| 48 | } |
| 49 | ``` |
| 50 | |
| 51 | Common error codes: `401` invalid API key, `403` insufficient permissions, |
| 52 | `404` resource not found, `422` validation error (check field formats), |
| 53 | `429` rate limited (retry with exponential backoff). |
| 54 | |
| 55 | ## Important Notes |
| 56 | |
| 57 | - **Pagination:** List methods return a page. Use `.autoPager()` for automatic iteration: `for (var item : page.autoPager()) { ... }`. For manual control, use `.hasNextPage()` and `.nextPage()`. |
| 58 | |
| 59 | ## List messaging profiles |
| 60 | |
| 61 | `GET /messaging_profiles` |
| 62 | |
| 63 | ```java |
| 64 | import com.telnyx.sdk.models.messagingprofiles.MessagingProfileListPage; |
| 65 | import com.telnyx.sdk.models.messagingprofiles.MessagingProfileListParams; |
| 66 | |
| 67 | MessagingProfileListPage page = client.messagingProfiles().list(); |
| 68 | ``` |
| 69 | |
| 70 | 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]) |
| 71 | |
| 72 | ## Create a messaging profile |
| 73 | |
| 74 | `POST /messaging_profiles` — Required: `name`, `whitelisted_destinations` |
| 75 | |
| 76 | 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) |
| 77 | |
| 78 | ```java |
| 79 | import com.telnyx.sdk.models.messagingprofiles.MessagingProfileCreateParams; |
| 80 | import com.telnyx.sdk.models.messagingprofiles.MessagingProfileCreateResponse; |
| 81 | |
| 82 | MessagingProfileCreateParams params = MessagingProfileCreateParams.builder() |
| 83 | .name("My name") |
| 84 | .addWhitelistedDestination("US") |
| 85 | .build(); |
| 86 | MessagingProfileCreateResponse messagingProfile = client.messagingProfiles().create(params); |
| 87 | ``` |
| 88 | |
| 89 | 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]) |
| 90 | |
| 91 | ## Retrieve |