$npx -y skills add team-telnyx/ai --skill telnyx-messaging-profiles-goCreate and manage messaging profiles with number pools, sticky sender, and geomatch features. Configure short codes for high-volume messaging. This skill provides Go SDK examples.
| 1 | <!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. --> |
| 2 | |
| 3 | # Telnyx Messaging Profiles - Go |
| 4 | |
| 5 | ## Installation |
| 6 | |
| 7 | ```bash |
| 8 | go get github.com/team-telnyx/telnyx-go |
| 9 | ``` |
| 10 | |
| 11 | ## Setup |
| 12 | |
| 13 | ```go |
| 14 | import ( |
| 15 | "context" |
| 16 | "fmt" |
| 17 | "os" |
| 18 | |
| 19 | "github.com/team-telnyx/telnyx-go" |
| 20 | "github.com/team-telnyx/telnyx-go/option" |
| 21 | ) |
| 22 | |
| 23 | client := telnyx.NewClient( |
| 24 | option.WithAPIKey(os.Getenv("TELNYX_API_KEY")), |
| 25 | ) |
| 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 | ```go |
| 36 | import "errors" |
| 37 | |
| 38 | result, err := client.Messages.Send(ctx, params) |
| 39 | if err != nil { |
| 40 | var apiErr *telnyx.Error |
| 41 | if errors.As(err, &apiErr) { |
| 42 | switch apiErr.StatusCode { |
| 43 | case 422: |
| 44 | fmt.Println("Validation error — check required fields and formats") |
| 45 | case 429: |
| 46 | // Rate limited — wait and retry with exponential backoff |
| 47 | fmt.Println("Rate limited, retrying...") |
| 48 | default: |
| 49 | fmt.Printf("API error %d: %s\n", apiErr.StatusCode, apiErr.Error()) |
| 50 | } |
| 51 | } else { |
| 52 | fmt.Println("Network error — check connectivity and retry") |
| 53 | } |
| 54 | } |
| 55 | ``` |
| 56 | |
| 57 | Common error codes: `401` invalid API key, `403` insufficient permissions, |
| 58 | `404` resource not found, `422` validation error (check field formats), |
| 59 | `429` rate limited (retry with exponential backoff). |
| 60 | |
| 61 | ## Important Notes |
| 62 | |
| 63 | - **Pagination:** Use `ListAutoPaging()` for automatic iteration: `iter := client.Resource.ListAutoPaging(ctx, params); for iter.Next() { item := iter.Current() }`. |
| 64 | |
| 65 | ## List messaging profiles |
| 66 | |
| 67 | `GET /messaging_profiles` |
| 68 | |
| 69 | ```go |
| 70 | page, err := client.MessagingProfiles.List(context.Background(), telnyx.MessagingProfileListParams{}) |
| 71 | if err != nil { |
| 72 | log.Fatal(err) |
| 73 | } |
| 74 | fmt.Printf("%+v\n", page) |
| 75 | ``` |
| 76 | |
| 77 | 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]) |
| 78 | |
| 79 | ## Create a messaging profile |
| 80 | |
| 81 | `POST /messaging_profiles` — Required: `name`, `whitelisted_destinations` |
| 82 | |
| 83 | 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) |
| 84 | |
| 85 | ```go |
| 86 | messagingProfile, err := client.MessagingProfiles.New(context.Background(), telnyx.MessagingProfileNewParams{ |
| 87 | Name: "My name", |
| 88 | WhitelistedDestinations: []string{"US"}, |
| 89 | }) |
| 90 | if err != nil { |
| 91 | log.Fatal(err) |
| 92 | } |
| 93 | fmt.Printf("%+v\n", messagingProfile.Data) |
| 94 | ``` |
| 95 | |
| 96 | 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]) |
| 97 | |
| 98 | ## Retrieve a messaging profile |
| 99 | |
| 100 | `GET /messaging_profiles/{id}` |
| 101 | |
| 102 | ```go |
| 103 | messagingProfile, err := client.MessagingProfiles.Get(context.Background(), "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e") |
| 104 | if err != nil { |
| 105 | log.Fatal(err) |
| 106 | } |
| 107 | fmt.Printf("%+v\n", messagingProfile.Data) |