Loading...
Loading...
Manage WebRTC credentials and mobile push notification settings. Use when building browser-based or mobile softphone applications. This skill provides JavaScript SDK examples.
npx skill4agent add team-telnyx/skills telnyx-webrtc-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 /mobile_push_credentials// Automatically fetches more pages as needed.
for await (const pushCredential of client.mobilePushCredentials.list()) {
console.log(pushCredential.id);
}aliascertificatecreated_atidprivate_keyproject_account_json_filerecord_typetypeupdated_atPOST /mobile_push_credentialstypecertificateprivate_keyaliasconst pushCredentialResponse = await client.mobilePushCredentials.create({
createMobilePushCredentialRequest: {
alias: 'LucyIosCredential',
certificate:
'-----BEGIN CERTIFICATE----- MIIGVDCCBTKCAQEAsNlRJVZn9ZvXcECQm65czs... -----END CERTIFICATE-----',
private_key:
'-----BEGIN RSA PRIVATE KEY----- MIIEpQIBAAKCAQEAsNlRJVZn9ZvXcECQm65czs... -----END RSA PRIVATE KEY-----',
type: 'ios',
},
});
console.log(pushCredentialResponse.data);aliascertificatecreated_atidprivate_keyproject_account_json_filerecord_typetypeupdated_atpush_credential_idGET /mobile_push_credentials/{push_credential_id}const pushCredentialResponse = await client.mobilePushCredentials.retrieve(
'0ccc7b76-4df3-4bca-a05a-3da1ecc389f0',
);
console.log(pushCredentialResponse.data);aliascertificatecreated_atidprivate_keyproject_account_json_filerecord_typetypeupdated_atpush_credential_idDELETE /mobile_push_credentials/{push_credential_id}await client.mobilePushCredentials.delete('0ccc7b76-4df3-4bca-a05a-3da1ecc389f0');GET /telephony_credentials// Automatically fetches more pages as needed.
for await (const telephonyCredential of client.telephonyCredentials.list()) {
console.log(telephonyCredential.id);
}created_atexpiredexpires_atidnamerecord_typeresource_idsip_passwordsip_usernameupdated_atuser_idPOST /telephony_credentialsconnection_idexpires_atnametagconst telephonyCredential = await client.telephonyCredentials.create({
connection_id: '1234567890',
});
console.log(telephonyCredential.data);created_atexpiredexpires_atidnamerecord_typeresource_idsip_passwordsip_usernameupdated_atuser_idGET /telephony_credentials/{id}const telephonyCredential = await client.telephonyCredentials.retrieve('550e8400-e29b-41d4-a716-446655440000');
console.log(telephonyCredential.data);created_atexpiredexpires_atidnamerecord_typeresource_idsip_passwordsip_usernameupdated_atuser_idPATCH /telephony_credentials/{id}connection_idexpires_atnametagconst telephonyCredential = await client.telephonyCredentials.update('550e8400-e29b-41d4-a716-446655440000');
console.log(telephonyCredential.data);created_atexpiredexpires_atidnamerecord_typeresource_idsip_passwordsip_usernameupdated_atuser_idDELETE /telephony_credentials/{id}const telephonyCredential = await client.telephonyCredentials.delete('550e8400-e29b-41d4-a716-446655440000');
console.log(telephonyCredential.data);created_atexpiredexpires_atidnamerecord_typeresource_idsip_passwordsip_usernameupdated_atuser_id