SuperAPI AI 工具集

telnyx-verify-go

安全与审计

查看项目

更新于 10-16 03:56

技能介绍

Telnyx Verify - Go 是 Telnyx 团队提供的 Go 语言 SDK 技能,围绕电话号码数据查询与用户验证两大用途,给出可直接运行的调用示例。

【用途】 该技能用于两类场景:一是查询电话号码信息(来电者名称、运营商、国家代码、号码格式、可携号转网情况、欺诈标记等),用于数据富化;二是通过短信、语音呼叫、Flash Call 或 WhatsApp 发送一次性验证码(OTP),并校验用户提交的验证码,用于用户注册、登录与风控等身份验证流程。

【安装与初始化】 安装命令为:go get github.com/team-telnyx/telnyx-go。初始化客户端时引入 github.com/team-telnyx/telnyx-go 与 github.com/team-telnyx/telnyx-go/option,通过 option.WithAPIKey(os.Getenv("TELNYX_API_KEY")) 传入 API Key。示例均假设 client 已按此方式初始化。

【主要能力】

  1. 号码查询:GET /number_lookup/{phone_number},返回 caller_name、carrier、country_code、fraud、national_format、phone_number、portability、record_type。
  2. 按号码列出验证记录:GET /verifications/by_phone_number/{phone_number},返回 created_at、custom_code、id、phone_number、record_type、status(pending、accepted、invalid、expired、error)、timeout_secs、type(sms、call、flashcall、whatsapp)、updated_at、verify_profile_id。
  3. 按号码校验验证码:POST /verifications/by_phone_number/{phone_number}/actions/verify,必填 code 与 verify_profile_id,返回 phone_number 与 response_code(accepted、rejected)。
  4. 触发验证:分别对应 POST /verifications/call(可选 custom_code、extension、timeout_secs)、POST /verifications/flashcall(可选 timeout_secs)、POST /verifications/sms(可选 custom_code、timeout_secs)、POST /verifications/whatsapp(可选 custom_code、timeout_secs);四者必填项均为 phone_number 与 verify_profile_id,返回结构一致。
  5. 按 ID 获取验证记录:GET /verifications/{verification_id};按 ID 校验:POST /verifications/{verification_id}/actions/verify,可选 code 或 status(accepted、rejected)。
  6. Verify Profile 管理:GET /verify_profiles 分页列表、POST /verify_profiles 创建(必填 name,可选 call、daily_spend_limit、daily_spend_limit_enabled、flashcall、language、sms、webhook_failover_url、webhook_url、whatsapp)、GET /verify_profiles/{verify_profile_id} 获取、PATCH 更新、DELETE 删除。
  7. 消息模板管理:GET /verify_profiles/templates 列出模板,POST /verify_profiles/templates 创建(必填 text,支持 {{app_name}}、{{code}} 占位符),PATCH /verify_profiles/templates/{template_id} 更新(必填 text)。

【使用方式与注意事项】 电话号码必须使用 E.164 格式,例如 +13125550001,包含 + 前缀与国家代码,不能有空格、短横线或括号。API 调用可能失败于网络错误、限流(429)、校验错误(422)或鉴权错误(401),示例建议在生产代码中用 errors.As 判断 *telnyx.Error 并按状态码分支处理,429 时配合指数退避重试。常见错误码含义:401 无效 API Key、403 权限不足、404 资源不存在、422 字段格式校验失败、429 触发限流。分页场景可使用 ListAutoPaging() 自动迭代:iter := client.Resource.ListAutoPaging(ctx, params); for iter.Next() { item := iter.Current() }。

【适用场景与限制】 适用于在 Go 后端为应用加入手机号验证、OTP 二次校验、电话号码信息补全等能力。文档未提供关于收费、价格、平台范围、服务可用国家或具体效果的信息,暂未提供;使用前需自行获取 Telnyx API Key。