$npx -y skills add team-telnyx/ai --skill telnyx-messaging-profiles-pythonCreate and manage messaging profiles with number pools, sticky sender, and geomatch features. Configure short codes for high-volume messaging. This skill provides Python SDK examples.
| 1 | <!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. --> |
| 2 | |
| 3 | # Telnyx Messaging Profiles - Python |
| 4 | |
| 5 | ## Installation |
| 6 | |
| 7 | ```bash |
| 8 | pip install telnyx |
| 9 | ``` |
| 10 | |
| 11 | ## Setup |
| 12 | |
| 13 | ```python |
| 14 | import os |
| 15 | from telnyx import Telnyx |
| 16 | |
| 17 | client = Telnyx( |
| 18 | api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted |
| 19 | ) |
| 20 | ``` |
| 21 | |
| 22 | All examples below assume `client` is already initialized as shown above. |
| 23 | |
| 24 | ## Error Handling |
| 25 | |
| 26 | All API calls can fail with network errors, rate limits (429), validation errors (422), |
| 27 | or authentication errors (401). Always handle errors in production code: |
| 28 | |
| 29 | ```python |
| 30 | import telnyx |
| 31 | |
| 32 | try: |
| 33 | result = client.messages.send(to="+13125550001", from_="+13125550002", text="Hello") |
| 34 | except telnyx.APIConnectionError: |
| 35 | print("Network error — check connectivity and retry") |
| 36 | except telnyx.RateLimitError: |
| 37 | # 429: rate limited — wait and retry with exponential backoff |
| 38 | import time |
| 39 | time.sleep(1) # Check Retry-After header for actual delay |
| 40 | except telnyx.APIStatusError as e: |
| 41 | print(f"API error {e.status_code}: {e.message}") |
| 42 | if e.status_code == 422: |
| 43 | print("Validation error — check required fields and formats") |
| 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 | - **Pagination:** List methods return an auto-paginating iterator. Use `for item in page_result:` to iterate through all pages automatically. |
| 53 | |
| 54 | ## List messaging profiles |
| 55 | |
| 56 | `GET /messaging_profiles` |
| 57 | |
| 58 | ```python |
| 59 | page = client.messaging_profiles.list() |
| 60 | page = page.data[0] |
| 61 | print(page.id) |
| 62 | ``` |
| 63 | |
| 64 | 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]) |
| 65 | |
| 66 | ## Create a messaging profile |
| 67 | |
| 68 | `POST /messaging_profiles` — Required: `name`, `whitelisted_destinations` |
| 69 | |
| 70 | 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) |
| 71 | |
| 72 | ```python |
| 73 | messaging_profile = client.messaging_profiles.create( |
| 74 | name="My name", |
| 75 | whitelisted_destinations=["US"], |
| 76 | ) |
| 77 | print(messaging_profile.data) |
| 78 | ``` |
| 79 | |
| 80 | 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]) |
| 81 | |
| 82 | ## Retrieve a messaging profile |
| 83 | |
| 84 | `GET /messaging_profiles/{id}` |
| 85 | |
| 86 | ```python |
| 87 | messaging_profile = client.messaging_profiles.retrieve( |
| 88 | "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", |
| 89 | ) |
| 90 | print(messaging_profile.data) |
| 91 | ``` |
| 92 | |
| 93 | 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_p |