$npx -y skills add team-telnyx/ai --skill telnyx-numbers-config-goConfigure phone number settings including caller ID, call forwarding, messaging enablement, and connection assignments. This skill provides Go SDK examples.
| 1 | <!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. --> |
| 2 | |
| 3 | # Telnyx Numbers Config - 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 | - **Phone numbers** must be in E.164 format (e.g., `+13125550001`). Include the `+` prefix and country code. No spaces, dashes, or parentheses. |
| 64 | - **Pagination:** Use `ListAutoPaging()` for automatic iteration: `iter := client.Resource.ListAutoPaging(ctx, params); for iter.Next() { item := iter.Current() }`. |
| 65 | |
| 66 | ## Bulk update phone number profiles |
| 67 | |
| 68 | `POST /messaging_numbers_bulk_updates` — Required: `messaging_profile_id`, `numbers` |
| 69 | |
| 70 | Optional: `assign_only` (boolean) |
| 71 | |
| 72 | ```go |
| 73 | messagingNumbersBulkUpdate, err := client.MessagingNumbersBulkUpdates.New(context.Background(), telnyx.MessagingNumbersBulkUpdateNewParams{ |
| 74 | MessagingProfileID: "00000000-0000-0000-0000-000000000000", |
| 75 | Numbers: []string{"+18880000000", "+18880000001", "+18880000002"}, |
| 76 | }) |
| 77 | if err != nil { |
| 78 | log.Fatal(err) |
| 79 | } |
| 80 | fmt.Printf("%+v\n", messagingNumbersBulkUpdate.Data) |
| 81 | ``` |
| 82 | |
| 83 | Returns: `failed` (array[string]), `order_id` (uuid), `pending` (array[string]), `record_type` (enum: messaging_numbers_bulk_update), `success` (array[string]) |
| 84 | |
| 85 | ## Retrieve bulk update status |
| 86 | |
| 87 | `GET /messaging_numbers_bulk_updates/{order_id}` |
| 88 | |
| 89 | ```go |
| 90 | messagingNumbersBulkUpdate, err := client.MessagingNumbersBulkUpdates.Get(context.Background(), "order_id") |
| 91 | if err != nil { |
| 92 | log.Fatal(err) |
| 93 | } |
| 94 | fmt.Printf("%+v\n", messagingNumbersBulkUpdate.Data) |
| 95 | ``` |
| 96 | |
| 97 | Returns: `failed` (array[string]), `order_id` (uuid), `pending` (array[string]), `record_type` (enum: messaging_numbers_bulk_update), `success` (array[string]) |
| 98 | |
| 99 | ## List mobile phone numbers with messaging settings |
| 100 | |
| 101 | `GET /mobile_phone_numbers/messaging` |
| 102 | |
| 103 | ```go |
| 104 | page, err := client.MobilePhoneNumbers.Messaging.List(context.Background(), telnyx.MobilePhoneNumberMessagingListParams{}) |
| 105 | if err != nil { |
| 106 | log.Fatal(err) |
| 107 | } |
| 108 | fmt.Printf("%+v\n", page) |
| 109 | ``` |
| 110 | |
| 111 | Returns: `country_code` (string), `created_at` (date-time), `features` (object), `id` (string), `messaging_product` (string), `messaging_profile_id` (string | null), `organization_id` (string), `phone_number` (string), `record_type` (enum: messaging_phone_number, messaging_settings), `tags` (array[string]), `traffic_type` (string), `type` (enum: longcode), `updated_at` (date-time) |
| 112 | |
| 113 | ## Retrieve a mobile phone number with messaging settings |
| 114 | |
| 115 | `GET /mobile_phone_numbers/{id}/messaging` |
| 116 | |
| 117 | ```go |
| 118 | messaging, err := client.MobilePhoneNumbers.Messaging.Get(context.Background(), "id") |
| 119 | if err != nil { |
| 120 | log.Fatal(err) |
| 121 | } |
| 122 | fmt.Printf("%+v\n", messaging.Data) |
| 123 | ``` |
| 124 | |
| 125 | Returns: `country_code` (string), `created_at` (date-time), `features` (object), `id` (string), `messaging_product` (string), `messaging_profile_id` (string | null), `organization_id` (string), `phone_number` (string), `record_type` (enum: messaging_phone_number, messaging_settings), `tags` (array[string]), `traffic_type` (string), `type` (enum: longcode), `updated_at` (date-time) |
| 126 | |
| 127 | ## List phone numbers |
| 128 | |
| 129 | `GET /phone_numbers` |
| 130 | |
| 131 | ```go |
| 132 | page, err := client.PhoneNumbers.List(context.Background(), telnyx.PhoneNumberListParams{}) |
| 133 | if err != nil { |
| 134 | log.Fatal(err) |
| 135 | } |
| 136 | fmt.Printf("%+v\n", page) |
| 137 | ``` |
| 138 | |
| 139 | Returns: `billing_group_id` (string | null), `call_forwarding_enabled` (boolean), `call_recording_enabled` (boolean), `caller_id_name_enabled` (boolean), `cnam_listing_enabled` (boolean), `connection_id` (string | |