Edits history of script submission #13176 for ' Dial (telnyx)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Telnyx = {
    	apiKey: string
    }
    /**
     * Dial
     * Dial a number or SIP URI from a given connection.
     */
    export async function main(
    	auth: Telnyx,
    	body: {
    		to: string | string[]
    		from: string
    		from_display_name?: string
    		connection_id: string
    		audio_url?: string
    		media_name?: string
    		preferred_codecs?: 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
    		}
    		conference_config?: {
    			id?: string
    			conference_name?: string
    			early_media?: false | true
    			end_conference_on_exit?: false | true
    			soft_end_conference_on_exit?: false | true
    			hold?: false | true
    			hold_audio_url?: string
    			hold_media_name?: string
    			mute?: false | true
    			start_conference_on_enter?: false | true
    			start_conference_on_create?: false | true
    			supervisor_role?: 'barge' | 'monitor' | 'none' | 'whisper'
    			whisper_call_control_ids?: string[]
    			beep_enabled?: 'always' | 'never' | 'on_enter' | 'on_exit'
    		}
    		custom_headers?: { name: string; value: string }[]
    		billing_group_id?: string
    		client_state?: string
    		command_id?: string
    		link_to?: 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
    		}
    		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'
    		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
    		enable_dialogflow?: false | true
    		dialogflow_config?: {
    			analyze_sentiment?: false | true
    			partial_automated_agent_reply?: false | true
    		}
    		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
    		}
    	}
    ) {
    	const url = new URL(`https://api.telnyx.com/v2/calls`)
    
    	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