telnyx-voice-gather-ruby
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 Voice Gather - Ruby
Telnyx 语音收集 - Ruby版
Installation
安装
bash
gem install telnyxbash
gem install telnyxSetup
初始化设置
ruby
require "telnyx"
client = Telnyx::Client.new(
api_key: ENV["TELNYX_API_KEY"], # This is the default and can be omitted
)All examples below assume is already initialized as shown above.
clientruby
require "telnyx"
client = Telnyx::Client.new(
api_key: ENV["TELNYX_API_KEY"], # 这是默认配置,可省略
)以下所有示例均假设已按照上述方式完成初始化。
clientAdd messages to AI Assistant
为AI助手添加消息
Add messages to the conversation started by an AI assistant on the call.
POST /calls/{call_control_id}/actions/ai_assistant_add_messagesOptional: (string), (string), (array[object])
client_statecommand_idmessagesruby
response = client.calls.actions.add_ai_assistant_messages("call_control_id")
puts(response)为通话中AI助手发起的对话添加消息。
POST /calls/{call_control_id}/actions/ai_assistant_add_messages可选参数:(字符串)、(字符串)、(对象数组)
client_statecommand_idmessagesruby
response = client.calls.actions.add_ai_assistant_messages("call_control_id")
puts(response)Start AI Assistant
启动AI助手
Start an AI assistant on the call.
POST /calls/{call_control_id}/actions/ai_assistant_startOptional: (object), (string), (string), (string), (object), (object), (string), (object)
assistantclient_statecommand_idgreetinginterruption_settingstranscriptionvoicevoice_settingsruby
response = client.calls.actions.start_ai_assistant("call_control_id")
puts(response)在通话中启动AI助手。
POST /calls/{call_control_id}/actions/ai_assistant_start可选参数:(对象)、(字符串)、(字符串)、(字符串)、(对象)、(对象)、(字符串)、(对象)
assistantclient_statecommand_idgreetinginterruption_settingstranscriptionvoicevoice_settingsruby
response = client.calls.actions.start_ai_assistant("call_control_id")
puts(response)Stop AI Assistant
停止AI助手
Stop an AI assistant on the call.
POST /calls/{call_control_id}/actions/ai_assistant_stopOptional: (string), (string)
client_statecommand_idruby
response = client.calls.actions.stop_ai_assistant("call_control_id")
puts(response)在通话中停止AI助手。
POST /calls/{call_control_id}/actions/ai_assistant_stop可选参数:(字符串)、(字符串)
client_statecommand_idruby
response = client.calls.actions.stop_ai_assistant("call_control_id")
puts(response)Gather stop
停止收集
Stop current gather.
POST /calls/{call_control_id}/actions/gather_stopOptional: (string), (string)
client_statecommand_idruby
response = client.calls.actions.stop_gather("call_control_id")
puts(response)停止当前的收集操作。
POST /calls/{call_control_id}/actions/gather_stop可选参数:(字符串)、(字符串)
client_statecommand_idruby
response = client.calls.actions.stop_gather("call_control_id")
puts(response)Gather using AI
使用AI进行收集
Gather parameters defined in the request payload using a voice assistant.
POST /calls/{call_control_id}/actions/gather_using_aiparametersOptional: (object), (string), (string), (string), (string), (object), (object), (array[object]), (boolean), (boolean), (object), (integer), (string), (object)
assistantclient_statecommand_idgather_ended_speechgreetinginterruption_settingslanguagemessage_historysend_message_history_updatessend_partial_resultstranscriptionuser_response_timeout_msvoicevoice_settingsruby
response = client.calls.actions.gather_using_ai(
"call_control_id",
parameters: {properties: "bar", required: "bar", type: "bar"}
)
puts(response)通过语音助手收集请求负载中定义的参数。
POST /calls/{call_control_id}/actions/gather_using_aiparameters可选参数:(对象)、(字符串)、(字符串)、(字符串)、(字符串)、(对象)、(对象)、(对象数组)、(布尔值)、(布尔值)、(对象)、(整数)、(字符串)、(对象)
assistantclient_statecommand_idgather_ended_speechgreetinginterruption_settingslanguagemessage_historysend_message_history_updatessend_partial_resultstranscriptionuser_response_timeout_msvoicevoice_settingsruby
response = client.calls.actions.gather_using_ai(
"call_control_id",
parameters: {properties: "bar", required: "bar", type: "bar"}
)
puts(response)Gather using audio
使用音频进行收集
Play an audio file on the call until the required DTMF signals are gathered to build interactive menus.
POST /calls/{call_control_id}/actions/gather_using_audioOptional: (string), (string), (string), (int32), (string), (string), (int32), (int32), (string), (int32), (string), (int32), (string)
audio_urlclient_statecommand_idinter_digit_timeout_millisinvalid_audio_urlinvalid_media_namemaximum_digitsmaximum_triesmedia_nameminimum_digitsterminating_digittimeout_millisvalid_digitsruby
response = client.calls.actions.gather_using_audio("call_control_id")
puts(response)在通话中播放音频文件,直到收集到所需的DTMF信号,以此构建交互式菜单。
POST /calls/{call_control_id}/actions/gather_using_audio可选参数:(字符串)、(字符串)、(字符串)、(32位整数)、(字符串)、(字符串)、(32位整数)、(32位整数)、(字符串)、(32位整数)、(字符串)、(32位整数)、(字符串)
audio_urlclient_statecommand_idinter_digit_timeout_millisinvalid_audio_urlinvalid_media_namemaximum_digitsmaximum_triesmedia_nameminimum_digitsterminating_digittimeout_millisvalid_digitsruby
response = client.calls.actions.gather_using_audio("call_control_id")
puts(response)Gather using speak
使用语音播报进行收集
Convert text to speech and play it on the call until the required DTMF signals are gathered to build interactive menus.
POST /calls/{call_control_id}/actions/gather_using_speakvoicepayloadOptional: (string), (string), (int32), (string), (enum), (int32), (int32), (int32), (enum), (enum), (string), (int32), (string), (object)
client_statecommand_idinter_digit_timeout_millisinvalid_payloadlanguagemaximum_digitsmaximum_triesminimum_digitspayload_typeservice_levelterminating_digittimeout_millisvalid_digitsvoice_settingsruby
response = client.calls.actions.gather_using_speak("call_control_id", payload: "say this on call", voice: "male")
puts(response)将文本转换为语音并在通话中播放,直到收集到所需的DTMF信号,以此构建交互式菜单。
POST /calls/{call_control_id}/actions/gather_using_speakvoicepayload可选参数:(字符串)、(字符串)、(32位整数)、(字符串)、(枚举值)、(32位整数)、(32位整数)、(32位整数)、(枚举值)、(枚举值)、(字符串)、(32位整数)、(字符串)、(对象)
client_statecommand_idinter_digit_timeout_millisinvalid_payloadlanguagemaximum_digitsmaximum_triesminimum_digitspayload_typeservice_levelterminating_digittimeout_millisvalid_digitsvoice_settingsruby
response = client.calls.actions.gather_using_speak("call_control_id", payload: "say this on call", voice: "male")
puts(response)Gather
基础收集
Gather DTMF signals to build interactive menus.
POST /calls/{call_control_id}/actions/gatherOptional: (string), (string), (string), (int32), (int32), (int32), (int32), (string), (int32), (string)
client_statecommand_idgather_idinitial_timeout_millisinter_digit_timeout_millismaximum_digitsminimum_digitsterminating_digittimeout_millisvalid_digitsruby
response = client.calls.actions.gather("call_control_id")
puts(response)收集DTMF信号以构建交互式菜单。
POST /calls/{call_control_id}/actions/gather可选参数:(字符串)、(字符串)、(字符串)、(32位整数)、(32位整数)、(32位整数)、(32位整数)、(字符串)、(32位整数)、(字符串)
client_statecommand_idgather_idinitial_timeout_millisinter_digit_timeout_millismaximum_digitsminimum_digitsterminating_digittimeout_millisvalid_digitsruby
response = client.calls.actions.gather("call_control_id")
puts(response)Webhooks
Webhook
The following webhook events are sent to your configured webhook URL.
All webhooks include and headers for verification (Standard Webhooks compatible).
telnyx-timestamptelnyx-signature-ed25519| Event | Description |
|---|---|
| Call Gather Ended |
| Call AI Gather Ended |
| Call AI Gather Message History Updated |
| Call AI Gather Partial Results |
| Call Conversation Ended |
| Call Playback Started |
| Call Playback Ended |
| Call Dtmf Received |
以下Webhook事件将发送至您配置的Webhook URL。所有Webhook均包含和头部用于验证(兼容标准Webhook)。
telnyx-timestamptelnyx-signature-ed25519| 事件 | 描述 |
|---|---|
| 语音收集结束 |
| AI语音收集结束 |
| AI语音收集消息历史更新 |
| AI语音收集部分结果 |
| 通话对话结束 |
| 语音播放开始 |
| 语音播放结束 |
| 收到DTMF信号 |
Webhook payload fields
Webhook 负载字段
callGatherEnded| Field | Type | Description |
|---|---|---|
| enum | Identifies the type of the resource. |
| enum | The type of event being delivered. |
| uuid | Identifies the type of resource. |
| date-time | ISO 8601 datetime of when the event occurred. |
| string | Call ID used to issue commands via Call Control API. |
| string | Call Control App ID (formerly Telnyx connection ID) used in the call. |
| string | ID that is unique to the call and can be used to correlate webhook events. |
| string | ID that is unique to the call session and can be used to correlate webhook events. |
| string | State received from a command. |
| string | Number or SIP URI placing the call. |
| string | Destination number or SIP URI of the call. |
| string | The received DTMF digit or symbol. |
| enum | Reflects how command ended. |
CallAIGatherEnded| Field | Type | Description |
|---|---|---|
| enum | Identifies the type of the resource. |
| enum | The type of event being delivered. |
| uuid | Identifies the type of resource. |
| date-time | ISO 8601 datetime of when the event occurred. |
| string | Call ID used to issue commands via Call Control API. |
| string | Telnyx connection ID used in the call. |
| string | ID that is unique to the call and can be used to correlate webhook events. |
| string | ID that is unique to the call session and can be used to correlate webhook events. |
| string | State received from a command. |
| string | Number or SIP URI placing the call. |
| string | Destination number or SIP URI of the call. |
| array[object] | The history of the messages exchanged during the AI gather |
| object | The result of the AI gather, its type depends of the |
| enum | Reflects how command ended. |
CallAIGatherMessageHistoryUpdated| Field | Type | Description |
|---|---|---|
| enum | Identifies the type of the resource. |
| enum | The type of event being delivered. |
| uuid | Identifies the type of resource. |
| date-time | ISO 8601 datetime of when the event occurred. |
| string | Call ID used to issue commands via Call Control API. |
| string | Telnyx connection ID used in the call. |
| string | ID that is unique to the call and can be used to correlate webhook events. |
| string | ID that is unique to the call session and can be used to correlate webhook events. |
| string | State received from a command. |
| string | Number or SIP URI placing the call. |
| string | Destination number or SIP URI of the call. |
| array[object] | The history of the messages exchanged during the AI gather |
CallAIGatherPartialResults| Field | Type | Description |
|---|---|---|
| enum | Identifies the type of the resource. |
| enum | The type of event being delivered. |
| uuid | Identifies the type of resource. |
| date-time | ISO 8601 datetime of when the event occurred. |
| string | Call ID used to issue commands via Call Control API. |
| string | Telnyx connection ID used in the call. |
| string | ID that is unique to the call and can be used to correlate webhook events. |
| string | ID that is unique to the call session and can be used to correlate webhook events. |
| string | State received from a command. |
| string | Number or SIP URI placing the call. |
| string | Destination number or SIP URI of the call. |
| array[object] | The history of the messages exchanged during the AI gather |
| object | The partial result of the AI gather, its type depends of the |
CallConversationEnded| Field | Type | Description |
|---|---|---|
| enum | Identifies the type of the resource. |
| enum | The type of event being delivered. |
| uuid | Unique identifier for the event. |
| date-time | ISO 8601 datetime of when the event occurred. |
| date-time | Timestamp when the event was created in the system. |
| string | Unique identifier of the assistant involved in the call. |
| string | Call ID used to issue commands via Call Control API. |
| string | Call Control App ID (formerly Telnyx connection ID) used in the call. |
| string | ID that is unique to the call leg. |
| string | ID that is unique to the call session (group of related call legs). |
| string | Base64-encoded state received from a command. |
| enum | The type of calling party connection. |
| string | ID unique to the conversation or insight group generated for the call. |
| integer | Duration of the conversation in seconds. |
| string | The caller's number or identifier. |
| string | The callee's number or SIP address. |
| string | The large language model used during the conversation. |
| string | The speech-to-text model used in the conversation. |
| string | The text-to-speech provider used in the call. |
| string | The model ID used for text-to-speech synthesis. |
| string | Voice ID used for TTS. |
callPlaybackStarted| Field | Type | Description |
|---|---|---|
| enum | Identifies the type of the resource. |
| enum | The type of event being delivered. |
| uuid | Identifies the type of resource. |
| date-time | ISO 8601 datetime of when the event occurred. |
| string | Call ID used to issue commands via Call Control API. |
| string | Call Control App ID (formerly Telnyx connection ID) used in the call. |
| string | ID that is unique to the call and can be used to correlate webhook events. |
| string | ID that is unique to the call session and can be used to correlate webhook events. |
| string | State received from a command. |
| string | The audio URL being played back, if audio_url has been used to start. |
| string | The name of the audio media file being played back, if media_name has been used to start. |
| boolean | Whether the audio is going to be played in overlay mode or not. |
callPlaybackEnded| Field | Type | Description |
|---|---|---|
| enum | Identifies the type of the resource. |
| enum | The type of event being delivered. |
| uuid | Identifies the type of resource. |
| date-time | ISO 8601 datetime of when the event occurred. |
| string | Call ID used to issue commands via Call Control API. |
| string | Call Control App ID (formerly Telnyx connection ID) used in the call. |
| string | ID that is unique to the call and can be used to correlate webhook events. |
| string | ID that is unique to the call session and can be used to correlate webhook events. |
| string | State received from a command. |
| string | The audio URL being played back, if audio_url has been used to start. |
| string | The name of the audio media file being played back, if media_name has been used to start. |
| boolean | Whether the stopped audio was in overlay mode or not. |
| enum | Reflects how command ended. |
| string | Provides details in case of failure. |
callDtmfReceived| Field | Type | Description |
|---|---|---|
| enum | Identifies the type of the resource. |
| enum | The type of event being delivered. |
| uuid | Identifies the type of resource. |
| date-time | ISO 8601 datetime of when the event occurred. |
| string | Call ID used to issue commands via Call Control API. |
| string | Identifies the type of resource. |
| string | ID that is unique to the call and can be used to correlate webhook events. |
| string | ID that is unique to the call session and can be used to correlate webhook events. |
| string | State received from a command. |
| string | Number or SIP URI placing the call. |
| string | Destination number or SIP URI of the call. |
| string | The received DTMF digit or symbol. |
callGatherEnded| 字段 | 类型 | 描述 |
|---|---|---|
| 枚举值 | 标识资源类型 |
| 枚举值 | 传递的事件类型 |
| UUID | 标识资源类型 |
| 日期时间 | 事件发生的ISO 8601格式时间 |
| 字符串 | 用于通过Call Control API下发指令的通话ID |
| 字符串 | 通话中使用的Call Control应用ID(原Telnyx连接ID) |
| 字符串 | 通话唯一标识ID,可用于关联Webhook事件 |
| 字符串 | 通话会话唯一标识ID,可用于关联Webhook事件 |
| 字符串 | 从指令中接收的状态信息 |
| 字符串 | 发起通话的号码或SIP URI |
| 字符串 | 通话的目标号码或SIP URI |
| 字符串 | 接收到的DTMF数字或符号 |
| 枚举值 | 指令的结束状态 |
CallAIGatherEnded| 字段 | 类型 | 描述 |
|---|---|---|
| 枚举值 | 标识资源类型 |
| 枚举值 | 传递的事件类型 |
| UUID | 标识资源类型 |
| 日期时间 | 事件发生的ISO 8601格式时间 |
| 字符串 | 用于通过Call Control API下发指令的通话ID |
| 字符串 | 通话中使用的Telnyx连接ID |
| 字符串 | 通话唯一标识ID,可用于关联Webhook事件 |
| 字符串 | 通话会话唯一标识ID,可用于关联Webhook事件 |
| 字符串 | 从指令中接收的状态信息 |
| 字符串 | 发起通话的号码或SIP URI |
| 字符串 | 通话的目标号码或SIP URI |
| 对象数组 | AI语音收集过程中交换的消息历史 |
| 对象 | AI语音收集的结果,其类型取决于指令中提供的 |
| 枚举值 | 指令的结束状态 |
CallAIGatherMessageHistoryUpdated| 字段 | 类型 | 描述 |
|---|---|---|
| 枚举值 | 标识资源类型 |
| 枚举值 | 传递的事件类型 |
| UUID | 标识资源类型 |
| 日期时间 | 事件发生的ISO 8601格式时间 |
| 字符串 | 用于通过Call Control API下发指令的通话ID |
| 字符串 | 通话中使用的Telnyx连接ID |
| 字符串 | 通话唯一标识ID,可用于关联Webhook事件 |
| 字符串 | 通话会话唯一标识ID,可用于关联Webhook事件 |
| 字符串 | 从指令中接收的状态信息 |
| 字符串 | 发起通话的号码或SIP URI |
| 字符串 | 通话的目标号码或SIP URI |
| 对象数组 | AI语音收集过程中交换的消息历史 |
CallAIGatherPartialResults| 字段 | 类型 | 描述 |
|---|---|---|
| 枚举值 | 标识资源类型 |
| 枚举值 | 传递的事件类型 |
| UUID | 标识资源类型 |
| 日期时间 | 事件发生的ISO 8601格式时间 |
| 字符串 | 用于通过Call Control API下发指令的通话ID |
| 字符串 | 通话中使用的Telnyx连接ID |
| 字符串 | 通话唯一标识ID,可用于关联Webhook事件 |
| 字符串 | 通话会话唯一标识ID,可用于关联Webhook事件 |
| 字符串 | 从指令中接收的状态信息 |
| 字符串 | 发起通话的号码或SIP URI |
| 字符串 | 通话的目标号码或SIP URI |
| 对象数组 | AI语音收集过程中交换的消息历史 |
| 对象 | AI语音收集的部分结果,其类型取决于指令中提供的 |
CallConversationEnded| 字段 | 类型 | 描述 |
|---|---|---|
| 枚举值 | 标识资源类型 |
| 枚举值 | 传递的事件类型 |
| UUID | 事件的唯一标识 |
| 日期时间 | 事件发生的ISO 8601格式时间 |
| 日期时间 | 事件在系统中创建的时间戳 |
| 字符串 | 通话中涉及的助手唯一标识 |
| 字符串 | 用于通过Call Control API下发指令的通话ID |
| 字符串 | 通话中使用的Call Control应用ID(原Telnyx连接ID) |
| 字符串 | 通话支路的唯一标识ID |
| 字符串 | 通话会话的唯一标识ID(相关通话支路的组) |
| 字符串 | 从指令中接收的Base64编码状态信息 |
| 枚举值 | 主叫方连接类型 |
| 字符串 | 通话生成的对话或洞察组的唯一标识ID |
| 整数 | 对话持续时长(秒) |
| 字符串 | 主叫号码或标识 |
| 字符串 | 被叫号码或SIP地址 |
| 字符串 | 对话中使用的大语言模型 |
| 字符串 | 对话中使用的语音转文本模型 |
| 字符串 | 通话中使用的文本转语音服务商 |
| 字符串 | 文本转语音合成使用的模型ID |
| 字符串 | 文本转语音使用的语音ID |
callPlaybackStarted| 字段 | 类型 | 描述 |
|---|---|---|
| 枚举值 | 标识资源类型 |
| 枚举值 | 传递的事件类型 |
| UUID | 标识资源类型 |
| 日期时间 | 事件发生的ISO 8601格式时间 |
| 字符串 | 用于通过Call Control API下发指令的通话ID |
| 字符串 | 通话中使用的Call Control应用ID(原Telnyx连接ID) |
| 字符串 | 通话唯一标识ID,可用于关联Webhook事件 |
| 字符串 | 通话会话唯一标识ID,可用于关联Webhook事件 |
| 字符串 | 从指令中接收的状态信息 |
| 字符串 | 正在播放的音频URL(若使用audio_url启动播放) |
| 字符串 | 正在播放的音频媒体文件名(若使用media_name启动播放) |
| 布尔值 | 是否以叠加模式播放音频 |
callPlaybackEnded| 字段 | 类型 | 描述 |
|---|---|---|
| 枚举值 | 标识资源类型 |
| 枚举值 | 传递的事件类型 |
| UUID | 标识资源类型 |
| 日期时间 | 事件发生的ISO 8601格式时间 |
| 字符串 | 用于通过Call Control API下发指令的通话ID |
| 字符串 | 通话中使用的Call Control应用ID(原Telnyx连接ID) |
| 字符串 | 通话唯一标识ID,可用于关联Webhook事件 |
| 字符串 | 通话会话唯一标识ID,可用于关联Webhook事件 |
| 字符串 | 从指令中接收的状态信息 |
| 字符串 | 正在播放的音频URL(若使用audio_url启动播放) |
| 字符串 | 正在播放的音频媒体文件名(若使用media_name启动播放) |
| 布尔值 | 已停止的音频是否为叠加模式 |
| 枚举值 | 指令的结束状态 |
| 字符串 | 失败时提供详细信息 |
callDtmfReceived| 字段 | 类型 | 描述 |
|---|---|---|
| 枚举值 | 标识资源类型 |
| 枚举值 | 传递的事件类型 |
| UUID | 标识资源类型 |
| 日期时间 | 事件发生的ISO 8601格式时间 |
| 字符串 | 用于通过Call Control API下发指令的通话ID |
| 字符串 | 标识资源类型 |
| 字符串 | 通话唯一标识ID,可用于关联Webhook事件 |
| 字符串 | 通话会话唯一标识ID,可用于关联Webhook事件 |
| 字符串 | 从指令中接收的状态信息 |
| 字符串 | 发起通话的号码或SIP URI |
| 字符串 | 通话的目标号码或SIP URI |
| 字符串 | 接收到的DTMF数字或符号 |