Edits history of script submission #13348 for ' List all call recordings (telnyx)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Telnyx = {
    	apiKey: string
    }
    /**
     * List all call recordings
     * Returns a list of your call recordings.
     */
    export async function main(
    	auth: Telnyx,
    	filter_conference_id_: string | undefined,
    	filter_created_at__gte_: string | undefined,
    	filter_created_at__lte_: string | undefined,
    	filter_call_leg_id_: string | undefined,
    	filter_call_session_id_: string | undefined,
    	filter_from_: string | undefined,
    	filter_to_: string | undefined,
    	filter_connection_id_: string | undefined,
    	page_number_: string | undefined,
    	page_size_: string | undefined
    ) {
    	const url = new URL(`https://api.telnyx.com/v2/recordings`)
    	for (const [k, v] of [
    		['filter[conference_id]', filter_conference_id_],
    		['filter[created_at][gte]', filter_created_at__gte_],
    		['filter[created_at][lte]', filter_created_at__lte_],
    		['filter[call_leg_id]', filter_call_leg_id_],
    		['filter[call_session_id]', filter_call_session_id_],
    		['filter[from]', filter_from_],
    		['filter[to]', filter_to_],
    		['filter[connection_id]', filter_connection_id_],
    		['page[number]', page_number_],
    		['page[size]', page_size_]
    	]) {
    		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