本文へ移動
cccskills
無料GitHub で公開

telnyx-voice-javascript

Programmatic call control: make/receive calls, transfer, bridge, gather DTMF, stream audio. Real-time call events via webhooks.

日本語の概要は準備中です。原文の説明を表示しています。

インストール方法を見る

含まれるファイル(2)

  • SKILL.md18.7 KB
  • references/api-details.md30.3 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

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

Telnyx Voice - JavaScript

Installation

npm install telnyx@6.74.2

Setup

import Telnyx from 'telnyx';

const client = new Telnyx({
  apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
  publicKey: process.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:

try {
  const response = await client.calls.dial({
    connection_id: '7267xxxxxxxxxxxxxx',
    from: '+18005550101',
    to: '+18005550100',
  });
} catch (err) {
  if (err instanceof Telnyx.APIConnectionError) {
    console.error('Network error — check connectivity and retry');
  } else if (err instanceof Telnyx.RateLimitError) {
    // 429: rate limited — wait, then retry the request (bounded exponential backoff)
    const retryAfter = err.headers?.['retry-after'] || 1;
    await new Promise(r => setTimeout(r, retryAfter * 1000));
    // ...retry the call here (give up after a few attempts)
  } else if (err instanceof Telnyx.APIError) {
    console.error(`API error ${err.status}: ${err.message}`);
    if (err.status === 422) {
      console.error('Validation error — check required fields and formats');
    }
  }
  throw err; // Re-throw: a failed request must never look like success to the caller
}

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).

Important Notes

  • Phone numbers must be in E.164 format (e.g., +13125550001). Include the + prefix and country code. No spaces, dashes, or parentheses.
  • Pagination: List methods return an auto-paginating iterator. Use for await (const item of result) { ... } to iterate through all pages automatically.

Operational Caveats

  • Call Control is event-driven. After dial() or an inbound webhook, issue follow-up commands from webhook handlers using the call_control_id in the event payload.
  • Outbound and inbound flows are different: outbound calls start with dial(), 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.

Core Tasks

Dial an outbound call

Primary voice entrypoint. Agents need the async call-control identifiers returned here.

client.calls.dial() — POST /calls

ParameterTypeRequiredDescription
tostring (E.164)YesThe DID or SIP URI to dial out to.
fromstring (E.164)YesThe from number to be used as the caller id presented to t...
connection_idstring (UUID)YesThe ID of the Call Control App (formerly ID of the connectio...
timeout_secsintegerNoThe number of seconds that Telnyx will wait for the call to ...
billing_group_idstring (UUID)NoUse this field to set the Billing Group ID for the call.
client_statestringNoUse this field to add state to every subsequent webhook.
...+59 optional params in references/api-details.md
const response = await client.calls.dial({
  connection_id: '7267xxxxxxxxxxxxxx',
  from: '+18005550101',
  to: '+18005550100',
});

console.log(response.data);

Primary response fields:

  • response.data.call_control_id
  • response.data.call_leg_id
  • response.data.call_session_id
  • response.data.is_alive
  • 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

ParameterTypeRequiredDescription
call_control_idstring (UUID)YesUnique identifier and token for controlling the call
billing_group_idstring (UUID)NoUse this field to set the Billing Group ID for the call.
client_statestringNoUse this field to add state to every subsequent webhook.
webhook_urlstring (URL)NoUse this field to override the URL for which Telnyx will sen...
...+29 optional params in references/api-details.md
const response = await client.calls.actions.answer('v3:550e8400-e29b-41d4-a716-446655440000_gRU1OGRkYQ');

console.log(response.data);

Primary response fields:

  • response.data.result
  • 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

ParameterTypeRequiredDescription
tostring (E.164)YesThe DID or SIP URI to dial out to.
call_control_idstring (UUID)YesUnique identifier and token for controlling the call
timeout_secsintegerNoThe number of seconds that Telnyx will wait for the call to ...
client_statestringNoUse this field to add state to every subsequent webhook.
webhook_urlstring (URL)NoUse this field to override the URL for which Telnyx will sen...
...+37 optional params in references/api-details.md
const response = await client.calls.actions.transfer('v3:550e8400-e29b-41d4-a716-446655440000_gRU1OGRkYQ', {
  to: '+18005550100',
});

console.log(response.data);

Primary response fields:

  • response.data.result

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., Express — use raw body, not parsed JSON):
app.post('/webhooks', express.raw({ type: 'application/json' }), async (req, res) => {
  try {
    const event = await client.webhooks.unwrap(req.body.toString(), {
      headers: req.headers,
    });
    // Signature valid — event is the parsed webhook payload
    console.log('Received event:', event.data.event_type);
    res.status(200).send('OK');
  } catch (err) {
    console.error('Webhook verification failed:', err.message);
    res.status(400).send('Invalid signature');
  }
});

Webhooks

These webhook payload fields are inline because they are part of the primary integration path.

Call Answered

FieldTypeDescription
data.record_typeenum: eventIdentifies the type of the resource.
data.event_typeenum: call.answeredThe 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 ev...

Call Hangup

FieldTypeDescription
data.record_typeenum: eventIdentifies the type of the resource.
data.event_typeenum: call.hangupThe 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 ev...

Call Initiated

FieldTypeDescription
data.record_typeenum: eventIdentifies the type of the resource.
data.event_typeenum: call.initiatedThe 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.connection_codecsstringThe list of comma-separated codecs enabled for the connection.
data.payload.offered_codecsstringThe 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

ParameterTypeRequiredDescription
call_control_idstring (UUID)YesUnique identifier and token for controlling the call
client_statestringNoUse this field to add state to every subsequent webhook.
command_idstring (UUID)NoUse this field to avoid duplicate commands.
custom_headersarray[object]NoCustom headers to be added to the SIP BYE message.
...+1 optional params in references/api-details.md
const response = await client.calls.actions.hangup('v3:550e8400-e29b-41d4-a716-446655440000_gRU1OGRkYQ');

console.log(response.data);

Primary response fields:

  • response.data.result

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

ParameterTypeRequiredDescription
call_control_id_to_bridge_withstring (UUID)YesThe Call Control ID of the call you want to bridge with, can...
call_control_idstring (UUID)YesUnique identifier and token for controlling the call
client_statestringNoUse this field to add state to every subsequent webhook.
command_idstring (UUID)NoUse this field to avoid duplicate commands.
video_room_idstring (UUID)NoThe ID of the video room you want to bridge with, can't be u...
...+16 optional params in references/api-details.md
const response = await client.calls.actions.bridge('v3:550e8400-e29b-41d4-a716-446655440000_gRU1OGRkYQ', {
  call_control_id_to_bridge_with: 'v3:MdI91X4lWFEs7IgbBEOT9M4AigoY08M0WWZFISt1Yw2axZ_IiE4pqg',
});

console.log(response.data);

Primary response fields:

  • response.data.result

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

ParameterTypeRequiredDescription
causeenum (CALL_REJECTED, NOT_FOUND, TEMPORARILY_UNAVAILABLE, USER_BUSY)YesCause for call rejection.
call_control_idstring (UUID)YesUnique identifier and token for controlling the call
client_statestringNoUse this field to add state to every subsequent webhook.
command_idstring (UUID)NoUse this field to avoid duplicate commands.
const response = await client.calls.actions.reject('v3:550e8400-e29b-41d4-a716-446655440000_gRU1OGRkYQ', { cause: 'USER_BUSY' });

console.log(response.data);

Primary response fields:

  • response.data.result

Retrieve a call status

Fetch the current state before updating, deleting, or making control-flow decisions.

client.calls.retrieveStatus() — GET /calls/{call_control_id}

ParameterTypeRequiredDescription
call_control_idstring (UUID)YesUnique identifier and token for controlling the call
const response = await client.calls.retrieveStatus('v3:550e8400-e29b-41d4-a716-446655440000_gRU1OGRkYQ');

console.log(response.data);

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
  • response.data.end_time

List all active calls for given connection

Fetch the current state before updating, deleting, or making control-flow decisions.

client.connections.listActiveCalls() — GET /connections/{connection_id}/active_calls

ParameterTypeRequiredDescription
connection_idstring (UUID)YesTelnyx connection id
pageobjectNoConsolidated page parameter (deepObject style).
// Automatically fetches more pages as needed.
for await (const connectionListActiveCallsResponse of client.connections.listActiveCalls(
  '1293384261075731461',
)) {
  console.log(connectionListActiveCallsResponse.call_control_id);
}

Response wrapper:

  • items: connectionListActiveCallsResponse.data
  • pagination: connectionListActiveCallsResponse.meta

Primary item fields:

  • call_control_id
  • call_duration
  • call_leg_id
  • call_session_id
  • client_state
  • record_type

List call control applications

Inspect available resources or choose an existing resource before mutating it.

client.callControlApplications.list() — GET /call_control_applications

ParameterTypeRequiredDescription
sortenum (created_at, connection_name, active)NoSpecifies the sort order for results.
filterobjectNoConsolidated filter parameter (deepObject style).
pageobjectNoConsolidated page parameter (deepObject style).
// Automatically fetches more pages as needed.
for await (const callControlApplication of client.callControlApplications.list()) {
  console.log(callControlApplication.id);
}

Response wrapper:

  • items: callControlApplication.data
  • pagination: callControlApplication.meta

Primary item fields:

  • id
  • created_at
  • updated_at
  • active
  • anchorsite_override
  • application_name

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.

OperationSDK methodEndpointUse whenRequired params
Create a call control applicationclient.callControlApplications.create()POST /call_control_applicationsCreate or provision an additional resource when the core tasks do not cover this flow.application_name, webhook_event_url
Retrieve a call control applicationclient.callControlApplications.retrieve()GET /call_control_applications/{id}Fetch the current state before updating, deleting, or making control-flow decisions.id
Update a call control applicationclient.callControlApplications.update()PATCH /call_control_applications/{id}Modify an existing resource without recreating it.application_name, webhook_event_url, id
Delete a call control applicationclient.callControlApplications.delete()DELETE /call_control_applications/{id}Remove, detach, or clean up an existing resource.id
SIP Refer a callclient.calls.actions.refer()POST /calls/{call_control_id}/actions/referTrigger a follow-up action in an existing workflow rather than creating a new top-level resource.sip_address, call_control_id
Send SIP infoclient.calls.actions.sendSipInfo()POST /calls/{call_control_id}/actions/send_sip_infoTrigger a follow-up action in an existing workflow rather than creating a new top-level resource.content_type, body, call_control_id
List dial metricsclient.dialMetrics.list()GET /dial_metricsInspect available resources or choose an existing resource before mutating it.None

Other Webhook Events

Eventdata.event_typeDescription
callBridgedcall.bridgedCall Bridged

For exhaustive optional parameters, full response schemas, and complete webhook payloads, see references/api-details.md.

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

コメント

ログインなしで書き込めます。使ってみた感想、質問、動かなかった環境などを気軽にどうぞ。

まだコメントはありません。最初のコメントを書いてみませんか。

送信するとすぐに公開されます。メールアドレスや電話番号などの個人情報は書かないでください。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 のスキルをすべて見る

このスキルの問題を報告する