Loading...
Loading...
Build voice applications using TeXML markup language (TwiML-compatible). Manage applications, calls, conferences, recordings, queues, and streams. This skill provides JavaScript SDK examples.
npx skill4agent add team-telnyx/skills telnyx-texml-javascriptnpm install telnyximport Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});clienttry {
const result = await client.messages.send({ to: '+13125550001', from: '+13125550002', text: 'Hello' });
} 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 and retry with exponential backoff
const retryAfter = err.headers?.['retry-after'] || 1;
await new Promise(r => setTimeout(r, retryAfter * 1000));
} 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');
}
}
}401403404422429for await (const item of result) { ... }GET /texml/Accounts/{account_sid}/Callsconst response = await client.texml.accounts.calls.retrieveCalls('account_sid');
console.log(response.calls);callsendfirst_page_urinext_page_uripagepage_sizestarturiPOST /texml/Accounts/{account_sid}/CallsToFromApplicationSidAsyncAmdAsyncAmdStatusCallbackAsyncAmdStatusCallbackMethodCallerIdCancelPlaybackOnDetectMessageEndCancelPlaybackOnMachineDetectionCustomHeadersDetectionModeFallbackUrlMachineDetectionMachineDetectionSilenceTimeoutMachineDetectionSpeechEndThresholdMachineDetectionSpeechThresholdMachineDetectionTimeoutPreferredCodecsRecordRecordingChannelsRecordingStatusCallbackRecordingStatusCallbackEventRecordingStatusCallbackMethodRecordingTimeoutRecordingTrackSendRecordingUrlSipAuthPasswordSipAuthUsernameSipRegionStatusCallbackStatusCallbackEventStatusCallbackMethodSuperviseCallSidSupervisingRoleTexmlTimeLimitTimeoutTrimUrlUrlMethodconst response = await client.texml.accounts.calls.calls('account_sid', {
ApplicationSid: 'example-app-sid',
From: '+13120001234',
To: '+13121230000',
});
console.log(response.from);fromstatustoGET /texml/Accounts/{account_sid}/Calls/{call_sid}const call = await client.texml.accounts.calls.retrieve('call_sid', { account_sid: '550e8400-e29b-41d4-a716-446655440000' });
console.log(call.account_sid);account_sidanswered_bycaller_namedate_createddate_updateddirectiondurationend_timefromfrom_formattedpriceprice_unitsidstart_timestatustoto_formatteduriPOST /texml/Accounts/{account_sid}/Calls/{call_sid}const call = await client.texml.accounts.calls.update('call_sid', { account_sid: '550e8400-e29b-41d4-a716-446655440000' });
console.log(call.account_sid);account_sidanswered_bycaller_namedate_createddate_updateddirectiondurationend_timefromfrom_formattedpriceprice_unitsidstart_timestatustoto_formatteduriGET /texml/Accounts/{account_sid}/Calls/{call_sid}/Recordings.jsonconst response = await client.texml.accounts.calls.recordingsJson.retrieveRecordingsJson(
'call_sid',
{ account_sid: '550e8400-e29b-41d4-a716-446655440000' },
);
console.log(response.end);endfirst_page_urinext_page_uripagepage_sizeprevious_page_urirecordingsstarturiPOST /texml/Accounts/{account_sid}/Calls/{call_sid}/Recordings.jsonconst response = await client.texml.accounts.calls.recordingsJson.recordingsJson('call_sid', {
account_sid: '550e8400-e29b-41d4-a716-446655440000',
});
console.log(response.account_sid);account_sidcall_sidchannelsconference_siddate_createddate_updateddurationerror_codepriceprice_unitsidsourcestart_timetrackuriPOST /texml/Accounts/{account_sid}/Calls/{call_sid}/Recordings/{recording_sid}.jsonconst response = await client.texml.accounts.calls.recordings.recordingSidJson(
'6a09cdc3-8948-47f0-aa62-74ac943d6c58',
{ account_sid: '550e8400-e29b-41d4-a716-446655440000', call_sid: '550e8400-e29b-41d4-a716-446655440000' },
);
console.log(response.account_sid);account_sidcall_sidchannelsconference_siddate_createddate_updateddurationerror_codepriceprice_unitsidsourcestart_timetrackuriPOST /texml/Accounts/{account_sid}/Calls/{call_sid}/Siprec.jsonconst response = await client.texml.accounts.calls.siprecJson('call_sid', {
account_sid: '550e8400-e29b-41d4-a716-446655440000',
});
console.log(response.account_sid);account_sidcall_siddate_createddate_updatederror_codesidstart_timestatustrackuriPOST /texml/Accounts/{account_sid}/Calls/{call_sid}/Siprec/{siprec_sid}.jsonconst response = await client.texml.accounts.calls.siprec.siprecSidJson('siprec_sid', {
account_sid: '550e8400-e29b-41d4-a716-446655440000',
call_sid: '550e8400-e29b-41d4-a716-446655440000',
});
console.log(response.account_sid);account_sidcall_siddate_updatederror_codesidstatusuriPOST /texml/Accounts/{account_sid}/Calls/{call_sid}/Streams.jsonconst response = await client.texml.accounts.calls.streamsJson('call_sid', {
account_sid: '550e8400-e29b-41d4-a716-446655440000',
});
console.log(response.account_sid);account_sidcall_siddate_updatednamesidstatusuriPOST /texml/Accounts/{account_sid}/Calls/{call_sid}/Streams/{streaming_sid}.jsonconst response = await client.texml.accounts.calls.streams.streamingSidJson(
'6a09cdc3-8948-47f0-aa62-74ac943d6c58',
{ account_sid: '550e8400-e29b-41d4-a716-446655440000', call_sid: '550e8400-e29b-41d4-a716-446655440000' },
);
console.log(response.account_sid);account_sidcall_siddate_updatedsidstatusuriGET /texml/Accounts/{account_sid}/Conferencesconst response = await client.texml.accounts.conferences.retrieveConferences('account_sid');
console.log(response.conferences);conferencesendfirst_page_urinext_page_uripagepage_sizestarturiGET /texml/Accounts/{account_sid}/Conferences/{conference_sid}const conference = await client.texml.accounts.conferences.retrieve('conference_sid', {
account_sid: '550e8400-e29b-41d4-a716-446655440000',
});
console.log(conference.account_sid);account_sidapi_versioncall_sid_ending_conferencedate_createddate_updatedfriendly_namereason_conference_endedregionsidstatussubresource_urisuriPOST /texml/Accounts/{account_sid}/Conferences/{conference_sid}const conference = await client.texml.accounts.conferences.update('conference_sid', {
account_sid: '550e8400-e29b-41d4-a716-446655440000',
});
console.log(conference.account_sid);account_sidapi_versioncall_sid_ending_conferencedate_createddate_updatedfriendly_namereason_conference_endedregionsidstatussubresource_urisuriGET /texml/Accounts/{account_sid}/Conferences/{conference_sid}/Participantsconst response = await client.texml.accounts.conferences.participants.retrieveParticipants(
'conference_sid',
{ account_sid: '550e8400-e29b-41d4-a716-446655440000' },
);
console.log(response.end);endfirst_page_urinext_page_uripagepage_sizeparticipantsstarturiPOST /texml/Accounts/{account_sid}/Conferences/{conference_sid}/Participantsconst response = await client.texml.accounts.conferences.participants.participants(
'conference_sid',
{ account_sid: '550e8400-e29b-41d4-a716-446655440000' },
);
console.log(response.account_sid);account_sidcall_sidcoachingcoaching_call_sidconference_sidend_conference_on_exitholdmutedstatusuriGET /texml/Accounts/{account_sid}/Conferences/{conference_sid}/Participants/{call_sid_or_participant_label}const participant = await client.texml.accounts.conferences.participants.retrieve(
'call_sid_or_participant_label',
{ account_sid: '550e8400-e29b-41d4-a716-446655440000', conference_sid: '550e8400-e29b-41d4-a716-446655440000' },
);
console.log(participant.account_sid);account_sidapi_versioncall_sidcall_sid_legacycoachingcoaching_call_sidcoaching_call_sid_legacyconference_siddate_createddate_updatedend_conference_on_exitholdmutedstatusuriPOST /texml/Accounts/{account_sid}/Conferences/{conference_sid}/Participants/{call_sid_or_participant_label}const participant = await client.texml.accounts.conferences.participants.update(
'call_sid_or_participant_label',
{ account_sid: '550e8400-e29b-41d4-a716-446655440000', conference_sid: '550e8400-e29b-41d4-a716-446655440000' },
);
console.log(participant.account_sid);account_sidapi_versioncall_sidcall_sid_legacycoachingcoaching_call_sidcoaching_call_sid_legacyconference_siddate_createddate_updatedend_conference_on_exitholdmutedstatusuriDELETE /texml/Accounts/{account_sid}/Conferences/{conference_sid}/Participants/{call_sid_or_participant_label}await client.texml.accounts.conferences.participants.delete('call_sid_or_participant_label', {
account_sid: '550e8400-e29b-41d4-a716-446655440000',
conference_sid: '550e8400-e29b-41d4-a716-446655440000',
});GET /texml/Accounts/{account_sid}/Conferences/{conference_sid}/Recordingsconst response = await client.texml.accounts.conferences.retrieveRecordings('conference_sid', {
account_sid: '550e8400-e29b-41d4-a716-446655440000',
});
console.log(response.end);endfirst_page_urinext_page_uripagepage_sizeparticipantsrecordingsstarturiGET /texml/Accounts/{account_sid}/Conferences/{conference_sid}/Recordings.jsonconst response = await client.texml.accounts.conferences.retrieveRecordingsJson('conference_sid', {
account_sid: '550e8400-e29b-41d4-a716-446655440000',
});
console.log(response.end);endfirst_page_urinext_page_uripagepage_sizeprevious_page_urirecordingsstarturiGET /texml/Accounts/{account_sid}/Queues// Automatically fetches more pages as needed.
for await (const queueListResponse of client.texml.accounts.queues.list('account_sid')) {
console.log(queueListResponse.account_sid);
}endfirst_page_urinext_page_uripagepage_sizequeuesstarturiPOST /texml/Accounts/{account_sid}/Queuesconst queue = await client.texml.accounts.queues.create('account_sid');
console.log(queue.account_sid);account_sidaverage_wait_timecurrent_sizedate_createddate_updatedmax_sizesidsubresource_urisuriGET /texml/Accounts/{account_sid}/Queues/{queue_sid}const queue = await client.texml.accounts.queues.retrieve('queue_sid', {
account_sid: '550e8400-e29b-41d4-a716-446655440000',
});
console.log(queue.account_sid);account_sidaverage_wait_timecurrent_sizedate_createddate_updatedmax_sizesidsubresource_urisuriPOST /texml/Accounts/{account_sid}/Queues/{queue_sid}const queue = await client.texml.accounts.queues.update('queue_sid', {
account_sid: '550e8400-e29b-41d4-a716-446655440000',
});
console.log(queue.account_sid);account_sidaverage_wait_timecurrent_sizedate_createddate_updatedmax_sizesidsubresource_urisuriDELETE /texml/Accounts/{account_sid}/Queues/{queue_sid}await client.texml.accounts.queues.delete('queue_sid', { account_sid: '550e8400-e29b-41d4-a716-446655440000' });GET /texml/Accounts/{account_sid}/Recordings.jsonconst response = await client.texml.accounts.retrieveRecordingsJson('account_sid');
console.log(response.end);endfirst_page_urinext_page_uripagepage_sizeprevious_page_urirecordingsstarturiGET /texml/Accounts/{account_sid}/Recordings/{recording_sid}.jsonconst texmlGetCallRecordingResponseBody =
await client.texml.accounts.recordings.json.retrieveRecordingSidJson(
'6a09cdc3-8948-47f0-aa62-74ac943d6c58',
{ account_sid: '550e8400-e29b-41d4-a716-446655440000' },
);
console.log(texmlGetCallRecordingResponseBody.account_sid);account_sidcall_sidchannelsconference_siddate_createddate_updateddurationerror_codemedia_urlsidsourcestart_timestatussubresources_urisuriDELETE /texml/Accounts/{account_sid}/Recordings/{recording_sid}.jsonawait client.texml.accounts.recordings.json.deleteRecordingSidJson(
'6a09cdc3-8948-47f0-aa62-74ac943d6c58',
{ account_sid: '550e8400-e29b-41d4-a716-446655440000' },
);GET /texml/Accounts/{account_sid}/Transcriptions.jsonconst response = await client.texml.accounts.retrieveTranscriptionsJson('account_sid');
console.log(response.end);endfirst_page_urinext_page_uripagepage_sizeprevious_page_uristarttranscriptionsuriGET /texml/Accounts/{account_sid}/Transcriptions/{recording_transcription_sid}.jsonconst response =
await client.texml.accounts.transcriptions.json.retrieveRecordingTranscriptionSidJson(
'6a09cdc3-8948-47f0-aa62-74ac943d6c58',
{ account_sid: '550e8400-e29b-41d4-a716-446655440000' },
);
console.log(response.account_sid);account_sidapi_versioncall_siddate_createddate_updateddurationrecording_sidsidstatustranscription_texturiDELETE /texml/Accounts/{account_sid}/Transcriptions/{recording_transcription_sid}.jsonawait client.texml.accounts.transcriptions.json.deleteRecordingTranscriptionSidJson(
'6a09cdc3-8948-47f0-aa62-74ac943d6c58',
{ account_sid: '550e8400-e29b-41d4-a716-446655440000' },
);POST /texml/secretsnamevalueconst response = await client.texml.secrets({ name: 'My Secret Name', value: 'My Secret Value' });
console.log(response.data);namevalueGET /texml_applications// Automatically fetches more pages as needed.
for await (const texmlApplication of client.texmlApplications.list()) {
console.log(texmlApplication.id);
}activeanchorsite_overridecall_cost_in_webhookscreated_atdtmf_typefirst_command_timeoutfirst_command_timeout_secsfriendly_nameidinboundoutboundrecord_typestatus_callbackstatus_callback_methodtagsupdated_atvoice_fallback_urlvoice_methodvoice_urlPOST /texml_applicationsfriendly_namevoice_urlactiveanchorsite_overridecall_cost_in_webhooksdtmf_typefirst_command_timeoutfirst_command_timeout_secsinboundoutboundstatus_callbackstatus_callback_methodtagsvoice_fallback_urlvoice_methodconst texmlApplication = await client.texmlApplications.create({
friendly_name: 'call-router',
voice_url: 'https://example.com',
});
console.log(texmlApplication.data);activeanchorsite_overridecall_cost_in_webhookscreated_atdtmf_typefirst_command_timeoutfirst_command_timeout_secsfriendly_nameidinboundoutboundrecord_typestatus_callbackstatus_callback_methodtagsupdated_atvoice_fallback_urlvoice_methodvoice_urlGET /texml_applications/{id}const texmlApplication = await client.texmlApplications.retrieve('1293384261075731499');
console.log(texmlApplication.data);activeanchorsite_overridecall_cost_in_webhookscreated_atdtmf_typefirst_command_timeoutfirst_command_timeout_secsfriendly_nameidinboundoutboundrecord_typestatus_callbackstatus_callback_methodtagsupdated_atvoice_fallback_urlvoice_methodvoice_urlPATCH /texml_applications/{id}friendly_namevoice_urlactiveanchorsite_overridecall_cost_in_webhooksdtmf_typefirst_command_timeoutfirst_command_timeout_secsinboundoutboundstatus_callbackstatus_callback_methodtagsvoice_fallback_urlvoice_methodconst texmlApplication = await client.texmlApplications.update('1293384261075731499', {
friendly_name: 'call-router',
voice_url: 'https://example.com',
});
console.log(texmlApplication.data);activeanchorsite_overridecall_cost_in_webhookscreated_atdtmf_typefirst_command_timeoutfirst_command_timeout_secsfriendly_nameidinboundoutboundrecord_typestatus_callbackstatus_callback_methodtagsupdated_atvoice_fallback_urlvoice_methodvoice_urlDELETE /texml_applications/{id}const texmlApplication = await client.texmlApplications.delete('1293384261075731499');
console.log(texmlApplication.data);activeanchorsite_overridecall_cost_in_webhookscreated_atdtmf_typefirst_command_timeoutfirst_command_timeout_secsfriendly_nameidinboundoutboundrecord_typestatus_callbackstatus_callback_methodtagsupdated_atvoice_fallback_urlvoice_methodvoice_url