Loading...
Loading...
Create and manage video rooms for real-time video communication and conferencing. This skill provides JavaScript SDK examples.
npx skill4agent add team-telnyx/skills telnyx-video-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');
}
}
}401403404422429GET /room_compositions// Automatically fetches more pages as needed.
for await (const roomComposition of client.roomCompositions.list()) {
console.log(roomComposition.id);
}completed_atcreated_atdownload_urlduration_secsended_atformatidrecord_typeresolutionroom_idsession_idsize_mbstarted_atstatusupdated_atuser_idvideo_layoutwebhook_event_failover_urlwebhook_event_urlwebhook_timeout_secsPOST /room_compositionsformatresolutionsession_idvideo_layoutwebhook_event_failover_urlwebhook_event_urlwebhook_timeout_secsconst roomComposition = await client.roomCompositions.create();
console.log(roomComposition.data);completed_atcreated_atdownload_urlduration_secsended_atformatidrecord_typeresolutionroom_idsession_idsize_mbstarted_atstatusupdated_atuser_idvideo_layoutwebhook_event_failover_urlwebhook_event_urlwebhook_timeout_secsGET /room_compositions/{room_composition_id}const roomComposition = await client.roomCompositions.retrieve(
'5219b3af-87c6-4c08-9b58-5a533d893e21',
);
console.log(roomComposition.data);completed_atcreated_atdownload_urlduration_secsended_atformatidrecord_typeresolutionroom_idsession_idsize_mbstarted_atstatusupdated_atuser_idvideo_layoutwebhook_event_failover_urlwebhook_event_urlwebhook_timeout_secsDELETE /room_compositions/{room_composition_id}await client.roomCompositions.delete('5219b3af-87c6-4c08-9b58-5a533d893e21');GET /room_participants// Automatically fetches more pages as needed.
for await (const roomParticipant of client.roomParticipants.list()) {
console.log(roomParticipant.id);
}contextidjoined_atleft_atrecord_typesession_idupdated_atGET /room_participants/{room_participant_id}const roomParticipant = await client.roomParticipants.retrieve(
'0ccc7b54-4df3-4bca-a65a-3da1ecc777f0',
);
console.log(roomParticipant.data);contextidjoined_atleft_atrecord_typesession_idupdated_atGET /room_recordings// Automatically fetches more pages as needed.
for await (const roomRecordingListResponse of client.roomRecordings.list()) {
console.log(roomRecordingListResponse.id);
}codeccompleted_atcreated_atdownload_urlduration_secsended_atidparticipant_idrecord_typeroom_idsession_idsize_mbstarted_atstatustypeupdated_atDELETE /room_recordingsconst response = await client.roomRecordings.deleteBulk();
console.log(response.data);room_recordingsGET /room_recordings/{room_recording_id}const roomRecording = await client.roomRecordings.retrieve('0ccc7b54-4df3-4bca-a65a-3da1ecc777f0');
console.log(roomRecording.data);codeccompleted_atcreated_atdownload_urlduration_secsended_atidparticipant_idrecord_typeroom_idsession_idsize_mbstarted_atstatustypeupdated_atDELETE /room_recordings/{room_recording_id}await client.roomRecordings.delete('0ccc7b54-4df3-4bca-a65a-3da1ecc777f0');GET /room_sessions// Automatically fetches more pages as needed.
for await (const roomSession of client.rooms.sessions.list0()) {
console.log(roomSession.id);
}activecreated_atended_atidparticipantsrecord_typeroom_idupdated_atGET /room_sessions/{room_session_id}const session = await client.rooms.sessions.retrieve('0ccc7b54-4df3-4bca-a65a-3da1ecc777f0');
console.log(session.data);activecreated_atended_atidparticipantsrecord_typeroom_idupdated_atPOST /room_sessions/{room_session_id}/actions/endconst response = await client.rooms.sessions.actions.end('0ccc7b54-4df3-4bca-a65a-3da1ecc777f0');
console.log(response.data);resultPOST /room_sessions/{room_session_id}/actions/kickexcludeparticipantsconst response = await client.rooms.sessions.actions.kick('0ccc7b54-4df3-4bca-a65a-3da1ecc777f0');
console.log(response.data);resultPOST /room_sessions/{room_session_id}/actions/muteexcludeparticipantsconst response = await client.rooms.sessions.actions.mute('0ccc7b54-4df3-4bca-a65a-3da1ecc777f0');
console.log(response.data);resultPOST /room_sessions/{room_session_id}/actions/unmuteexcludeparticipantsconst response = await client.rooms.sessions.actions.unmute('0ccc7b54-4df3-4bca-a65a-3da1ecc777f0');
console.log(response.data);resultGET /room_sessions/{room_session_id}/participants// Automatically fetches more pages as needed.
for await (const roomParticipant of client.rooms.sessions.retrieveParticipants(
'0ccc7b54-4df3-4bca-a65a-3da1ecc777f0',
)) {
console.log(roomParticipant.id);
}contextidjoined_atleft_atrecord_typesession_idupdated_atGET /rooms// Automatically fetches more pages as needed.
for await (const room of client.rooms.list()) {
console.log(room.id);
}active_session_idcreated_atenable_recordingidmax_participantsrecord_typesessionsunique_nameupdated_atwebhook_event_failover_urlwebhook_event_urlwebhook_timeout_secsPOST /roomsenable_recordingmax_participantsunique_namewebhook_event_failover_urlwebhook_event_urlwebhook_timeout_secsconst room = await client.rooms.create({
uniqueName: 'my-meeting-room',
maxParticipants: 10,
});
console.log(room.data);active_session_idcreated_atenable_recordingidmax_participantsrecord_typesessionsunique_nameupdated_atwebhook_event_failover_urlwebhook_event_urlwebhook_timeout_secsGET /rooms/{room_id}const room = await client.rooms.retrieve('0ccc7b54-4df3-4bca-a65a-3da1ecc777f0');
console.log(room.data);active_session_idcreated_atenable_recordingidmax_participantsrecord_typesessionsunique_nameupdated_atwebhook_event_failover_urlwebhook_event_urlwebhook_timeout_secsPATCH /rooms/{room_id}enable_recordingmax_participantsunique_namewebhook_event_failover_urlwebhook_event_urlwebhook_timeout_secsconst room = await client.rooms.update('0ccc7b54-4df3-4bca-a65a-3da1ecc777f0');
console.log(room.data);active_session_idcreated_atenable_recordingidmax_participantsrecord_typesessionsunique_nameupdated_atwebhook_event_failover_urlwebhook_event_urlwebhook_timeout_secsDELETE /rooms/{room_id}await client.rooms.delete('0ccc7b54-4df3-4bca-a65a-3da1ecc777f0');token_ttl_secsrefresh_token_ttl_secsPOST /rooms/{room_id}/actions/generate_join_client_tokenrefresh_token_ttl_secstoken_ttl_secsconst response = await client.rooms.actions.generateJoinClientToken(
'0ccc7b54-4df3-4bca-a65a-3da1ecc777f0',
);
console.log(response.data);refresh_tokenrefresh_token_expires_attokentoken_expires_attoken_ttl_secsPOST /rooms/{room_id}/actions/refresh_client_tokenrefresh_tokentoken_ttl_secsconst response = await client.rooms.actions.refreshClientToken(
'0ccc7b54-4df3-4bca-a65a-3da1ecc777f0',
{
refresh_token:
'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZWxueXhfdGVsZXBob255IiwiZXhwIjoxNTkwMDEwMTQzLCJpYXQiOjE1ODc1OTA5NDMsImlzcyI6InRlbG55eF90ZWxlcGhvbnkiLCJqdGkiOiJiOGM3NDgzNy1kODllLTRhNjUtOWNmMi0zNGM3YTZmYTYwYzgiLCJuYmYiOjE1ODc1OTA5NDIsInN1YiI6IjVjN2FjN2QwLWRiNjUtNGYxMS05OGUxLWVlYzBkMWQ1YzZhZSIsInRlbF90b2tlbiI6InJqX1pra1pVT1pNeFpPZk9tTHBFVUIzc2lVN3U2UmpaRmVNOXMtZ2JfeENSNTZXRktGQUppTXlGMlQ2Q0JSbWxoX1N5MGlfbGZ5VDlBSThzRWlmOE1USUlzenl6U2xfYURuRzQ4YU81MHlhSEd1UlNZYlViU1ltOVdJaVEwZz09IiwidHlwIjoiYWNjZXNzIn0.gNEwzTow5MLLPLQENytca7pUN79PmPj6FyqZWW06ZeEmesxYpwKh0xRtA0TzLh6CDYIRHrI8seofOO0YFGDhpQ',
},
);
console.log(response.data);tokentoken_expires_atGET /rooms/{room_id}/sessions// Automatically fetches more pages as needed.
for await (const roomSession of client.rooms.sessions.list1(
'0ccc7b54-4df3-4bca-a65a-3da1ecc777f0',
)) {
console.log(roomSession.id);
}activecreated_atended_atidparticipantsrecord_typeroom_idupdated_at