Loading...
Loading...
Compare original and translation side by side
pip install telnyxpip install telnyximport os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted
)clientimport os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # 这是默认值,可省略
)clientimport telnyx
try:
response = client.calls.dial(
connection_id="7267xxxxxxxxxxxxxx",
from_="+18005550101",
to="+18005550100",
)
except telnyx.APIConnectionError:
print("Network error — check connectivity and retry")
except telnyx.RateLimitError:
import time
time.sleep(1) # Check Retry-After header for actual delay
except telnyx.APIStatusError as e:
print(f"API error {e.status_code}: {e.message}")
if e.status_code == 422:
print("Validation error — check required fields and formats")401403404422429import telnyx
try:
response = client.calls.dial(
connection_id="7267xxxxxxxxxxxxxx",
from_="+18005550101",
to="+18005550100",
)
except telnyx.APIConnectionError:
print("网络错误 — 检查连接并重试")
except telnyx.RateLimitError:
import time
time.sleep(1) # 查看Retry-After header获取实际延迟时间
except telnyx.APIStatusError as e:
print(f"API错误 {e.status_code}: {e.message}")
if e.status_code == 422:
print("验证错误 — 检查必填字段和格式")401403404422429+13125550001+for item in page_result:+13125550001+for item in page_result:dial()call_control_iddial()dial()call_control_iddial()## Additional Operations## 额外操作client.calls.dial()POST /calls| Parameter | Type | Required | Description |
|---|---|---|---|
| string (E.164) | Yes | The DID or SIP URI to dial out to. |
| string (E.164) | Yes | The |
| 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 |
response = client.calls.dial(
connection_id="7267xxxxxxxxxxxxxx",
from_="+18005550101",
to="+18005550100",
)
print(response.data)response.data.call_control_idresponse.data.call_leg_idresponse.data.call_session_idresponse.data.is_aliveresponse.data.recording_idresponse.data.call_durationclient.calls.dial()POST /calls| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| string (E.164) | 是 | 要呼出的DID或SIP URI。 |
| string (E.164) | 是 | 作为主叫号码显示给被叫方的 |
| string (UUID) | 是 | 呼叫控制应用的ID(原连接ID)。 |
| integer | 否 | Telnyx等待呼叫接通的秒数。 |
| string (UUID) | 否 | 使用此字段设置呼叫的计费组ID。 |
| string | 否 | 使用此字段为后续所有webhook添加状态信息。 |
| ... | references/api-details.md中还有48个可选参数 |
response = client.calls.dial(
connection_id="7267xxxxxxxxxxxxxx",
from_="+18005550101",
to="+18005550100",
)
print(response.data)response.data.call_control_idresponse.data.call_leg_idresponse.data.call_session_idresponse.data.is_aliveresponse.data.recording_idresponse.data.call_durationclient.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 |
response = client.calls.actions.answer(
call_control_id="550e8400-e29b-41d4-a716-446655440000",
)
print(response.data)response.data.resultresponse.data.recording_idclient.calls.actions.answer()POST /calls/{call_control_id}/actions/answer| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| string (UUID) | 是 | 用于控制呼叫的唯一标识符和令牌 |
| string (UUID) | 否 | 使用此字段设置呼叫的计费组ID。 |
| string | 否 | 使用此字段为后续所有webhook添加状态信息。 |
| string (URL) | 否 | 使用此字段覆盖Telnyx发送webhook的URL。 |
| ... | references/api-details.md中还有26个可选参数 |
response = client.calls.actions.answer(
call_control_id="550e8400-e29b-41d4-a716-446655440000",
)
print(response.data)response.data.resultresponse.data.recording_idclient.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 |
response = client.calls.actions.transfer(
call_control_id="550e8400-e29b-41d4-a716-446655440000",
to="+18005550100",
)
print(response.data)response.data.resultclient.calls.actions.transfer()POST /calls/{call_control_id}/actions/transfer| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| string (E.164) | 是 | 要转接的DID或SIP URI。 |
| string (UUID) | 是 | 用于控制呼叫的唯一标识符和令牌 |
| integer | 否 | Telnyx等待呼叫接通的秒数。 |
| string | 否 | 使用此字段为后续所有webhook添加状态信息。 |
| string (URL) | 否 | 使用此字段覆盖Telnyx发送webhook的URL。 |
| ... | references/api-details.md中还有33个可选参数 |
response = client.calls.actions.transfer(
call_control_id="550e8400-e29b-41d4-a716-446655440000",
to="+18005550100",
)
print(response.data)response.data.resulttelnyx-signature-ed25519telnyx-timestampundefinedtelnyx-signature-ed25519telnyx-timestampundefinedundefinedundefined| 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. |
| 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 ev... |
| 字段 | 类型 | 描述 |
|---|---|---|
| enum: event | 标识资源类型。 |
| enum: call.answered | 传递的事件类型。 |
| uuid | 标识资源类型。 |
| date-time | 事件发生的ISO 8601格式时间。 |
| string | 用于通过呼叫控制API发出命令的呼叫ID。 |
| string | 呼叫中使用的呼叫控制应用ID(原Telnyx连接ID)。 |
| string | 呼叫的唯一ID,可用于关联webhook事件。 |
| string | 呼叫会话的唯一ID,可用于关联webhook事件。 |
| 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. |
| 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 ev... |
| 字段 | 类型 | 描述 |
|---|---|---|
| enum: event | 标识资源类型。 |
| enum: call.hangup | 传递的事件类型。 |
| uuid | 标识资源类型。 |
| date-time | 事件发生的ISO 8601格式时间。 |
| string | 用于通过呼叫控制API发出命令的呼叫ID。 |
| string | 呼叫中使用的呼叫控制应用ID(原Telnyx连接ID)。 |
| string | 呼叫的唯一ID,可用于关联webhook事件。 |
| string | 呼叫会话的唯一ID,可用于关联webhook事件。 |
| 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. |
| 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 | The list of comma-separated codecs enabled for the connection. |
| string | The list of comma-separated codecs offered by caller. |
| 字段 | 类型 | 描述 |
|---|---|---|
| enum: event | 标识资源类型。 |
| enum: call.initiated | 传递的事件类型。 |
| uuid | 标识资源类型。 |
| date-time | 事件发生的ISO 8601格式时间。 |
| string | 用于通过呼叫控制API发出命令的呼叫ID。 |
| string | 呼叫中使用的呼叫控制应用ID(原Telnyx连接ID)。 |
| string | 连接启用的编解码器列表,用逗号分隔。 |
| string | 主叫方提供的编解码器列表,用逗号分隔。 |
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. |
response = client.calls.actions.hangup(
call_control_id="550e8400-e29b-41d4-a716-446655440000",
)
print(response.data)response.data.resultclient.calls.actions.hangup()POST /calls/{call_control_id}/actions/hangup| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| string (UUID) | 是 | 用于控制呼叫的唯一标识符和令牌 |
| string | 否 | 使用此字段为后续所有webhook添加状态信息。 |
| string (UUID) | 否 | 使用此字段避免重复命令。 |
| array[object] | 否 | 要添加到SIP BYE消息中的自定义头。 |
response = client.calls.actions.hangup(
call_control_id="550e8400-e29b-41d4-a716-446655440000",
)
print(response.data)response.data.resultclient.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 |
response = client.calls.actions.bridge(
call_control_id_to_bridge="call_control_id",
call_control_id_to_bridge_with="v3:MdI91X4lWFEs7IgbBEOT9M4AigoY08M0WWZFISt1Yw2axZ_IiE4pqg",
)
print(response.data)response.data.resultclient.calls.actions.bridge()POST /calls/{call_control_id}/actions/bridge| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| string (UUID) | 是 | 要桥接的呼叫的呼叫控制ID |
| string (UUID) | 是 | 用于控制呼叫的唯一标识符和令牌 |
| string | 否 | 使用此字段为后续所有webhook添加状态信息。 |
| string (UUID) | 否 | 使用此字段避免重复命令。 |
| string (UUID) | 否 | 要桥接的视频房间ID,不能与...同时使用 |
| ... | references/api-details.md中还有16个可选参数 |
response = client.calls.actions.bridge(
call_control_id_to_bridge="call_control_id",
call_control_id_to_bridge_with="v3:MdI91X4lWFEs7IgbBEOT9M4AigoY08M0WWZFISt1Yw2axZ_IiE4pqg",
)
print(response.data)response.data.resultclient.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. |
response = client.calls.actions.reject(
call_control_id="550e8400-e29b-41d4-a716-446655440000",
cause="USER_BUSY",
)
print(response.data)response.data.resultclient.calls.actions.reject()POST /calls/{call_control_id}/actions/reject| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| enum (CALL_REJECTED, USER_BUSY) | 是 | 拒绝呼叫的原因。 |
| string (UUID) | 是 | 用于控制呼叫的唯一标识符和令牌 |
| string | 否 | 使用此字段为后续所有webhook添加状态信息。 |
| string (UUID) | 否 | 使用此字段避免重复命令。 |
response = client.calls.actions.reject(
call_control_id="550e8400-e29b-41d4-a716-446655440000",
cause="USER_BUSY",
)
print(response.data)response.data.resultclient.calls.retrieve_status()GET /calls/{call_control_id}| Parameter | Type | Required | Description |
|---|---|---|---|
| string (UUID) | Yes | Unique identifier and token for controlling the call |
response = client.calls.retrieve_status(
"call_control_id",
)
print(response.data)response.data.call_control_idresponse.data.call_durationresponse.data.call_leg_idresponse.data.call_session_idresponse.data.client_stateresponse.data.end_timeclient.calls.retrieve_status()GET /calls/{call_control_id}| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| string (UUID) | 是 | 用于控制呼叫的唯一标识符和令牌 |
response = client.calls.retrieve_status(
"call_control_id",
)
print(response.data)response.data.call_control_idresponse.data.call_durationresponse.data.call_leg_idresponse.data.call_session_idresponse.data.client_stateresponse.data.end_timeclient.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). |
page = client.connections.list_active_calls(
connection_id="1293384261075731461",
)
page = page.data[0]
print(page.call_control_id)page.datapage.metacall_control_idcall_durationcall_leg_idcall_session_idclient_staterecord_typeclient.connections.list_active_calls()GET /connections/{connection_id}/active_calls| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| string (UUID) | 是 | Telnyx连接ID |
| object | 否 | 合并的分页参数(deepObject风格)。 |
page = client.connections.list_active_calls(
connection_id="1293384261075731461",
)
page = page.data[0]
print(page.call_control_id)page.datapage.metacall_control_idcall_durationcall_leg_idcall_session_idclient_staterecord_typeclient.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). |
page = client.call_control_applications.list()
page = page.data[0]
print(page.id)page.datapage.metaidcreated_atupdated_atactiveanchorsite_overrideapplication_nameclient.call_control_applications.list()GET /call_control_applications| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| enum (created_at, connection_name, active) | 否 | 指定结果的排序顺序。 |
| object | 否 | 合并的筛选参数(deepObject风格)。 |
| object | 否 | 合并的分页参数(deepObject风格)。 |
page = client.call_control_applications.list()
page = page.data[0]
print(page.id)page.datapage.metaidcreated_atupdated_atactiveanchorsite_overrideapplication_name| Operation | SDK method | Endpoint | Use when | Required params |
|---|---|---|---|---|
| Create a call control application | | | Create or provision an additional resource when the core tasks do not cover this flow. | |
| Retrieve a call control application | | | Fetch the current state before updating, deleting, or making control-flow decisions. | |
| Update a call control application | | | Modify an existing resource without recreating it. | |
| Delete a call control application | | | Remove, detach, or clean up an existing resource. | |
| SIP Refer a call | | | Trigger a follow-up action in an existing workflow rather than creating a new top-level resource. | |
| Send SIP info | | | Trigger a follow-up action in an existing workflow rather than creating a new top-level resource. | |
| 操作 | SDK方法 | 端点 | 使用场景 | 必填参数 |
|---|---|---|---|---|
| 创建呼叫控制应用 | | | 当核心任务无法覆盖业务流程时,创建或配置额外资源。 | |
| 查询呼叫控制应用 | | | 在更新、删除或做出控制流决策前获取当前状态。 | |
| 更新呼叫控制应用 | | | 修改现有资源,无需重新创建。 | |
| 删除呼叫控制应用 | | | 删除、分离或清理现有资源。 | |
| SIP转接呼叫 | | | 在现有工作流中触发后续操作,而非创建新的顶级资源。 | |
| 发送SIP信息 | | | 在现有工作流中触发后续操作,而非创建新的顶级资源。 | |
| Event | | Description |
|---|---|---|
| | Call Bridged |
| 事件 | | 描述 |
|---|---|---|
| | 呼叫已桥接 |