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-gobash
go get github.com/team-telnyx/telnyx-goSetup
初始化配置
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 is already initialized as shown above.
clientgo
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")),
)以下所有示例均默认已按照上方代码完成初始化。
clientError 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: invalid API key, insufficient permissions,
resource not found, validation error (check field formats),
rate limited (retry with exponential backoff).
401403404422429所有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")
}
}常见错误码: 无效API密钥、 权限不足、 资源不存在、 参数校验错误(请检查字段格式)、 触发限流(请使用指数退避策略重试)。
401403404422429Important Notes
重要提示
- Pagination: Use for automatic iteration:
ListAutoPaging().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_channelsgo
page, err := client.NotificationChannels.List(context.Background(), telnyx.NotificationChannelListParams{})
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", page)Returns: (string), (enum: sms, voice, email, webhook), (date-time), (string), (string), (date-time)
channel_destinationchannel_type_idcreated_atidnotification_profile_idupdated_at列出所有通知渠道。
GET /notification_channelsgo
page, err := client.NotificationChannels.List(context.Background(), telnyx.NotificationChannelListParams{})
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", page)返回参数: (字符串)、 (枚举值:sms, voice, email, webhook)、 (日期时间)、 (字符串)、 (字符串)、 (日期时间)
channel_destinationchannel_type_idcreated_atidnotification_profile_idupdated_atCreate a notification channel
创建通知渠道
Create a notification channel.
POST /notification_channelsOptional: (string), (enum: sms, voice, email, webhook), (date-time), (string), (string), (date-time)
channel_destinationchannel_type_idcreated_atidnotification_profile_idupdated_atgo
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: (string), (enum: sms, voice, email, webhook), (date-time), (string), (string), (date-time)
channel_destinationchannel_type_idcreated_atidnotification_profile_idupdated_at新建一个通知渠道。
POST /notification_channels可选参数: (字符串)、 (枚举值:sms, voice, email, webhook)、 (日期时间)、 (字符串)、 (字符串)、 (日期时间)
channel_destinationchannel_type_idcreated_atidnotification_profile_idupdated_atgo
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)返回参数: (字符串)、 (枚举值:sms, voice, email, webhook)、 (日期时间)、 (字符串)、 (字符串)、 (日期时间)
channel_destinationchannel_type_idcreated_atidnotification_profile_idupdated_atGet 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: (string), (enum: sms, voice, email, webhook), (date-time), (string), (string), (date-time)
channel_destinationchannel_type_idcreated_atidnotification_profile_idupdated_at查询指定通知渠道的详情。
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)返回参数: (字符串)、 (枚举值:sms, voice, email, webhook)、 (日期时间)、 (字符串)、 (字符串)、 (日期时间)
channel_destinationchannel_type_idcreated_atidnotification_profile_idupdated_atUpdate a notification channel
更新通知渠道
Update a notification channel.
PATCH /notification_channels/{id}Optional: (string), (enum: sms, voice, email, webhook), (date-time), (string), (string), (date-time)
channel_destinationchannel_type_idcreated_atidnotification_profile_idupdated_atgo
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: (string), (enum: sms, voice, email, webhook), (date-time), (string), (string), (date-time)
channel_destinationchannel_type_idcreated_atidnotification_profile_idupdated_at修改指定通知渠道的配置。
PATCH /notification_channels/{id}可选参数: (字符串)、 (枚举值:sms, voice, email, webhook)、 (日期时间)、 (字符串)、 (字符串)、 (日期时间)
channel_destinationchannel_type_idcreated_atidnotification_profile_idupdated_atgo
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)返回参数: (字符串)、 (枚举值:sms, voice, email, webhook)、 (日期时间)、 (字符串)、 (字符串)、 (日期时间)
channel_destinationchannel_type_idcreated_atidnotification_profile_idupdated_atDelete 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: (string), (enum: sms, voice, email, webhook), (date-time), (string), (string), (date-time)
channel_destinationchannel_type_idcreated_atidnotification_profile_idupdated_at删除指定的通知渠道。
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)返回参数: (字符串)、 (枚举值:sms, voice, email, webhook)、 (日期时间)、 (字符串)、 (字符串)、 (日期时间)
channel_destinationchannel_type_idcreated_atidnotification_profile_idupdated_atList all Notifications Events Conditions
列出所有通知事件条件
Returns a list of your notifications events conditions.
GET /notification_event_conditionsgo
page, err := client.NotificationEventConditions.List(context.Background(), telnyx.NotificationEventConditionListParams{})
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", page)Returns: (boolean), (enum: account, phone_number), (boolean), (date-time), (string), (boolean), (string), (string), (string), (array[object]), (array[string]), (date-time)
allow_multiple_channelsassociated_record_typeasynchronouscreated_atdescriptionenabledidnamenotification_event_idparameterssupported_channelsupdated_at返回所有通知事件条件的列表。
GET /notification_event_conditionsgo
page, err := client.NotificationEventConditions.List(context.Background(), telnyx.NotificationEventConditionListParams{})
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", page)返回参数: (布尔值)、 (枚举值:account, phone_number)、 (布尔值)、 (日期时间)、 (字符串)、 (布尔值)、 (字符串)、 (字符串)、 (字符串)、 (对象数组)、 (字符串数组)、 (日期时间)
allow_multiple_channelsassociated_record_typeasynchronouscreated_atdescriptionenabledidnamenotification_event_idparameterssupported_channelsupdated_atList all Notifications Events
列出所有通知事件
Returns a list of your notifications events.
GET /notification_eventsgo
page, err := client.NotificationEvents.List(context.Background(), telnyx.NotificationEventListParams{})
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", page)Returns: (date-time), (boolean), (string), (string), (string), (date-time)
created_atenabledidnamenotification_categoryupdated_at返回所有通知事件的列表。
GET /notification_eventsgo
page, err := client.NotificationEvents.List(context.Background(), telnyx.NotificationEventListParams{})
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", page)返回参数: (日期时间)、 (布尔值)、 (字符串)、 (字符串)、 (字符串)、 (日期时间)
created_atenabledidnamenotification_categoryupdated_atList all Notifications Profiles
列出所有通知配置文件
Returns a list of your notifications profiles.
GET /notification_profilesgo
page, err := client.NotificationProfiles.List(context.Background(), telnyx.NotificationProfileListParams{})
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", page)Returns: (date-time), (string), (string), (date-time)
created_atidnameupdated_at返回所有通知配置文件的列表。
GET /notification_profilesgo
page, err := client.NotificationProfiles.List(context.Background(), telnyx.NotificationProfileListParams{})
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", page)返回参数: (日期时间)、 (字符串)、 (字符串)、 (日期时间)
created_atidnameupdated_atCreate a notification profile
创建通知配置文件
Create a notification profile.
POST /notification_profilesOptional: (date-time), (string), (string), (date-time)
created_atidnameupdated_atgo
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: (date-time), (string), (string), (date-time)
created_atidnameupdated_at新建一个通知配置文件。
POST /notification_profiles可选参数: (日期时间)、 (字符串)、 (字符串)、 (日期时间)
created_atidnameupdated_atgo
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_atidnameupdated_atGet 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: (date-time), (string), (string), (date-time)
created_atidnameupdated_at查询指定通知配置文件的详情。
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_atidnameupdated_atUpdate a notification profile
更新通知配置文件
Update a notification profile.
PATCH /notification_profiles/{id}Optional: (date-time), (string), (string), (date-time)
created_atidnameupdated_atgo
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: (date-time), (string), (string), (date-time)
created_atidnameupdated_at修改指定通知配置文件的配置。
PATCH /notification_profiles/{id}可选参数: (日期时间)、 (字符串)、 (字符串)、 (日期时间)
created_atidnameupdated_atgo
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_atidnameupdated_atDelete 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: (date-time), (string), (string), (date-time)
created_atidnameupdated_at删除指定的通知配置文件。
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_atidnameupdated_atList notification settings
列出通知设置
List notification settings.
GET /notification_settingsgo
page, err := client.NotificationSettings.List(context.Background(), telnyx.NotificationSettingListParams{})
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", page)Returns: (string), (string), (date-time), (string), (string), (string), (string), (array[object]), (enum: enabled, enable-received, enable-pending, enable-submitted, delete-received, delete-pending, delete-submitted, deleted), (date-time)
associated_record_typeassociated_record_type_valuecreated_atidnotification_channel_idnotification_event_condition_idnotification_profile_idparametersstatusupdated_at列出所有通知设置。
GET /notification_settingsgo
page, err := client.NotificationSettings.List(context.Background(), telnyx.NotificationSettingListParams{})
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", page)返回参数: (字符串)、 (字符串)、 (日期时间)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (对象数组)、 (枚举值:enabled, enable-received, enable-pending, enable-submitted, delete-received, delete-pending, delete-submitted, deleted)、 (日期时间)
associated_record_typeassociated_record_type_valuecreated_atidnotification_channel_idnotification_event_condition_idnotification_profile_idparametersstatusupdated_atAdd a Notification Setting
添加通知设置
Add a notification setting.
POST /notification_settingsOptional: (string), (string), (date-time), (string), (string), (string), (string), (array[object]), (enum: enabled, enable-received, enable-pending, enable-submitted, delete-received, delete-pending, delete-submitted, deleted), (date-time)
associated_record_typeassociated_record_type_valuecreated_atidnotification_channel_idnotification_event_condition_idnotification_profile_idparametersstatusupdated_atgo
notificationSetting, err := client.NotificationSettings.New(context.Background(), telnyx.NotificationSettingNewParams{})
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", notificationSetting.Data)Returns: (string), (string), (date-time), (string), (string), (string), (string), (array[object]), (enum: enabled, enable-received, enable-pending, enable-submitted, delete-received, delete-pending, delete-submitted, deleted), (date-time)
associated_record_typeassociated_record_type_valuecreated_atidnotification_channel_idnotification_event_condition_idnotification_profile_idparametersstatusupdated_at新增一条通知设置。
POST /notification_settings可选参数: (字符串)、 (字符串)、 (日期时间)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (对象数组)、 (枚举值:enabled, enable-received, enable-pending, enable-submitted, delete-received, delete-pending, delete-submitted, deleted)、 (日期时间)
associated_record_typeassociated_record_type_valuecreated_atidnotification_channel_idnotification_event_condition_idnotification_profile_idparametersstatusupdated_atgo
notificationSetting, err := client.NotificationSettings.New(context.Background(), telnyx.NotificationSettingNewParams{})
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", notificationSetting.Data)返回参数: (字符串)、 (字符串)、 (日期时间)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (对象数组)、 (枚举值:enabled, enable-received, enable-pending, enable-submitted, delete-received, delete-pending, delete-submitted, deleted)、 (日期时间)
associated_record_typeassociated_record_type_valuecreated_atidnotification_channel_idnotification_event_condition_idnotification_profile_idparametersstatusupdated_atGet 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: (string), (string), (date-time), (string), (string), (string), (string), (array[object]), (enum: enabled, enable-received, enable-pending, enable-submitted, delete-received, delete-pending, delete-submitted, deleted), (date-time)
associated_record_typeassociated_record_type_valuecreated_atidnotification_channel_idnotification_event_condition_idnotification_profile_idparametersstatusupdated_at查询指定通知设置的详情。
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)返回参数: (字符串)、 (字符串)、 (日期时间)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (对象数组)、 (枚举值:enabled, enable-received, enable-pending, enable-submitted, delete-received, delete-pending, delete-submitted, deleted)、 (日期时间)
associated_record_typeassociated_record_type_valuecreated_atidnotification_channel_idnotification_event_condition_idnotification_profile_idparametersstatusupdated_atDelete 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: (string), (string), (date-time), (string), (string), (string), (string), (array[object]), (enum: enabled, enable-received, enable-pending, enable-submitted, delete-received, delete-pending, delete-submitted, deleted), (date-time)
associated_record_typeassociated_record_type_valuecreated_atidnotification_channel_idnotification_event_condition_idnotification_profile_idparametersstatusupdated_at删除指定的通知设置。
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)返回参数: (字符串)、 (字符串)、 (日期时间)、 (字符串)、 (字符串)、 (字符串)、 (字符串)、 (对象数组)、 (枚举值:enabled, enable-received, enable-pending, enable-submitted, delete-received, delete-pending, delete-submitted, deleted)、 (日期时间)
associated_record_typeassociated_record_type_valuecreated_atidnotification_channel_idnotification_event_condition_idnotification_profile_idparametersstatusupdated_at