用途:在 Telnyx 呼叫中采集用户输入。可通过标准 gather 收集 DTMF 按键,或用 AI 驱动的 gather 由语音助手按 JSON Schema 采集语音信息,用于交互式语音菜单和 AI 语音助手。
安装与初始化:go get github.com/team-telnyx/telnyx-go;用 telnyx.NewClient 配合 option.WithAPIKey(os.Getenv("TELNYX_API_KEY")) 初始化客户端。
主要能力与接口:Gather 采集 DTMF,可设 valid_digits、最小/最大位数、超时与终止键,须先执行 Answer;Gather stop 停止采集。Gather using AI 按请求中的 parameters(JSON Schema)采集语音信息,返回 conversation_id 和 result。Gather using audio 播放音频文件直至收到 DTMF;Gather using speak 将文本转为语音播放并等待按键,必填 voice、payload,可选语言、重试次数、invalid_payload 等。另提供 AI 助手的启动、停止和向会话添加消息接口。
错误与 Webhook:需处理 401、403、404、422、429 等错误,429 可指数退避重试。Webhook 使用 Ed25519 签名,请求带 telnyx-signature-ed25519 与 telnyx-timestamp 头,用 client.Webhooks.Unwrap(body, r.Header) 校验。事件包括 CallAIGatherEnded、CallAIGatherMessageHistoryUpdated、CallAIGatherPartialResults、callGatherEnded;采集结束状态可能为 valid、invalid、call_hangup、cancelled、cancelled_amd、timeout。
适用场景:电话 IVR、按键菜单、AI 语音助手信息收集。
限制:需有效 Telnyx API Key 与已配置的呼叫控制;Gather 须在 Answer 之后调用;价格与配额资料未提供。