跳到正文
cccskills
免费在 GitHub 公开

telnyx-voice-streaming-ruby

Stream call audio in real-time, fork media to external destinations, and transcribe speech live. Use for real-time analytics and AI integrations. This skill provides Ruby SDK examples.

中文简介正在准备中。当前显示原文说明。

查看安装方法

包含的文件(1)

  • SKILL.md13.3 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

<!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. -->

Telnyx Voice Streaming - Ruby

Installation

gem install telnyx

Setup

require "telnyx"

client = Telnyx::Client.new(
  api_key: ENV["TELNYX_API_KEY"], # This is the default and can be omitted
  public_key: ENV["TELNYX_PUBLIC_KEY"], # Required for client.webhooks.unwrap (webhook verification)
)

All examples below assume client is already initialized as shown above.

Error 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:

begin
  result = client.messages.send_(to: "+13125550001", from: "+13125550002", text: "Hello")
rescue Telnyx::Errors::APIConnectionError
  puts "Network error — check connectivity and retry"
  raise
rescue Telnyx::Errors::RateLimitError
  # 429: rate limited — wait, then retry the request (bounded exponential backoff)
  sleep(1) # Check Retry-After header for actual delay
  # ...retry the call here (give up after a few attempts); otherwise re-raise:
  raise
rescue Telnyx::Errors::APIStatusError => e
  puts "API error #{e.status}: #{e.message}"
  if e.status == 422
    puts "Validation error — check required fields and formats"
  end
  raise # A failed request must never look like success to the caller
end

Common error codes: 401 invalid API key, 403 insufficient permissions, 404 resource not found, 422 validation error (check field formats), 429 rate limited (retry with exponential backoff).

Forking start

Call forking allows you to stream the media from a call to a specific target in realtime. This stream can be used to enable realtime audio analysis to support a variety of use cases, including fraud detection, or the creation of AI-generated audio responses. Requests must specify either the target attribute or the rx and tx attributes.

POST /calls/{call_control_id}/actions/fork_start

Optional: client_state (string), command_id (string), rx (string), stream_type (enum: decrypted), tx (string)

response = client.calls.actions.start_forking("v3:550e8400-e29b-41d4-a716-446655440000_gRU1OGRkYQ")

puts(response)

Returns: result (string)

Forking stop

Stop forking a call. Expected Webhooks:

  • call.fork.stopped

POST /calls/{call_control_id}/actions/fork_stop

Optional: client_state (string), command_id (string), stream_type (enum: raw, decrypted)

response = client.calls.actions.stop_forking("v3:550e8400-e29b-41d4-a716-446655440000_gRU1OGRkYQ")

puts(response)

Returns: result (string)

Streaming start

Start streaming the media from a call to a specific WebSocket address or Dialogflow connection in near-realtime. Audio will be delivered as base64-encoded RTP payload (raw audio), wrapped in JSON payloads. Please find more details about media streaming messages specification under the link.

POST /calls/{call_control_id}/actions/streaming_start

Optional: client_state (string), command_id (string), custom_parameters (array[object]), dialogflow_config (object), enable_dialogflow (boolean), stream_auth_token (string), stream_bidirectional_codec (enum: PCMU, PCMA, G722, OPUS, AMR-WB, L16), stream_bidirectional_mode (enum: mp3, rtp), stream_bidirectional_sampling_rate (enum: 8000, 16000, 22050, 24000, 48000), stream_bidirectional_target_legs (enum: both, self, opposite), stream_codec (enum: PCMU, PCMA, G722, OPUS, AMR-WB, L16, default), stream_track (enum: inbound_track, outbound_track, both_tracks), stream_url (string)

response = client.calls.actions.start_streaming("v3:550e8400-e29b-41d4-a716-446655440000_gRU1OGRkYQ", stream_url: "wss://example.com/audio-stream")
puts(response)

Returns: result (string)

Streaming stop

Stop streaming a call to a WebSocket. Expected Webhooks:

  • streaming.stopped

POST /calls/{call_control_id}/actions/streaming_stop

Optional: client_state (string), command_id (string), stream_id (uuid)

response = client.calls.actions.stop_streaming("v3:550e8400-e29b-41d4-a716-446655440000_gRU1OGRkYQ")

puts(response)

Returns: result (string)

Transcription start

