Loading...
Loading...
Configure phone number settings including caller ID, call forwarding, messaging enablement, and connection assignments. This skill provides JavaScript SDK examples.
npx skill4agent add team-telnyx/skills telnyx-numbers-config-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');
}
}
}401403404422429+13125550001+for await (const item of result) { ... }POST /messaging_numbers_bulk_updatesmessaging_profile_idnumbersassign_onlyconst messagingNumbersBulkUpdate = await client.messagingNumbersBulkUpdates.create({
messaging_profile_id: '00000000-0000-0000-0000-000000000000',
numbers: ['+18880000000', '+18880000001', '+18880000002'],
});
console.log(messagingNumbersBulkUpdate.data);failedorder_idpendingrecord_typesuccessGET /messaging_numbers_bulk_updates/{order_id}const messagingNumbersBulkUpdate = await client.messagingNumbersBulkUpdates.retrieve('order_id');
console.log(messagingNumbersBulkUpdate.data);failedorder_idpendingrecord_typesuccessGET /mobile_phone_numbers/messaging// Automatically fetches more pages as needed.
for await (const messagingListResponse of client.mobilePhoneNumbers.messaging.list()) {
console.log(messagingListResponse.id);
}country_codecreated_atfeaturesidmessaging_productmessaging_profile_idorganization_idphone_numberrecord_typetagstraffic_typetypeupdated_atGET /mobile_phone_numbers/{id}/messagingconst messaging = await client.mobilePhoneNumbers.messaging.retrieve('550e8400-e29b-41d4-a716-446655440000');
console.log(messaging.data);country_codecreated_atfeaturesidmessaging_productmessaging_profile_idorganization_idphone_numberrecord_typetagstraffic_typetypeupdated_atGET /phone_numbers// Automatically fetches more pages as needed.
for await (const phoneNumberDetailed of client.phoneNumbers.list()) {
console.log(phoneNumberDetailed.id);
}billing_group_idcall_forwarding_enabledcall_recording_enabledcaller_id_name_enabledcnam_listing_enabledconnection_idconnection_namecountry_iso_alpha2created_atcustomer_referencedeletion_lock_enabledemergency_address_idemergency_enabledemergency_statusexternal_pinhd_voice_enabledidinbound_call_screeningmessaging_profile_idmessaging_profile_namephone_numberphone_number_typepurchased_atrecord_typesource_typestatust38_fax_gateway_enabledtagsupdated_atPOST /phone_numbers/actions/verify_ownershipphone_numbersconst response = await client.phoneNumbers.actions.verifyOwnership({
phone_numbers: ['+15551234567'],
});
console.log(response.data);foundnot_foundrecord_typeGET /phone_numbers/jobs// Automatically fetches more pages as needed.
for await (const phoneNumbersJob of client.phoneNumbers.jobs.list()) {
console.log(phoneNumbersJob.id);
}created_atetcfailed_operationsidpending_operationsphone_numbersrecord_typestatussuccessful_operationstypeupdated_atPOST /phone_numbers/jobs/delete_phone_numbersphone_numbersconst response = await client.phoneNumbers.jobs.deleteBatch({
phone_numbers: ['+19705555098', '+19715555098', '32873127836'],
});
console.log(response.data);created_atetcfailed_operationsidpending_operationsphone_numbersrecord_typestatussuccessful_operationstypeupdated_atPOST /phone_numbers/jobs/update_emergency_settingsemergency_enabledphone_numbersemergency_address_idconst response = await client.phoneNumbers.jobs.updateEmergencySettingsBatch({
emergency_enabled: true,
phone_numbers: ['+19705555098', '+19715555098', '32873127836'],
});
console.log(response.data);created_atetcfailed_operationsidpending_operationsphone_numbersrecord_typestatussuccessful_operationstypeupdated_atPOST /phone_numbers/jobs/update_phone_numbersphone_numbersbilling_group_idconnection_idcustomer_referencedeletion_lock_enabledexternal_pinhd_voice_enabledtagsvoiceconst response = await client.phoneNumbers.jobs.updateBatch({
phone_numbers: ['1583466971586889004', '+13127367254'],
});
console.log(response.data);created_atetcfailed_operationsidpending_operationsphone_numbersrecord_typestatussuccessful_operationstypeupdated_atGET /phone_numbers/jobs/{id}const job = await client.phoneNumbers.jobs.retrieve('550e8400-e29b-41d4-a716-446655440000');
console.log(job.data);created_atetcfailed_operationsidpending_operationsphone_numbersrecord_typestatussuccessful_operationstypeupdated_atGET /phone_numbers/messaging// Automatically fetches more pages as needed.
for await (const phoneNumberWithMessagingSettings of client.phoneNumbers.messaging.list()) {
console.log(phoneNumberWithMessagingSettings.id);
}country_codecreated_ateligible_messaging_productsfeatureshealthidmessaging_productmessaging_profile_idorganization_idphone_numberrecord_typetagstraffic_typetypeupdated_atGET /phone_numbers/slim// Automatically fetches more pages as needed.
for await (const phoneNumberSlimListResponse of client.phoneNumbers.slimList()) {
console.log(phoneNumberSlimListResponse.id);
}billing_group_idcall_forwarding_enabledcall_recording_enabledcaller_id_name_enabledcnam_listing_enabledconnection_idcountry_iso_alpha2created_atcustomer_referenceemergency_address_idemergency_enabledemergency_statusexternal_pinhd_voice_enabledidinbound_call_screeningphone_numberphone_number_typepurchased_atrecord_typestatust38_fax_gateway_enabledupdated_atGET /phone_numbers/voice// Automatically fetches more pages as needed.
for await (const phoneNumberWithVoiceSettings of client.phoneNumbers.voice.list()) {
console.log(phoneNumberWithVoiceSettings.id);
}call_forwardingcall_recordingcnam_listingconnection_idcustomer_referenceemergencyidinbound_call_screeningmedia_featuresphone_numberrecord_typetech_prefix_enabledtranslated_numberusage_payment_methodGET /phone_numbers/{id}const phoneNumber = await client.phoneNumbers.retrieve('1293384261075731499');
console.log(phoneNumber.data);billing_group_idcall_forwarding_enabledcall_recording_enabledcaller_id_name_enabledcnam_listing_enabledconnection_idconnection_namecountry_iso_alpha2created_atcustomer_referencedeletion_lock_enabledemergency_address_idemergency_enabledemergency_statusexternal_pinhd_voice_enabledidinbound_call_screeningmessaging_profile_idmessaging_profile_namephone_numberphone_number_typepurchased_atrecord_typesource_typestatust38_fax_gateway_enabledtagsupdated_atPATCH /phone_numbers/{id}address_idbilling_group_idconnection_idcustomer_referenceexternal_pinhd_voice_enabledidtagsconst phoneNumber = await client.phoneNumbers.update('1293384261075731499');
console.log(phoneNumber.data);billing_group_idcall_forwarding_enabledcall_recording_enabledcaller_id_name_enabledcnam_listing_enabledconnection_idconnection_namecountry_iso_alpha2created_atcustomer_referencedeletion_lock_enabledemergency_address_idemergency_enabledemergency_statusexternal_pinhd_voice_enabledidinbound_call_screeningmessaging_profile_idmessaging_profile_namephone_numberphone_number_typepurchased_atrecord_typesource_typestatust38_fax_gateway_enabledtagsupdated_atDELETE /phone_numbers/{id}const phoneNumber = await client.phoneNumbers.delete('1293384261075731499');
console.log(phoneNumber.data);billing_group_idcall_forwarding_enabledcall_recording_enabledcaller_id_name_enabledcnam_listing_enabledconnection_idconnection_namecreated_atcustomer_referencedeletion_lock_enabledemergency_address_idemergency_enabledexternal_pinhd_voice_enabledidmessaging_profile_idmessaging_profile_namephone_numberphone_number_typepurchased_atrecord_typestatust38_fax_gateway_enabledtagsupdated_atPATCH /phone_numbers/{id}/actions/bundle_status_changebundle_idconst response = await client.phoneNumbers.actions.changeBundleStatus('1293384261075731499', {
bundle_id: '5194d8fc-87e6-4188-baa9-1c434bbe861b',
});
console.log(response.data);call_forwardingcall_recordingcnam_listingconnection_idcustomer_referenceemergencyidinbound_call_screeningmedia_featuresphone_numberrecord_typetech_prefix_enabledtranslated_numberusage_payment_methodPOST /phone_numbers/{id}/actions/enable_emergencyemergency_enabledemergency_address_idconst response = await client.phoneNumbers.actions.enableEmergency('1293384261075731499', {
emergency_address_id: '53829456729313',
emergency_enabled: true,
});
console.log(response.data);call_forwardingcall_recordingcnam_listingconnection_idcustomer_referenceemergencyidinbound_call_screeningmedia_featuresphone_numberrecord_typetech_prefix_enabledtranslated_numberusage_payment_methodGET /phone_numbers/{id}/messagingconst messaging = await client.phoneNumbers.messaging.retrieve('550e8400-e29b-41d4-a716-446655440000');
console.log(messaging.data);country_codecreated_ateligible_messaging_productsfeatureshealthidmessaging_productmessaging_profile_idorganization_idphone_numberrecord_typetagstraffic_typetypeupdated_atPATCH /phone_numbers/{id}/messagingmessaging_productmessaging_profile_idtagsconst messaging = await client.phoneNumbers.messaging.update('550e8400-e29b-41d4-a716-446655440000');
console.log(messaging.data);country_codecreated_ateligible_messaging_productsfeatureshealthidmessaging_productmessaging_profile_idorganization_idphone_numberrecord_typetagstraffic_typetypeupdated_atGET /phone_numbers/{id}/voiceconst voice = await client.phoneNumbers.voice.retrieve('1293384261075731499');
console.log(voice.data);call_forwardingcall_recordingcnam_listingconnection_idcustomer_referenceemergencyidinbound_call_screeningmedia_featuresphone_numberrecord_typetech_prefix_enabledtranslated_numberusage_payment_methodPATCH /phone_numbers/{id}/voicecall_forwardingcall_recordingcaller_id_name_enabledcnam_listinginbound_call_screeningmedia_featurestech_prefix_enabledtranslated_numberusage_payment_methodconst voice = await client.phoneNumbers.voice.update('1293384261075731499');
console.log(voice.data);call_forwardingcall_recordingcnam_listingconnection_idcustomer_referenceemergencyidinbound_call_screeningmedia_featuresphone_numberrecord_typetech_prefix_enabledtranslated_numberusage_payment_methodGET /v2/mobile_phone_numbers// Automatically fetches more pages as needed.
for await (const mobilePhoneNumber of client.mobilePhoneNumbers.list()) {
console.log(mobilePhoneNumber.id);
}call_forwardingcall_recordingcaller_id_name_enabledcnam_listingconnection_idconnection_nameconnection_typecountry_iso_alpha2created_atcustomer_referenceidinboundinbound_call_screeningmobile_voice_enablednoise_suppressionoutboundphone_numberrecord_typesim_card_idstatustagsupdated_atGET /v2/mobile_phone_numbers/{id}const mobilePhoneNumber = await client.mobilePhoneNumbers.retrieve('550e8400-e29b-41d4-a716-446655440000');
console.log(mobilePhoneNumber.data);call_forwardingcall_recordingcaller_id_name_enabledcnam_listingconnection_idconnection_nameconnection_typecountry_iso_alpha2created_atcustomer_referenceidinboundinbound_call_screeningmobile_voice_enablednoise_suppressionoutboundphone_numberrecord_typesim_card_idstatustagsupdated_atPATCH /v2/mobile_phone_numbers/{id}call_forwardingcall_recordingcaller_id_name_enabledcnam_listingconnection_idcustomer_referenceinboundinbound_call_screeningnoise_suppressionoutboundtagsconst mobilePhoneNumber = await client.mobilePhoneNumbers.update('550e8400-e29b-41d4-a716-446655440000');
console.log(mobilePhoneNumber.data);call_forwardingcall_recordingcaller_id_name_enabledcnam_listingconnection_idconnection_nameconnection_typecountry_iso_alpha2created_atcustomer_referenceidinboundinbound_call_screeningmobile_voice_enablednoise_suppressionoutboundphone_numberrecord_typesim_card_idstatustagsupdated_at