Edits history of script submission #13541 for ' SIPREC start (telnyx)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Telnyx = {
    	apiKey: string
    }
    /**
     * SIPREC start
     * Start siprec session to configured in SIPREC connector SRS. 
    
    **Expected Webhooks:**
    
    - `siprec.started`
    - `siprec.stopped`
    - `siprec.failed`
    
     */
    export async function main(
    	auth: Telnyx,
    	call_control_id: string,
    	body: {
    		connector_name?: string
    		siprec_track?: 'inbound_track' | 'outbound_track' | 'both_tracks'
    		include_metadata_custom_headers?: false | true
    		secure?: false | true
    		session_timeout_secs?: number
    		client_state?: string
    	}
    ) {
    	const url = new URL(`https://api.telnyx.com/v2/calls/${call_control_id}/actions/siprec_start`)
    
    	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