Start real-time transcription. Transcription will stop on call hang-up, or can be initiated via the Transcription stop command. Expected Webhooks:

  • call.transcription

POST /calls/{call_control_id}/actions/transcription_start

Optional: client_state (string), command_id (string), transcription_engine (enum: Google, Telnyx, Deepgram, Azure, xAI, AssemblyAI, Speechmatics, Soniox, Parakeet, Humain, Reson8, Cohere, A, B), transcription_engine_config (object), transcription_tracks (string)

response = client.calls.actions.start_transcription("v3:550e8400-e29b-41d4-a716-446655440000_gRU1OGRkYQ")

puts(response)

Returns: result (string)

Transcription stop

Stops real-time transcription on the call. Transcription webhooks cease once the command takes effect; the call itself is unaffected.

POST /calls/{call_control_id}/actions/transcription_stop

Optional: client_state (string), command_id (string)

response = client.calls.actions.stop_transcription("v3:550e8400-e29b-41d4-a716-446655440000_gRU1OGRkYQ")

puts(response)

Returns: result (string)


Webhooks

Webhook Verification

Telnyx signs webhooks with Ed25519. Each request includes telnyx-signature-ed25519 and telnyx-timestamp headers. Always verify signatures in production:

Verification needs your account's public key (Mission Control Portal → API Keys → Public Key). The SDK reads it from TELNYX_PUBLIC_KEY (the ## Setup block above passes it explicitly); without it every valid webhook fails verification and the handler below returns 400.

# In your webhook handler (e.g., Sinatra — use raw body):
post "/webhooks" do
  payload = request.body.read
  headers = {
    "telnyx-signature-ed25519" => request.env["HTTP_TELNYX_SIGNATURE_ED25519"],
    "telnyx-timestamp" => request.env["HTTP_TELNYX_TIMESTAMP"],
  }
  begin
    event = client.webhooks.unwrap(payload, headers)
  rescue => e
    halt 400, "Invalid signature: #{e.message}"
  end
  # Signature valid — event is the parsed webhook payload
  puts "Received event: #{event.data.event_type}"
  status 200
end

The following webhook events are sent to your configured webhook URL. All webhooks include telnyx-timestamp and telnyx-signature-ed25519 headers for Ed25519 signature verification. Use client.webhooks.unwrap() to verify.

EventDescription
callForkStartedCall Fork Started
callForkStoppedCall Fork Stopped
callStreamingFailedCall Streaming Failed
callStreamingStartedCall Streaming Started
callStreamingStoppedCall Streaming Stopped
transcriptionTranscription

Webhook payload fields

callForkStarted

FieldTypeDescription
data.record_typeenum: eventIdentifies the type of the resource.
data.event_typeenum: call.fork.startedThe type of event being delivered.
data.iduuidIdentifies the type of resource.
data.occurred_atdate-timeISO 8601 datetime of when the event occurred.
data.payload.connection_idstringCall Control App ID (formerly Telnyx connection ID) used in the call.
data.payload.call_control_idstringUnique ID for controlling the call.
data.payload.call_leg_idstringID that is unique to the call and can be used to correlate webhook events.
data.payload.call_session_idstringID that is unique to the call session and can be used to correlate webhook events.
data.payload.client_statestringState received from a command.
data.payload.stream_typeenum: decryptedType of media streamed.

callForkStopped

FieldTypeDescription
data.record_typeenum: eventIdentifies the type of the resource.
data.event_typeenum: call.fork.stoppedThe type of event being delivered.
data.iduuidIdentifies the type of resource.
data.occurred_atdate-timeISO 8601 datetime of when the event occurred.
data.payload.connection_idstringCall Control App ID (formerly Telnyx connection ID) used in the call.
data.payload.call_control_idstringUnique ID for controlling the call.
data.payload.call_leg_idstringID that is unique to the call and can be used to correlate webhook events.
data.payload.call_session_idstringID that is unique to the call session and can be used to correlate webhook events.
data.payload.client_statestringState received from a command.
data.payload.stream_typeenum: decryptedType of media streamed.

callStreamingFailed

