Edits history of script submission #13577 for ' Transfer call (telnyx)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Telnyx = {
    	apiKey: string
    }
    /**
     * Transfer call
     * Transfer a call to a new destination.
     */
    export async function main(
    	auth: Telnyx,
    	call_control_id: string,
    	body: {
    		to: string
    		from?: string
    		from_display_name?: string
    		audio_url?: string
    		early_media?: false | true
    		media_name?: string
    		timeout_secs?: number
    		time_limit_secs?: number
    		answering_machine_detection?:
    			| 'premium'
    			| 'detect'
    			| 'detect_beep'
    			| 'detect_words'
    			| 'greeting_end'
    			| 'disabled'
    		answering_machine_detection_config?: {
    			total_analysis_time_millis?: number
    			after_greeting_silence_millis?: number
    			between_words_silence_millis?: number
    			greeting_duration_millis?: number
    			initial_silence_millis?: number
    			maximum_number_of_words?: number
    			maximum_word_length_millis?: number
    			silence_threshold?: number
    			greeting_total_analysis_time_millis?: number
    			greeting_silence_duration_millis?: number
    		}
    		custom_headers?: { name: string; value: string }[]
    		client_state?: string
    		target_leg_client_state?: string
    		command_id?: string
    		media_encryption?: 'disabled' | 'SRTP'
    		sip_auth_username?: string
    		sip_auth_password?: string
    		sip_headers?: { name: 'User-to-User'; value: string }[]
    		sip_transport_protocol?: 'UDP' | 'TCP' | 'TLS'
    		sound_modifications?: {
    			pitch?: number
    			semitone?: number
    			octaves?: number
    			track?: string
    		}
    		webhook_url?: string
    		webhook_url_method?: 'POST' | 'GET'
    	}
    ) {
    	const url = new URL(`https://api.telnyx.com/v2/calls/${call_control_id}/actions/transfer`)
    
    	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