Edits history of script submission #13007 for ' Answer call (telnyx)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Telnyx = {
    	apiKey: string
    }
    /**
     * Answer call
     * Answer an incoming call. You must issue this command before executing subsequent commands on an incoming call.
    
    **Expected Webhooks (see [callback schema](https://developers.telnyx.com/api/call-control/answer-call#callbacks) below):**
    
    - `call.answered`
    - `streaming.started`, `streaming.stopped` or `streaming.failed` if `stream_url` was set
    
     */
    export async function main(
    	auth: Telnyx,
    	call_control_id: string,
    	body: {
    		billing_group_id?: string
    		client_state?: string
    		command_id?: string
    		custom_headers?: { name: string; value: string }[]
    		preferred_codecs?: 'G722,PCMU,PCMA,G729,OPUS,VP8,H264'
    		sip_headers?: { name: 'User-to-User'; value: string }[]
    		sound_modifications?: {
    			pitch?: number
    			semitone?: number
    			octaves?: number
    			track?: string
    		}
    		stream_url?: string
    		stream_track?: 'inbound_track' | 'outbound_track' | 'both_tracks'
    		stream_bidirectional_mode?: 'mp3' | 'rtp'
    		stream_bidirectional_codec?: 'PCMU' | 'PCMA' | 'G722'
    		stream_bidirectional_target_legs?: 'both' | 'self' | 'opposite'
    		send_silence_when_idle?: false | true
    		webhook_url?: string
    		webhook_url_method?: 'POST' | 'GET'
    		transcription?: false | true
    		transcription_config?: {
    			transcription_engine?: 'A' | 'B'
    			language?:
    				| 'af'
    				| 'sq'
    				| 'am'
    				| 'ar'
    				| 'hy'
    				| 'az'
    				| 'eu'
    				| 'bn'
    				| 'bs'
    				| 'bg'
    				| 'my'
    				| 'ca'
    				| 'yue'
    				| 'zh'
    				| 'hr'
    				| 'cs'
    				| 'da'
    				| 'nl'
    				| 'en'
    				| 'et'
    				| 'fil'
    				| 'fi'
    				| 'fr'
    				| 'gl'
    				| 'ka'
    				| 'de'
    				| 'el'
    				| 'gu'
    				| 'iw'
    				| 'hi'
    				| 'hu'
    				| 'is'
    				| 'id'
    				| 'it'
    				| 'ja'
    				| 'jv'
    				| 'kn'
    				| 'kk'
    				| 'km'
    				| 'ko'
    				| 'lo'
    				| 'lv'
    				| 'lt'
    				| 'mk'
    				| 'ms'
    				| 'ml'
    				| 'mr'
    				| 'mn'
    				| 'ne'
    				| 'no'
    				| 'fa'
    				| 'pl'
    				| 'pt'
    				| 'pa'
    				| 'ro'
    				| 'ru'
    				| 'rw'
    				| 'sr'
    				| 'si'
    				| 'sk'
    				| 'sl'
    				| 'ss'
    				| 'st'
    				| 'es'
    				| 'su'
    				| 'sw'
    				| 'sv'
    				| 'ta'
    				| 'te'
    				| 'th'
    				| 'tn'
    				| 'tr'
    				| 'ts'
    				| 'uk'
    				| 'ur'
    				| 'uz'
    				| 've'
    				| 'vi'
    				| 'xh'
    				| 'zu'
    				| 'he'
    				| 'la'
    				| 'mi'
    				| 'cy'
    				| 'br'
    				| 'sn'
    				| 'yo'
    				| 'so'
    				| 'oc'
    				| 'be'
    				| 'tg'
    				| 'sd'
    				| 'yi'
    				| 'fo'
    				| 'ht'
    				| 'ps'
    				| 'tk'
    				| 'nn'
    				| 'mt'
    				| 'sa'
    				| 'lb'
    				| 'bo'
    				| 'tl'
    				| 'mg'
    				| 'as'
    				| 'tt'
    				| 'haw'
    				| 'ln'
    				| 'ha'
    				| 'ba'
    				| 'jw'
    				| 'auto_detect'
    			interim_results?: false | true
    			enable_speaker_diarization?: false | true
    			min_speaker_count?: number
    			max_speaker_count?: number
    			client_state?: string
    			transcription_tracks?: string
    			command_id?: string
    		}
    		record?: 'record-from-answer'
    		record_channels?: 'single' | 'dual'
    		record_format?: 'mp3' | 'wav'
    		record_max_length?: number
    		record_timeout_secs?: number
    		record_track?: 'both' | 'inbound' | 'outbound'
    		record_trim?: 'trim-silence'
    		record_custom_file_name?: string
    	}
    ) {
    	const url = new URL(`https://api.telnyx.com/v2/calls/${call_control_id}/actions/answer`)
    
    	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