//native
type Telnyx = {
apiKey: string
}
/**
* Refresh Client Token to join a room.
* Synchronously refresh an Client Token to join a Room. Client Token is necessary to join a Telnyx Room. Client Token will expire after `apiKey_ttl_secs`.
*/
export async function main(
auth: Telnyx,
room_id: string,
body: { apiKey_ttl_secs?: number; refresh_apiKey: string }
) {
const url = new URL(`https://api.telnyx.com/v2/rooms/${room_id}/actions/refresh_client_apiKey`)
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + auth.apiKey
},
body: JSON.stringify(body)
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 428 days ago