$npx -y skills add team-telnyx/ai --skill telnyx-messaging-hosted-goSet up hosted SMS numbers, toll-free verification, and RCS messaging. Use when migrating numbers or enabling rich messaging features. This skill provides Go SDK examples.
| 1 | <!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. --> |
| 2 | |
| 3 | # Telnyx Messaging Hosted - 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 | ## Send an RCS message |
| 67 | |
| 68 | `POST /messages/rcs` — Required: `agent_id`, `to`, `messaging_profile_id`, `agent_message` |
| 69 | |
| 70 | Optional: `mms_fallback` (object), `sms_fallback` (object), `type` (enum: RCS), `webhook_url` (url) |
| 71 | |
| 72 | ```go |
| 73 | response, err := client.Messages.Rcs.Send(context.Background(), telnyx.MessageRcSendParams{ |
| 74 | AgentID: "Agent007", |
| 75 | AgentMessage: telnyx.RcsAgentMessageParam{}, |
| 76 | MessagingProfileID: "550e8400-e29b-41d4-a716-446655440000", |
| 77 | To: "+13125551234", |
| 78 | }) |
| 79 | if err != nil { |
| 80 | log.Fatal(err) |
| 81 | } |
| 82 | fmt.Printf("%+v\n", response.Data) |
| 83 | ``` |
| 84 | |
| 85 | Returns: `body` (object), `direction` (string), `encoding` (string), `from` (object), `id` (string), `messaging_profile_id` (string), `organization_id` (string), `received_at` (date-time), `record_type` (string), `to` (array[object]), `type` (string), `wait_seconds` (float) |
| 86 | |
| 87 | ## Generate RCS deeplink |
| 88 | |
| 89 | Generate a deeplink URL that can be used to start an RCS conversation with a specific agent. |
| 90 | |
| 91 | `GET /messages/rcs/deeplinks/{agent_id}` |
| 92 | |
| 93 | ```go |
| 94 | response, err := client.Messages.Rcs.GenerateDeeplink( |
| 95 | context.Background(), |
| 96 | "agent_id", |
| 97 | telnyx.MessageRcGenerateDeeplinkParams{}, |
| 98 | ) |
| 99 | if err != nil { |
| 100 | log.Fatal(err) |
| 101 | } |
| 102 | fmt.Printf("%+v\n", response.Data) |
| 103 | ``` |
| 104 | |
| 105 | Returns: `url` (string) |
| 106 | |
| 107 | ## List all RCS agents |
| 108 | |
| 109 | `GET /messaging/rcs/agents` |
| 110 | |
| 111 | ```go |
| 112 | page, err := client.Messaging.Rcs.Agents.List(context.Background(), telnyx.MessagingRcAgentListParams{}) |
| 113 | if err != nil { |
| 114 | log.Fatal(err) |
| 115 | } |
| 116 | fmt.Printf("%+v\n", page) |
| 117 | ``` |
| 118 | |
| 119 | Returns: `agent_id` (string), `agent_name` (string), `created_at` (date-time), `enabled` (boolean), `profile_id` (uuid), `updated_at` (date-time), `user_id` (string), `webhook_failover_url` (url), `webhook_url` (url) |
| 120 | |
| 121 | ## Retrieve an RCS agent |
| 122 | |
| 123 | `GET /messaging/rcs/agents/{id}` |
| 124 | |
| 125 | ```go |
| 126 | rcsAgentResponse, err := client.Messaging.Rcs.Agents.Get(context.Background(), "id") |
| 127 | if err != nil { |
| 128 | log.Fatal(err) |
| 129 | } |
| 130 | fmt.Printf("%+v\n", rcsAgentResponse.Data) |
| 131 | ``` |
| 132 | |
| 133 | Returns: `agent_id` (string), `agent_name` (string), `created_at` (date-time), `enabled` (boolean), `profile_id` (uuid), `updated_at` (date-time), `user_id` (string), `webhook_failover_url` (url), `webhook_url` (url) |
| 134 | |
| 135 | ## Modify an RCS agent |
| 136 | |
| 137 | `PATCH /messaging/rcs/agents/{id}` |
| 138 | |
| 139 | Optional: `profile_id` (uuid), `webhook_failover_url` (url), `webhook_url` (url) |
| 140 | |
| 141 | ```go |
| 142 | rcsAgentResponse, err := client.Messaging.Rcs.Agents.Update( |
| 143 | context.Background(), |
| 144 | "id", |
| 145 | telnyx.MessagingRcAgentUpdateParams{}, |
| 146 | ) |
| 147 | if err != nil { |
| 148 | log.Fatal(err) |
| 149 | } |
| 150 | fmt.Printf("%+v\n", rcsAgentResponse.Data) |
| 151 | ``` |
| 152 | |
| 153 | Returns: `agent_id` (string), `agent_name` (string), `created_at` (date-time), `enabled` (boolean), `profile_id` (uuid), `updated_at` (date-time), `user_id` (string), `webhook_failover_url` (url), `webhook_url` (url) |
| 154 | |
| 155 | ## Check RCS capabilities (batch) |
| 156 | |
| 157 | `POST /messaging/rcs/bulk_capabilities` — Required: `agent_id`, `phone_numbers` |
| 158 | |
| 159 | ```go |
| 160 | response, er |