FieldTypeDescription
data.record_typeenum: eventIdentifies the resource.
data.event_typeenum: streaming.failedThe type of event being delivered.
data.iduuidIdentifies the type of resource.
data.occurred_atdate-timeISO 8601 datetime of when the event occurred.
data.payload.call_control_idstringCall ID used to issue commands via Call Control API.
data.payload.connection_idstringCall Control App ID (formerly Telnyx connection ID) used in the call.
data.payload.call_leg_idstringID that is unique to the call and can be used to correlate webhook events.
data.payload.call_session_idstringID that is unique to the call session and can be used to correlate webhook events.
data.payload.client_statestringState received from a command.
data.payload.failure_reasonstringA short description explaning why the media streaming failed.
data.payload.stream_iduuidIdentifies the streaming.
data.payload.stream_typeenum: websocket, dialogflowThe type of stream connection the stream is performing.

callStreamingStarted

FieldTypeDescription
data.record_typeenum: eventIdentifies the type of the resource.
data.event_typeenum: streaming.startedThe type of event being delivered.
data.iduuidIdentifies the type of resource.
data.occurred_atdate-timeISO 8601 datetime of when the event occurred.
data.payload.call_control_idstringCall ID used to issue commands via Call Control API.
data.payload.connection_idstringCall Control App ID (formerly Telnyx connection ID) used in the call.
data.payload.call_leg_idstringID that is unique to the call and can be used to correlate webhook events.
data.payload.call_session_idstringID that is unique to the call session and can be used to correlate webhook events.
data.payload.client_statestringState received from a command.
data.payload.stream_urlstringDestination WebSocket address where the stream is going to be delivered.

callStreamingStopped

FieldTypeDescription
data.record_typeenum: eventIdentifies the type of the resource.
data.event_typeenum: streaming.stoppedThe type of event being delivered.
data.iduuidIdentifies the type of resource.
data.occurred_atdate-timeISO 8601 datetime of when the event occurred.
data.payload.call_control_idstringCall ID used to issue commands via Call Control API.
data.payload.connection_idstringCall Control App ID (formerly Telnyx connection ID) used in the call.
data.payload.call_leg_idstringID that is unique to the call and can be used to correlate webhook events.
data.payload.call_session_idstringID that is unique to the call session and can be used to correlate webhook events.
data.payload.client_statestringState received from a command.
data.payload.stream_urlstringDestination WebSocket address where the stream is going to be delivered.

transcription

FieldTypeDescription
data.record_typeenum: eventIdentifies the type of the resource.
data.event_typeenum: call.transcriptionThe type of event being delivered.
data.iduuidIdentifies the type of resource.
data.occurred_atdate-timeISO 8601 datetime of when the event occurred.
data.payload.call_control_idstringUnique identifier and token for controlling the call.
data.payload.call_leg_idstringID that is unique to the call and can be used to correlate webhook events.
data.payload.call_session_idstringID that is unique to the call session and can be used to correlate webhook events.
data.payload.client_statestringUse this field to add state to every subsequent webhook.
data.payload.connection_idstringCall Control App ID (formerly Telnyx connection ID) used in the call.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Test VoIP push notifications for Telnyx WebRTC iOS (APNs) and Android (FCM) apps. Use when debugging push notification delivery, validating certificate/credential setup, or testing that a device receives VoIP pushes correctly.

中文简介正在准备中。当前显示原文说明。

team-telnyx/ai2222026年10月21日 更新

10DLC brand and campaign registration for US A2P messaging compliance. Assign phone numbers to campaigns.

中文简介正在准备中。当前显示原文说明。

team-telnyx/ai2222026年10月21日 更新

10DLC brand and campaign registration for US A2P messaging compliance. Assign phone numbers to campaigns.

中文简介正在准备中。当前显示原文说明。

team-telnyx/ai2222026年10月21日 更新

10DLC brand and campaign registration for US A2P messaging compliance. Assign phone numbers to campaigns.

中文简介正在准备中。当前显示原文说明。

team-telnyx/ai2222026年10月21日 更新

10DLC brand and campaign registration for US A2P messaging compliance. Assign phone numbers to campaigns.

中文简介正在准备中。当前显示原文说明。

team-telnyx/ai2222026年10月21日 更新

10DLC brand and campaign registration for US A2P messaging compliance. Assign phone numbers to campaigns.

中文简介正在准备中。当前显示原文说明。

team-telnyx/ai2222026年10月21日 更新

查看 team-telnyx 的全部技能

报告此技能的问题