Edits history of script submission #13345 for ' List all active calls for given connection (telnyx)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Telnyx = {
    	apiKey: string
    }
    /**
     * List all active calls for given connection
     * Lists all active calls for given connection. Acceptable connections are either SIP connections with webhook_url or xml_request_url, call control or texml. Returned results are cursor paginated.
    
     */
    export async function main(
    	auth: Telnyx,
    	connection_id: string,
    	page_limit_: string | undefined,
    	page_after_: string | undefined,
    	page_before_: string | undefined
    ) {
    	const url = new URL(`https://api.telnyx.com/v2/connections/${connection_id}/active_calls`)
    	for (const [k, v] of [
    		['page[limit]', page_limit_],
    		['page[after]', page_after_],
    		['page[before]', page_before_]
    	]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			Authorization: 'Bearer ' + auth.apiKey
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 428 days ago