<!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. -->
Telnyx Voice - Ruby
Installation
Setup
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.
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:
ruby
response = client.calls.dial(
connection_id: "7267xxxxxxxxxxxxxx",
from: "+18005550101",
to: "+18005550100"
)
puts(response)
Common error codes:
invalid API key,
insufficient permissions,
resource not found,
validation error (check field formats),
rate limited (retry with exponential backoff).
Important Notes
- Phone numbers must be in E.164 format (e.g., ). Include the prefix and country code. No spaces, dashes, or parentheses.
- Pagination: Use for automatic iteration:
page.auto_paging_each { |item| puts item.id }
.
Operational Caveats
- Call Control is event-driven. After or an inbound webhook, issue follow-up commands from webhook handlers using the in the event payload.
- Outbound and inbound flows are different: outbound calls start with , while inbound calls must be answered from the incoming webhook before other commands run.
- A publicly reachable webhook endpoint is required for real call control. Without it, calls may connect but your application cannot drive the live call state.
Reference Use Rules
Do not invent Telnyx parameters, enums, response fields, or webhook fields.
- If the parameter, enum, or response field you need is not shown inline in this skill, read references/api-details.md before writing code.
- Before using any operation in , read the optional-parameters section and the response-schemas section.
- Before reading or matching webhook fields beyond the inline examples, read the webhook payload reference.
Core Tasks
Dial an outbound call
Primary voice entrypoint. Agents need the async call-control identifiers returned here.
| Parameter | Type | Required | Description |
|---|
| string (E.164) | Yes | The DID or SIP URI to dial out to. |
| string (E.164) | Yes | The number to be used as the caller id presented to t... |
| string (UUID) | Yes | The ID of the Call Control App (formerly ID of the connectio... |
| integer | No | The number of seconds that Telnyx will wait for the call to ... |
| string (UUID) | No | Use this field to set the Billing Group ID for the call. |
| string | No | Use this field to add state to every subsequent webhook. |
| ... | | | +48 optional params in references/api-details.md |
ruby
response = client.calls.dial(
connection_id: "7267xxxxxxxxxxxxxx",
from: "+18005550101",
to: "+18005550100"
)
puts(response)
Primary response fields:
response.data.call_control_id
response.data.call_leg_id
response.data.call_session_id
response.data.recording_id
response.data.call_duration
Answer an inbound call
Primary inbound call-control command.
client.calls.actions.answer()
—
POST /calls/{call_control_id}/actions/answer
| Parameter | Type | Required | Description |
|---|
| string (UUID) | Yes | Unique identifier and token for controlling the call |
| string (UUID) | No | Use this field to set the Billing Group ID for the call. |
| string | No | Use this field to add state to every subsequent webhook. |
| string (URL) | No | Use this field to override the URL for which Telnyx will sen... |
| ... | | | +26 optional params in references/api-details.md |
ruby
response = client.calls.actions.answer("v3:550e8400-e29b-41d4-a716-446655440000_gRU1OGRkYQ")
puts(response)
Primary response fields:
response.data.recording_id
Transfer a live call
Common post-answer control path with downstream webhook implications.
client.calls.actions.transfer()
—
POST /calls/{call_control_id}/actions/transfer
| Parameter | Type | Required | Description |
|---|
| string (E.164) | Yes | The DID or SIP URI to dial out to. |
| string (UUID) | Yes | Unique identifier and token for controlling the call |
| integer | No | The number of seconds that Telnyx will wait for the call to ... |
| string | No | Use this field to add state to every subsequent webhook. |
| string (URL) | No | Use this field to override the URL for which Telnyx will sen... |
| ... | | | +33 optional params in references/api-details.md |
ruby
response = client.calls.actions.transfer("call_control_id", to: "+18005550100")
puts(response)
Primary response fields:
Webhook Verification
Telnyx signs webhooks with Ed25519. Each request includes
and
headers. Always verify signatures in production:
ruby
# 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
Webhooks
These webhook payload fields are inline because they are part of the primary integration path.
Call Answered
| Field | Type | Description |
|---|
| enum: event | Identifies the type of the resource. |
| enum: call.answered | The type of event being delivered. |
| uuid | Identifies the type of resource. |
| date-time | ISO 8601 datetime of when the event occurred. |
data.payload.call_control_id
| string | Call ID used to issue commands via Call Control API. |
data.payload.connection_id
| 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. |
data.payload.call_session_id
| string | ID that is unique to the call session and can be used to correlate webhook ev... |
Call Hangup
| Field | Type | Description |
|---|
| enum: event | Identifies the type of the resource. |
| enum: call.hangup | The type of event being delivered. |
| uuid | Identifies the type of resource. |
| date-time | ISO 8601 datetime of when the event occurred. |
data.payload.call_control_id
| string | Call ID used to issue commands via Call Control API. |
data.payload.connection_id
| 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. |
data.payload.call_session_id
| string | ID that is unique to the call session and can be used to correlate webhook ev... |
Call Initiated
| Field | Type | Description |
|---|
| enum: event | Identifies the type of the resource. |
| enum: call.initiated | The type of event being delivered. |
| uuid | Identifies the type of resource. |
| date-time | ISO 8601 datetime of when the event occurred. |
data.payload.call_control_id
| string | Call ID used to issue commands via Call Control API. |
data.payload.connection_id
| string | Call Control App ID (formerly Telnyx connection ID) used in the call. |
data.payload.connection_codecs
| string | The list of comma-separated codecs enabled for the connection. |
data.payload.offered_codecs
| string | The list of comma-separated codecs offered by caller. |
If you need webhook fields that are not listed inline here, read the webhook payload reference before writing the handler.
Important Supporting Operations
Use these when the core tasks above are close to your flow, but you need a common variation or follow-up step.
Hangup call
End a live call from your webhook-driven control flow.
client.calls.actions.hangup()
—
POST /calls/{call_control_id}/actions/hangup
| Parameter | Type | Required | Description |
|---|
| string (UUID) | Yes | Unique identifier and token for controlling the call |
| string | No | Use this field to add state to every subsequent webhook. |
| string (UUID) | No | Use this field to avoid duplicate commands. |
| array[object] | No | Custom headers to be added to the SIP BYE message. |
ruby
response = client.calls.actions.hangup("v3:550e8400-e29b-41d4-a716-446655440000_gRU1OGRkYQ")
puts(response)
Primary response fields:
Bridge calls
Trigger a follow-up action in an existing workflow rather than creating a new top-level resource.
client.calls.actions.bridge()
—
POST /calls/{call_control_id}/actions/bridge
| Parameter | Type | Required | Description |
|---|
| string (UUID) | Yes | The Call Control ID of the call you want to bridge with, can... |
| string (UUID) | Yes | Unique identifier and token for controlling the call |
| string | No | Use this field to add state to every subsequent webhook. |
| string (UUID) | No | Use this field to avoid duplicate commands. |
| string (UUID) | No | The ID of the video room you want to bridge with, can't be u... |
| ... | | | +16 optional params in references/api-details.md |
ruby
response = client.calls.actions.bridge(
"call_control_id",
call_control_id_to_bridge_with: "v3:MdI91X4lWFEs7IgbBEOT9M4AigoY08M0WWZFISt1Yw2axZ_IiE4pqg"
)
puts(response)
Primary response fields:
Reject a call
Trigger a follow-up action in an existing workflow rather than creating a new top-level resource.
client.calls.actions.reject()
—
POST /calls/{call_control_id}/actions/reject
| Parameter | Type | Required | Description |
|---|
| enum (CALL_REJECTED, USER_BUSY) | Yes | Cause for call rejection. |
| string (UUID) | Yes | Unique identifier and token for controlling the call |
| string | No | Use this field to add state to every subsequent webhook. |
| string (UUID) | No | Use this field to avoid duplicate commands. |
ruby
response = client.calls.actions.reject("call_control_id", cause: :USER_BUSY)
puts(response)
Primary response fields:
Retrieve a call status
Fetch the current state before updating, deleting, or making control-flow decisions.
client.calls.retrieve_status()
—
GET /calls/{call_control_id}
| Parameter | Type | Required | Description |
|---|
| string (UUID) | Yes | Unique identifier and token for controlling the call |
ruby
response = client.calls.retrieve_status("v3:550e8400-e29b-41d4-a716-446655440000_gRU1OGRkYQ")
puts(response)
Primary response fields:
response.data.call_control_id
response.data.call_duration
response.data.call_leg_id
response.data.call_session_id
response.data.client_state
List all active calls for given connection
Fetch the current state before updating, deleting, or making control-flow decisions.
client.connections.list_active_calls()
—
GET /connections/{connection_id}/active_calls
| Parameter | Type | Required | Description |
|---|
| string (UUID) | Yes | Telnyx connection id |
| object | No | Consolidated page parameter (deepObject style). |
ruby
page = client.connections.list_active_calls("1293384261075731461")
puts(page)
Response wrapper:
Primary item fields:
List call control applications
Inspect available resources or choose an existing resource before mutating it.
client.call_control_applications.list()
—
GET /call_control_applications
| Parameter | Type | Required | Description |
|---|
| enum (created_at, connection_name, active) | No | Specifies the sort order for results. |
| object | No | Consolidated filter parameter (deepObject style). |
| object | No | Consolidated page parameter (deepObject style). |
ruby
page = client.call_control_applications.list
puts(page)
Response wrapper:
Primary item fields:
Additional Operations
Use the core tasks above first. The operations below are indexed here with exact SDK methods and required params; use references/api-details.md for full optional params, response schemas, and lower-frequency webhook payloads.
Before using any operation below, read the optional-parameters section and the response-schemas section so you do not guess missing fields.
| Operation | SDK method | Endpoint | Use when | Required params |
|---|
| Create a call control application | client.call_control_applications.create()
| POST /call_control_applications
| Create or provision an additional resource when the core tasks do not cover this flow. | , |
| Retrieve a call control application | client.call_control_applications.retrieve()
| GET /call_control_applications/{id}
| Fetch the current state before updating, deleting, or making control-flow decisions. | |
| Update a call control application | client.call_control_applications.update()
| PATCH /call_control_applications/{id}
| Modify an existing resource without recreating it. | , , |
| Delete a call control application | client.call_control_applications.delete()
| DELETE /call_control_applications/{id}
| Remove, detach, or clean up an existing resource. | |
| SIP Refer a call | client.calls.actions.refer()
| POST /calls/{call_control_id}/actions/refer
| Trigger a follow-up action in an existing workflow rather than creating a new top-level resource. | , |
| Send SIP info | client.calls.actions.send_sip_info()
| POST /calls/{call_control_id}/actions/send_sip_info
| Trigger a follow-up action in an existing workflow rather than creating a new top-level resource. | , , |
Other Webhook Events
| Event | | Description |
|---|
| | Call Bridged |
For exhaustive optional parameters, full response schemas, and complete webhook payloads, see references/api-details.md.