跳至正文
OpenAgentSkill
浏览已开放 · 目录记录日期 2026-11-21 · 自动更新和账户服务暂时关闭。
浏览器与自动化

telnyx-messaging-go

Send and receive SMS/MMS, handle opt-outs and delivery webhooks. Use for notifications, 2FA, or messaging apps.

team-telnyx · 已有 AI 审核记录

安装与使用

运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。

npx skills add team-telnyx/ai --skill telnyx-messaging-go

技能说明


name: telnyx-messaging-go description: >- Send and receive SMS/MMS, handle opt-outs and delivery webhooks. Use for notifications, 2FA, or messaging apps. metadata: author: telnyx product: messaging language: go generated_by: telnyx-openapi-pipeline contract: v2

Telnyx Messaging - Go

Installation

go get github.com/team-telnyx/telnyx-go

Setup

import (
  "context"
  "fmt"
  "os"

  "github.com/team-telnyx/telnyx-go"
  "github.com/team-telnyx/telnyx-go/option"
)

client := telnyx.NewClient(
  option.WithAPIKey(os.Getenv("TELNYX_API_KEY")),
)

All examples below assume client is already initialized as shown above.

Error Handling

All API calls can fail with network errors, rate limits (429), validation errors (422), or authentication errors (401). Always handle errors in production code:

import "errors"

response, err := client.Messages.Send(context.Background(), telnyx.MessageSendParams{
		To: "+18445550001",
		From: "+18005550101",
		Text: "Hello from Telnyx!",
	})
if err != nil {
  var apiErr *telnyx.Error
  if errors.As(err, &apiErr) {
    switch apiErr.StatusCode {
    case 422:
      fmt.Println("Validation error — check required fields and formats")
    case 429:
      fmt.Println("Rate limited, retrying...")
    default:
      fmt.Printf("API error %d: %s\n", apiErr.StatusCode, apiErr.Error())
    }
  } else {
    fmt.Println("Network error — check connectivity and retry")
  }
}

Common error codes: 401 invalid API key, 403 insufficient permissions, 404 resource not found, 422 validation error (check field formats), 429 rate limited (retry with exponential backoff).

Important Notes

  • Phone numbers must be in E.164 format (e.g., +13125550001). Include the + prefix and country code. No spaces, dashes, or parentheses.
  • Pagination: Use ListAutoPaging() for automatic iteration: iter := client.Resource.ListAutoPaging(ctx, params); for iter.Next() { item := iter.Current() }.

Operational Caveats

  • The sending number must already be assigned to the correct messaging profile before you send traffic from it.
  • US A2P long-code traffic must complete 10DLC registration before production sending or carriers will block or heavily filter messages.
  • Delivery webhooks are asynchronous. Treat the send response as acceptance of the request, not final carrier delivery.

Reference Use Rules

Do not invent Telnyx parameters, enums, response fields, or webhook fields.

  • If the parameter, enum, or response field you need is not shown inline in this skill, read references/api-details.md before writing code.
  • Before using any operation in ## Additional Operations, read the optional-parameters section and the response-schemas section.
  • Before reading or matching webhook fields beyond the inline examples, read the webhook payload reference.

Core Tasks

Send an SMS

Primary outbound messaging flow. Agents need exact request fields and delivery-related response fields.

client.Messages.Send() — POST /messages

ParameterTypeRequiredDescription
Tostring (E.164)YesReceiving address (+E.164 formatted phone number or short co...
Fromstring (E.164)YesSending address (+E.164 formatted phone number, alphanumeric...
TextstringYesMessage body (i.e., content) as a non-empty string.
MessagingProfileIdstring (UUID)NoUnique identifier for a messaging profile.
MediaUrlsarray[string]NoA list of media URLs.
WebhookUrlstring (URL)NoThe URL where webhooks related to this message will be sent.
...+7 optional params in references/api-details.md
	response, err := client.Messages.Send(context.Background(), telnyx.MessageSendParams{
		To: "+18445550001",
		From: "+18005550101",
		Text: "Hello from Telnyx!",
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", response.Data)

Primary response fields:

  • response.Data.ID
  • response.Data.To
  • response.Data.From
  • response.Data.Text
  • response.Data.SentAt
  • response.Data.Errors

Send an SMS with an alphanumeric sender ID

Common sender variant that requires different request shape.

client.Messages.SendWithAlphanumericSender() — POST /messages/alphanumeric_sender_id

ParameterTypeRequiredDescription
Fromstring (E.164)YesA valid alphanumeric sender ID on the user's account.
Tostring (E.164)YesReceiving address (+E.164 formatted phone number or short co...
TextstringYesThe message body.
MessagingProfileIdstring (UUID)YesThe messaging profile ID to use.
WebhookUrlstring (URL)NoCallback URL for delivery status updates.
WebhookFailoverUrlstring (URL)NoFailover callback URL for delivery status updates.
UseProfileWebhooksbooleanNoIf true, use the messaging profile's webhook settings.
	response, err := client.Messages.SendWithAlphanumericSender(context.Background(), telnyx.MessageSendWithAlphanumericSenderParams{
		From:               "MyCompany",
		MessagingProfileID: "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
		Text: "Hello from Telnyx!",
		To: "+13125550001",
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", response.Data)

Primary response fields:

  • response.Data.ID
  • response.Data.To
  • response.Data.From
  • response.Data.Text
  • response.Data.SentAt
  • response.Data.Errors

Webhook Verification

Telnyx signs webhooks with Ed25519. Each request includes telnyx-signature-ed25519 and telnyx-timestamp header

阅读完整来源 ↗