SuperAPI AI 工具集

telnyx-account-notifications-ruby

编程与开发

查看项目

更新于 10-16 04:47

技能介绍

用途

Telnyx Account Notifications - Ruby 用于在 Ruby 应用中配置 Telnyx 账户的告警与事件通知,包括设置推送渠道以及通知相关的配置结构。该技能以 telnyx Ruby SDK 为基础,提供可直接参考的调用示例。

安装与初始化

安装命令:

gem install telnyx

初始化客户端:

require "telnyx"

client = Telnyx::Client.new( api_key: ENV["TELNYX_API_KEY"], # This is the default and can be omitted )

文档中所有示例均假定 client 已按上述方式初始化。

主要能力

该技能覆盖以下几类资源的管理:

通知渠道(notification channels)

  • 列出通知渠道:GET /notification_channels
  • 创建通知渠道:POST /notification_channels
  • 获取单个通知渠道:GET /notification_channels/{id}
  • 更新通知渠道:PATCH /notification_channels/{id}
  • 删除通知渠道:DELETE /notification_channels/{id}

渠道返回字段包括 channel_destination(字符串)、channel_type_id(枚举:sms、voice、email、webhook)、created_at、id、notification_profile_id、updated_at。创建渠道的示例:

notification_channel = client.notification_channels.create(channel_type_id: "webhook", channel_destination: "https://example.com/webhooks") puts(notification_channel)

通知事件与事件条件

  • 列出所有通知事件条件:GET /notification_event_conditions,返回字段包括 allow_multiple_channels、associated_record_type(枚举:account、phone_number)、asynchronous、created_at、description、enabled、id、name、notification_event_id、parameters、supported_channels、updated_at。
  • 列出所有通知事件:GET /notification_events,返回字段包括 created_at、enabled、id、name、notification_category、updated_at。

通知配置文件(notification profiles)

  • 列出通知配置文件:GET /notification_profiles
  • 创建通知配置文件:POST /notification_profiles
  • 获取通知配置文件:GET /notification_profiles/{id}
  • 更新通知配置文件:PATCH /notification_profiles/{id}
  • 删除通知配置文件:DELETE /notification_profiles/{id}

配置文件字段包括 created_at、id、name、updated_at。创建示例:

notification_profile = client.notification_profiles.create(name: "My Notification Profile") puts(notification_profile)

通知设置(notification settings)

  • 列出通知设置:GET /notification_settings
  • 添加通知设置:POST /notification_settings
  • 获取通知设置:GET /notification_settings/{id}
  • 删除通知设置:DELETE /notification_settings/{id}

通知设置字段包括 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。添加示例:

notification_setting = client.notification_settings.create puts(notification_setting)

使用方式

所有 API 调用均通过已初始化的 client 对象完成,资源方法名采用下划线风格,如 client.notification_channels.list、client.notification_profiles.create、client.notification_settings.retrieve。读取单条资源时传入 id,例如:

notification_channel = client.notification_channels.retrieve("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")

列表分页可使用 auto_paging_each 自动遍历:

page.auto_paging_each { |item| puts item.id }

错误处理

文档强调生产代码应处理以下错误:

  • Telnyx::Errors::APIConnectionError:网络错误,检查连接并重试。
  • Telnyx::Errors::RateLimitError:429 限流,等待后按指数退避重试;可检查 Retry-After 头获取实际延迟。
  • Telnyx::Errors::APIStatusError:返回状态码与消息,422 通常为校验错误,需检查必填字段和格式。

常见错误码:401 无效 API 密钥,403 权限不足,404 资源不存在,422 校验错误,429 限流。

适用场景

适合需要在 Ruby 项目中以代码方式管理 Telnyx 账户告警通知的开发者,例如批量创建 Webhook 通知渠道、按账户或电话号码维度组织通知配置文件、组合渠道与事件条件生成通知设置,并在应用中统一处理限流与认证错误。

限制

该技能文档未提供收费、价格、平台限制或具体业务效果等信息。分页、错误码和字段说明以文档所列为准,未提及的行为暂未提供说明。