Edits history of script submission #13431 for ' Play audio URL (telnyx)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Telnyx = {
    	apiKey: string
    }
    /**
     * Play audio URL
     * Play an audio file on the call.
     */
    export async function main(
    	auth: Telnyx,
    	call_control_id: string,
    	body: {
    		audio_url?: string
    		media_name?: string
    		loop?: string | number
    		overlay?: false | true
    		stop?: string
    		target_legs?: string
    		cache_audio?: false | true
    		audio_type?: 'mp3' | 'wav'
    		playback_content?: string
    		client_state?: string
    		command_id?: string
    	}
    ) {
    	const url = new URL(`https://api.telnyx.com/v2/calls/${call_control_id}/actions/playback_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