telnyx-account-notifications-go

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
<!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. -->
<!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. -->

Telnyx Account Notifications - Go

Telnyx 账户通知 - Go

Installation

安装

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

Setup

初始化配置

go
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.
go
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")),
)
以下所有示例均默认
client
已按照上方代码完成初始化。

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:
go
import "errors"

result, err := client.Messages.Send(ctx, params)
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:
      // Rate limited — wait and retry with exponential backoff
      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).
所有API调用都可能因网络错误、限流(429)、参数校验错误(422)或鉴权失败(401)报错,生产环境代码中请务必做好错误处理:
go
import "errors"

result, err := client.Messages.Send(ctx, params)
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:
      // Rate limited — wait and retry with exponential backoff
      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")
  }
}
常见错误码:
401
无效API密钥、
403
权限不足、
404
资源不存在、
422
参数校验错误(请检查字段格式)、
429
触发限流(请使用指数退避策略重试)。

Important Notes

重要提示

  • Pagination: Use
    ListAutoPaging()
    for automatic iteration:
    iter := client.Resource.ListAutoPaging(ctx, params); for iter.Next() { item := iter.Current() }
    .
  • 分页: 可使用
    ListAutoPaging()
    实现自动遍历:
    iter := client.Resource.ListAutoPaging(ctx, params); for iter.Next() { item := iter.Current() }

List notification channels

列出通知渠道

List notification channels.
GET /notification_channels
go
	page, err := client.NotificationChannels.List(context.Background(), telnyx.NotificationChannelListParams{})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", page)
Returns:
channel_destination
(string),
channel_type_id
(enum: sms, voice, email, webhook),
created_at
(date-time),
id
(string),
notification_profile_id
(string),
updated_at
(date-time)
列出所有通知渠道。
GET /notification_channels
go
	page, err := client.NotificationChannels.List(context.Background(), telnyx.NotificationChannelListParams{})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", page)
返回参数:
channel_destination
(字符串)、
channel_type_id
(枚举值:sms, voice, email, webhook)、
created_at
(日期时间)、
id
(字符串)、
notification_profile_id
(字符串)、
updated_at
(日期时间)

Create a notification channel

创建通知渠道

