Loading...
Loading...
Create and manage messaging profiles with number pools, sticky sender, and geomatch features. Configure short codes for high-volume messaging. This skill provides JavaScript SDK examples.
npx skill4agent add team-telnyx/skills telnyx-messaging-profiles-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 /messaging_profiles// Automatically fetches more pages as needed.
for await (const messagingProfile of client.messagingProfiles.list()) {
console.log(messagingProfile.id);
}ai_assistant_idalpha_sendercreated_atdaily_spend_limitdaily_spend_limit_enabledenabledhealth_webhook_urlidmms_fall_back_to_smsmms_transcodingmobile_onlynamenumber_pool_settingsorganization_idrecord_typeredaction_enabledredaction_levelresource_group_idsmart_encodingupdated_aturl_shortener_settingsv1_secretwebhook_api_versionwebhook_failover_urlwebhook_urlwhitelisted_destinationsPOST /messaging_profilesnamewhitelisted_destinationsai_assistant_idalpha_senderdaily_spend_limitdaily_spend_limit_enabledenabledhealth_webhook_urlmms_fall_back_to_smsmms_transcodingmobile_onlynumber_pool_settingsresource_group_idsmart_encodingurl_shortener_settingswebhook_api_versionwebhook_failover_urlwebhook_urlconst messagingProfile = await client.messagingProfiles.create({
name: 'My name',
whitelisted_destinations: ['US'],
});
console.log(messagingProfile.data);ai_assistant_idalpha_sendercreated_atdaily_spend_limitdaily_spend_limit_enabledenabledhealth_webhook_urlidmms_fall_back_to_smsmms_transcodingmobile_onlynamenumber_pool_settingsorganization_idrecord_typeredaction_enabledredaction_levelresource_group_idsmart_encodingupdated_aturl_shortener_settingsv1_secretwebhook_api_versionwebhook_failover_urlwebhook_urlwhitelisted_destinationsGET /messaging_profiles/{id}const messagingProfile = await client.messagingProfiles.retrieve(
'182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
);
console.log(messagingProfile.data);ai_assistant_idalpha_sendercreated_atdaily_spend_limitdaily_spend_limit_enabledenabledhealth_webhook_urlidmms_fall_back_to_smsmms_transcodingmobile_onlynamenumber_pool_settingsorganization_idrecord_typeredaction_enabledredaction_levelresource_group_idsmart_encodingupdated_aturl_shortener_settingsv1_secretwebhook_api_versionwebhook_failover_urlwebhook_urlwhitelisted_destinationsPATCH /messaging_profiles/{id}alpha_sendercreated_atdaily_spend_limitdaily_spend_limit_enabledenabledidmms_fall_back_to_smsmms_transcodingmobile_onlynamenumber_pool_settingsrecord_typesmart_encodingupdated_aturl_shortener_settingsv1_secretwebhook_api_versionwebhook_failover_urlwebhook_urlwhitelisted_destinationsconst messagingProfile = await client.messagingProfiles.update(
'182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
);
console.log(messagingProfile.data);ai_assistant_idalpha_sendercreated_atdaily_spend_limitdaily_spend_limit_enabledenabledhealth_webhook_urlidmms_fall_back_to_smsmms_transcodingmobile_onlynamenumber_pool_settingsorganization_idrecord_typeredaction_enabledredaction_levelresource_group_idsmart_encodingupdated_aturl_shortener_settingsv1_secretwebhook_api_versionwebhook_failover_urlwebhook_urlwhitelisted_destinationsDELETE /messaging_profiles/{id}const messagingProfile = await client.messagingProfiles.delete(
'182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
);
console.log(messagingProfile.data);ai_assistant_idalpha_sendercreated_atdaily_spend_limitdaily_spend_limit_enabledenabledhealth_webhook_urlidmms_fall_back_to_smsmms_transcodingmobile_onlynamenumber_pool_settingsorganization_idrecord_typeredaction_enabledredaction_levelresource_group_idsmart_encodingupdated_aturl_shortener_settingsv1_secretwebhook_api_versionwebhook_failover_urlwebhook_urlwhitelisted_destinationsGET /messaging_profiles/{id}/phone_numbers// Automatically fetches more pages as needed.
for await (const phoneNumberWithMessagingSettings of client.messagingProfiles.listPhoneNumbers(
'182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
)) {
console.log(phoneNumberWithMessagingSettings.id);
}country_codecreated_ateligible_messaging_productsfeatureshealthidmessaging_productmessaging_profile_idorganization_idphone_numberrecord_typetagstraffic_typetypeupdated_atGET /messaging_profiles/{id}/short_codes// Automatically fetches more pages as needed.
for await (const shortCode of client.messagingProfiles.listShortCodes(
'182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
)) {
console.log(shortCode.messaging_profile_id);
}country_codecreated_atidmessaging_profile_idrecord_typeshort_codetagsupdated_atGET /short_codes// Automatically fetches more pages as needed.
for await (const shortCode of client.shortCodes.list()) {
console.log(shortCode.messaging_profile_id);
}country_codecreated_atidmessaging_profile_idrecord_typeshort_codetagsupdated_atGET /short_codes/{id}const shortCode = await client.shortCodes.retrieve('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e');
console.log(shortCode.data);country_codecreated_atidmessaging_profile_idrecord_typeshort_codetagsupdated_atmessaging_profile_idnullPATCH /short_codes/{id}messaging_profile_idtagsconst shortCode = await client.shortCodes.update('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
messaging_profile_id: 'abc85f64-5717-4562-b3fc-2c9600000000',
});
console.log(shortCode.data);country_codecreated_atidmessaging_profile_idrecord_typeshort_codetagsupdated_at