Edits history of script submission #13205 for ' Gather using audio (telnyx)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Telnyx = {
    	apiKey: string
    }
    /**
     * Gather using audio
     * Play an audio file on the call until the required DTMF signals are gathered to build interactive menus.
     */
    export async function main(
    	auth: Telnyx,
    	call_control_id: string,
    	body: {
    		audio_url?: string
    		media_name?: string
    		invalid_audio_url?: string
    		invalid_media_name?: string
    		minimum_digits?: number
    		maximum_digits?: number
    		maximum_tries?: number
    		timeout_millis?: number
    		terminating_digit?: string
    		valid_digits?: string
    		inter_digit_timeout_millis?: number
    		client_state?: string
    		command_id?: string
    	}
    ) {
    	const url = new URL(
    		`https://api.telnyx.com/v2/calls/${call_control_id}/actions/gather_using_audio`
    	)
    
    	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