Create a notification channel.
POST /notification_channels
Optional:
channel_destination
(string),
channel_type_id
(enum: sms, voice, email, webhook),
created_at
(date-time),
id
(string),
notification_profile_id
(string),
updated_at
(date-time)
go
	notificationChannel, err := client.NotificationChannels.New(context.Background(), telnyx.NotificationChannelNewParams{
		ChannelTypeID: "550e8400-e29b-41d4-a716-446655440000",
		ChannelDestination: "https://example.com/webhooks",
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", notificationChannel.Data)
Returns:
channel_destination
(string),
channel_type_id
(enum: sms, voice, email, webhook),
created_at
(date-time),
id
(string),
notification_profile_id
(string),
updated_at
(date-time)
新建一个通知渠道。
POST /notification_channels
可选参数:
channel_destination
(字符串)、
channel_type_id
(枚举值:sms, voice, email, webhook)、
created_at
(日期时间)、
id
(字符串)、
notification_profile_id
(字符串)、
updated_at
(日期时间)
go
	notificationChannel, err := client.NotificationChannels.New(context.Background(), telnyx.NotificationChannelNewParams{
		ChannelTypeID: "550e8400-e29b-41d4-a716-446655440000",
		ChannelDestination: "https://example.com/webhooks",
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", notificationChannel.Data)
返回参数:
channel_destination
(字符串)、
channel_type_id
(枚举值:sms, voice, email, webhook)、
created_at
(日期时间)、
id
(字符串)、
notification_profile_id
(字符串)、
updated_at
(日期时间)

Get a notification channel

获取单个通知渠道

Get a notification channel.
GET /notification_channels/{id}
go
	notificationChannel, err := client.NotificationChannels.Get(context.Background(), "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", notificationChannel.Data)
Returns:
channel_destination
(string),
channel_type_id
(enum: sms, voice, email, webhook),
created_at
(date-time),
id
(string),
notification_profile_id
(string),
updated_at
(date-time)
查询指定通知渠道的详情。
GET /notification_channels/{id}
go
	notificationChannel, err := client.NotificationChannels.Get(context.Background(), "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", notificationChannel.Data)
返回参数:
channel_destination
(字符串)、
channel_type_id
(枚举值:sms, voice, email, webhook)、
created_at
(日期时间)、
id
(字符串)、
notification_profile_id
(字符串)、
updated_at
(日期时间)

Update a notification channel

更新通知渠道

Update a notification channel.
PATCH /notification_channels/{id}
Optional:
channel_destination
(string),
channel_type_id
(enum: sms, voice, email, webhook),
created_at
(date-time),
id
(string),
notification_profile_id
(string),
updated_at
(date-time)
go
	notificationChannel, err := client.NotificationChannels.Update(
		context.Background(),
		"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
		telnyx.NotificationChannelUpdateParams{
			NotificationChannel: telnyx.NotificationChannelParam{},
		},
	)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", notificationChannel.Data)
Returns:
channel_destination
(string),
channel_type_id
(enum: sms, voice, email, webhook),
created_at
(date-time),
id
(string),
notification_profile_id
(string),
updated_at
(date-time)
修改指定通知渠道的配置。
PATCH /notification_channels/{id}
可选参数:
channel_destination
(字符串)、
channel_type_id
(枚举值:sms, voice, email, webhook)、
created_at
(日期时间)、
id
(字符串)、
notification_profile_id
(字符串)、
updated_at
(日期时间)
go
	notificationChannel, err := client.NotificationChannels.Update(
		context.Background(),
		"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
		telnyx.NotificationChannelUpdateParams{
			NotificationChannel: telnyx.NotificationChannelParam{},
		},
	)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", notificationChannel.Data)
返回参数:
channel_destination
(字符串)、
channel_type_id
(枚举值:sms, voice, email, webhook)、
created_at
(日期时间)、
id
(字符串)、
notification_profile_id
(字符串)、
updated_at
(日期时间)

Delete a notification channel

删除通知渠道

Delete a notification channel.
DELETE /notification_channels/{id}
go
	notificationChannel, err := client.NotificationChannels.Delete(context.Background(), "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", notificationChannel.Data)
Returns:
channel_destination
(string),
channel_type_id
(enum: sms, voice, email, webhook),
created_at
(date-time),
id
(string),
notification_profile_id
(string),
updated_at
(date-time)
删除指定的通知渠道。
DELETE /notification_channels/{id}
go
	notificationChannel, err := client.NotificationChannels.Delete(context.Background(), "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", notificationChannel.Data)
返回参数:
channel_destination
(字符串)、
channel_type_id
(枚举值:sms, voice, email, webhook)、
created_at
(日期时间)、
id
(字符串)、
notification_profile_id
(字符串)、
updated_at
(日期时间)

List all Notifications Events Conditions

列出所有通知事件条件

Returns a list of your notifications events conditions.
GET /notification_event_conditions
go
	page, err := client.NotificationEventConditions.List(context.Background(), telnyx.NotificationEventConditionListParams{})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", page)
Returns:
allow_multiple_channels
(boolean),
associated_record_type
(enum: account, phone_number),
asynchronous
(boolean),
created_at
(date-time),
description
(string),
enabled
(boolean),
id
(string),
name
(string),
notification_event_id
(string),
parameters
(array[object]),
supported_channels
(array[string]),
updated_at
(date-time)
返回所有通知事件条件的列表。
GET /notification_event_conditions
go
	page, err := client.NotificationEventConditions.List(context.Background(), telnyx.NotificationEventConditionListParams{})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", page)
返回参数:
allow_multiple_channels
(布尔值)、
associated_record_type
(枚举值:account, phone_number)、
asynchronous
(布尔值)、
created_at
(日期时间)、
description
(字符串)、
enabled
(布尔值)、
id
(字符串)、
name
(字符串)、
notification_event_id
(字符串)、
parameters
(对象数组)、
supported_channels
(字符串数组)、
updated_at
(日期时间)

List all Notifications Events

列出所有通知事件

Returns a list of your notifications events.
GET /notification_events
go
	page, err := client.NotificationEvents.List(context.Background(), telnyx.NotificationEventListParams{})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", page)
Returns:
created_at
(date-time),
enabled
(boolean),
id
(string),
name
(string),
notification_category
(string),
updated_at
(date-time)
返回所有通知事件的列表。
GET /notification_events
go
	page, err := client.NotificationEvents.List(context.Background(), telnyx.NotificationEventListParams{})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", page)
返回参数:
created_at
(日期时间)、
enabled
(布尔值)、
id
(字符串)、
name
(字符串)、
notification_category
(字符串)、
updated_at
(日期时间)

List all Notifications Profiles

列出所有通知配置文件

Returns a list of your notifications profiles.
GET /notification_profiles
go
	page, err := client.NotificationProfiles.List(context.Background(), telnyx.NotificationProfileListParams{})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", page)
Returns:
created_at
(date-time),
id
(string),
name
(string),
updated_at
(date-time)
返回所有通知配置文件的列表。
GET /notification_profiles
go
	page, err := client.NotificationProfiles.List(context.Background(), telnyx.NotificationProfileListParams{})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", page)
返回参数:
created_at
(日期时间)、
id
(字符串)、
name
(字符串)、
updated_at
(日期时间)

Create a notification profile

创建通知配置文件

Create a notification profile.
POST /notification_profiles
Optional:
created_at
(date-time),
id
(string),
name
(string),
updated_at
(date-time)
go
	notificationProfile, err := client.NotificationProfiles.New(context.Background(), telnyx.NotificationProfileNewParams{
		Name: "My Notification Profile",
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", notificationProfile.Data)
Returns:
created_at
(date-time),
id
(string),
name
(string),
updated_at
(date-time)
新建一个通知配置文件。
POST /notification_profiles
可选参数:
created_at
(日期时间)、
id
(字符串)、
name
(字符串)、
updated_at
(日期时间)
go
	notificationProfile, err := client.NotificationProfiles.New(context.Background(), telnyx.NotificationProfileNewParams{
		Name: "My Notification Profile",
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", notificationProfile.Data)
返回参数:
created_at
(日期时间)、
id
(字符串)、
name
(字符串)、
updated_at
(日期时间)

Get a notification profile

获取单个通知配置文件

Get a notification profile.
GET /notification_profiles/{id}
go
	notificationProfile, err := client.NotificationProfiles.Get(context.Background(), "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", notificationProfile.Data)
Returns:
created_at
(date-time),
id
(string),
name
(string),
updated_at
(date-time)
查询指定通知配置文件的详情。
GET /notification_profiles/{id}
go
	notificationProfile, err := client.NotificationProfiles.Get(context.Background(), "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", notificationProfile.Data)
返回参数:
created_at
(日期时间)、
id
(字符串)、
name
(字符串)、
updated_at
(日期时间)

Update a notification profile

更新通知配置文件

Update a notification profile.
PATCH /notification_profiles/{id}
Optional:
created_at
(date-time),
id
(string),
name
(string),
updated_at
(date-time)
go
	notificationProfile, err := client.NotificationProfiles.Update(
		context.Background(),
		"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
		telnyx.NotificationProfileUpdateParams{
			NotificationProfile: telnyx.NotificationProfileParam{},
		},
	)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", notificationProfile.Data)
Returns:
created_at
(date-time),
id
(string),
name
(string),
updated_at
(date-time)
修改指定通知配置文件的配置。
PATCH /notification_profiles/{id}
可选参数:
created_at
(日期时间)、
id
(字符串)、
name
(字符串)、
updated_at
(日期时间)
go
	notificationProfile, err := client.NotificationProfiles.Update(
		context.Background(),
		"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
		telnyx.NotificationProfileUpdateParams{
			NotificationProfile: telnyx.NotificationProfileParam{},
		},
	)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", notificationProfile.Data)
返回参数:
created_at
(日期时间)、
id
(字符串)、
name
(字符串)、
updated_at
(日期时间)

Delete a notification profile

删除通知配置文件

Delete a notification profile.
DELETE /notification_profiles/{id}
go
	notificationProfile, err := client.NotificationProfiles.Delete(context.Background(), "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", notificationProfile.Data)
Returns:
created_at
(date-time),
id
(string),
name
(string),
updated_at
(date-time)
删除指定的通知配置文件。
DELETE /notification_profiles/{id}
go
	notificationProfile, err := client.NotificationProfiles.Delete(context.Background(), "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", notificationProfile.Data)
返回参数:
created_at
(日期时间)、
id
(字符串)、
name
(字符串)、
updated_at
(日期时间)

List notification settings

列出通知设置

List notification settings.
GET /notification_settings
go
	page, err := client.NotificationSettings.List(context.Background(), telnyx.NotificationSettingListParams{})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", page)
Returns:
associated_record_type
(string),
associated_record_type_value
(string),
created_at
(date-time),
id
(string),
notification_channel_id
(string),
notification_event_condition_id
(string),
notification_profile_id
(string),
parameters
(array[object]),
status
(enum: enabled, enable-received, enable-pending, enable-submitted, delete-received, delete-pending, delete-submitted, deleted),
updated_at
(date-time)
列出所有通知设置。
GET /notification_settings
go
	page, err := client.NotificationSettings.List(context.Background(), telnyx.NotificationSettingListParams{})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", page)
返回参数:
associated_record_type
(字符串)、
associated_record_type_value
(字符串)、
created_at
(日期时间)、
id
(字符串)、
notification_channel_id
(字符串)、
notification_event_condition_id
(字符串)、
notification_profile_id
(字符串)、
parameters
(对象数组)、
status
(枚举值:enabled, enable-received, enable-pending, enable-submitted, delete-received, delete-pending, delete-submitted, deleted)、
updated_at
(日期时间)

Add a Notification Setting

添加通知设置

Add a notification setting.
POST /notification_settings
Optional:
associated_record_type
(string),
associated_record_type_value
(string),
created_at
(date-time),
id
(string),
notification_channel_id
(string),
notification_event_condition_id
(string),
notification_profile_id
(string),
parameters
(array[object]),
status
(enum: enabled, enable-received, enable-pending, enable-submitted, delete-received, delete-pending, delete-submitted, deleted),
updated_at
(date-time)
go
	notificationSetting, err := client.NotificationSettings.New(context.Background(), telnyx.NotificationSettingNewParams{})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", notificationSetting.Data)
Returns:
associated_record_type
(string),
associated_record_type_value
(string),
created_at
(date-time),
id
(string),
notification_channel_id
(string),
notification_event_condition_id
(string),
notification_profile_id
(string),
parameters
(array[object]),
status
(enum: enabled, enable-received, enable-pending, enable-submitted, delete-received, delete-pending, delete-submitted, deleted),
updated_at
(date-time)
新增一条通知设置。
POST /notification_settings
可选参数:
associated_record_type
(字符串)、
associated_record_type_value
(字符串)、
created_at
(日期时间)、
id
(字符串)、
notification_channel_id
(字符串)、
notification_event_condition_id
(字符串)、
notification_profile_id
(字符串)、
parameters
(对象数组)、
status
(枚举值:enabled, enable-received, enable-pending, enable-submitted, delete-received, delete-pending, delete-submitted, deleted)、
updated_at
(日期时间)
go
	notificationSetting, err := client.NotificationSettings.New(context.Background(), telnyx.NotificationSettingNewParams{})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", notificationSetting.Data)
返回参数:
associated_record_type
(字符串)、
associated_record_type_value
(字符串)、
created_at
(日期时间)、
id
(字符串)、
notification_channel_id
(字符串)、
notification_event_condition_id
(字符串)、
notification_profile_id
(字符串)、
parameters
(对象数组)、
status
(枚举值:enabled, enable-received, enable-pending, enable-submitted, delete-received, delete-pending, delete-submitted, deleted)、
updated_at
(日期时间)

Get a notification setting

获取单个通知设置

Get a notification setting.
GET /notification_settings/{id}
go
	notificationSetting, err := client.NotificationSettings.Get(context.Background(), "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", notificationSetting.Data)
Returns:
associated_record_type
(string),
associated_record_type_value
(string),
created_at
(date-time),
id
(string),
notification_channel_id
(string),
notification_event_condition_id
(string),
notification_profile_id
(string),
parameters
(array[object]),
status
(enum: enabled, enable-received, enable-pending, enable-submitted, delete-received, delete-pending, delete-submitted, deleted),
updated_at
(date-time)
查询指定通知设置的详情。
GET /notification_settings/{id}
go
	notificationSetting, err := client.NotificationSettings.Get(context.Background(), "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", notificationSetting.Data)
返回参数:
associated_record_type
(字符串)、
associated_record_type_value
(字符串)、
created_at
(日期时间)、
id
(字符串)、
notification_channel_id
(字符串)、
notification_event_condition_id
(字符串)、
notification_profile_id
(字符串)、
parameters
(对象数组)、
status
(枚举值:enabled, enable-received, enable-pending, enable-submitted, delete-received, delete-pending, delete-submitted, deleted)、
updated_at
(日期时间)

Delete a notification setting

删除通知设置

Delete a notification setting.
DELETE /notification_settings/{id}
go
	notificationSetting, err := client.NotificationSettings.Delete(context.Background(), "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", notificationSetting.Data)
Returns:
associated_record_type
(string),
associated_record_type_value
(string),
created_at
(date-time),
id
(string),
notification_channel_id
(string),
notification_event_condition_id
(string),
notification_profile_id
(string),
parameters
(array[object]),
status
(enum: enabled, enable-received, enable-pending, enable-submitted, delete-received, delete-pending, delete-submitted, deleted),
updated_at
(date-time)
删除指定的通知设置。
DELETE /notification_settings/{id}
go
	notificationSetting, err := client.NotificationSettings.Delete(context.Background(), "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", notificationSetting.Data)
返回参数:
associated_record_type
(字符串)、
associated_record_type_value
(字符串)、
created_at
(日期时间)、
id
(字符串)、
notification_channel_id
(字符串)、
notification_event_condition_id
(字符串)、
notification_profile_id
(字符串)、
parameters
(对象数组)、
status
(枚举值:enabled, enable-received, enable-pending, enable-submitted, delete-received, delete-pending, delete-submitted, deleted)、
updated_at
(日期时间)