$npx -y skills add team-telnyx/ai --skill telnyx-messaging-goSend and receive SMS/MMS, handle opt-outs and delivery webhooks. Use for notifications, 2FA, or messaging apps.
| 1 | <!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. --> |
| 2 | |
| 3 | # Telnyx Messaging - 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 | response, err := client.Messages.Send(context.Background(), telnyx.MessageSendParams{ |
| 39 | To: "+18445550001", |
| 40 | From: "+18005550101", |
| 41 | Text: "Hello from Telnyx!", |
| 42 | }) |
| 43 | if err != nil { |
| 44 | var apiErr *telnyx.Error |
| 45 | if errors.As(err, &apiErr) { |
| 46 | switch apiErr.StatusCode { |
| 47 | case 422: |
| 48 | fmt.Println("Validation error — check required fields and formats") |
| 49 | case 429: |
| 50 | fmt.Println("Rate limited, retrying...") |
| 51 | default: |
| 52 | fmt.Printf("API error %d: %s\n", apiErr.StatusCode, apiErr.Error()) |
| 53 | } |
| 54 | } else { |
| 55 | fmt.Println("Network error — check connectivity and retry") |
| 56 | } |
| 57 | } |
| 58 | ``` |
| 59 | |
| 60 | Common error codes: `401` invalid API key, `403` insufficient permissions, |
| 61 | `404` resource not found, `422` validation error (check field formats), |
| 62 | `429` rate limited (retry with exponential backoff). |
| 63 | |
| 64 | ## Important Notes |
| 65 | |
| 66 | - **Phone numbers** must be in E.164 format (e.g., `+13125550001`). Include the `+` prefix and country code. No spaces, dashes, or parentheses. |
| 67 | - **Pagination:** Use `ListAutoPaging()` for automatic iteration: `iter := client.Resource.ListAutoPaging(ctx, params); for iter.Next() { item := iter.Current() }`. |
| 68 | |
| 69 | ## Operational Caveats |
| 70 | |
| 71 | - The sending number must already be assigned to the correct messaging profile before you send traffic from it. |
| 72 | - US A2P long-code traffic must complete 10DLC registration before production sending or carriers will block or heavily filter messages. |
| 73 | - Delivery webhooks are asynchronous. Treat the send response as acceptance of the request, not final carrier delivery. |
| 74 | |
| 75 | ## Reference Use Rules |
| 76 | |
| 77 | Do not invent Telnyx parameters, enums, response fields, or webhook fields. |
| 78 | |
| 79 | - If the parameter, enum, or response field you need is not shown inline in this skill, read [references/api-details.md](references/api-details.md) before writing code. |
| 80 | - Before using any operation in `## Additional Operations`, read [the optional-parameters section](references/api-details.md#optional-parameters) and [the response-schemas section](references/api-details.md#response-schemas). |
| 81 | - Before reading or matching webhook fields beyond the inline examples, read [the webhook payload reference](references/api-details.md#webhook-payload-fields). |
| 82 | |
| 83 | ## Core Tasks |
| 84 | |
| 85 | ### Send an SMS |
| 86 | |
| 87 | Primary outbound messaging flow. Agents need exact request fields and delivery-related response fields. |
| 88 | |
| 89 | `client.Messages.Send()` — `POST /messages` |
| 90 | |
| 91 | | Parameter | Type | Required | Description | |
| 92 | |-----------|------|----------|-------------| |
| 93 | | `To` | string (E.164) | Yes | Receiving address (+E.164 formatted phone number or short co... | |
| 94 | | `From` | string (E.164) | Yes | Sending address (+E.164 formatted phone number, alphanumeric... | |
| 95 | | `Text` | string | Yes | Message body (i.e., content) as a non-empty string. | |
| 96 | | `MessagingProfileId` | string (UUID) | No | Unique identifier for a messaging profile. | |
| 97 | | `MediaUrls` | array[string] | No | A list of media URLs. | |
| 98 | | `WebhookUrl` | string (URL) | No | The URL where webhooks related to this message will be sent. | |
| 99 | | ... | | | +7 optional params in [references/api-details.md](references/api-details.md) | |
| 100 | |
| 101 | ```go |
| 102 | response, err := client.Messages.Send(context.Background(), telnyx.MessageSendParams{ |
| 103 | To: "+18445550001", |
| 104 | From: "+18005550101", |
| 105 | Text: "Hello from Telnyx!", |
| 106 | }) |
| 107 | if err != nil { |
| 108 | log.Fatal(err) |
| 109 | } |
| 110 | fmt.Printf("%+v\n", response.Data) |
| 111 | ``` |
| 112 | |
| 113 | Primary response fields: |
| 114 | - `response.Data.ID` |
| 115 | - `response.Data.To` |
| 116 | - `response.Data.From` |
| 117 | - `response.Data.Text` |
| 118 | - `response.Data.SentAt` |
| 119 | - `response.Data.Errors` |
| 120 | |
| 121 | ### Send an SMS with an alphanumeric sender ID |
| 122 | |
| 123 | Common sender variant that requires different request shape. |
| 124 | |
| 125 | `client.Messages.SendWithAlphanumericSender()` — `POST /messages/alphanumeric_sender_id` |
| 126 | |
| 127 | | Parameter | Type | Required | Description | |
| 128 | |-----------|------|----------|-------------| |
| 129 | | `From` | string (E.164) | Yes | A valid alphanumeric sender ID on the user's account. | |
| 130 | | `To` | string (E.164) | Yes | Receiving address (+E.164 formatted phone number or short co... | |
| 131 | | `Text` | string | Yes | The message body. | |
| 132 | | `MessagingProfileId` |