Edits history of script submission #13289 for ' Initiate an outbound call (telnyx)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Telnyx = {
    	apiKey: string
    }
    /**
     * Initiate an outbound call
     * Initiate an outbound TeXML call. Telnyx will request TeXML from the XML Request URL configured for the connection in the Mission Control Portal.
     */
    export async function main(
    	auth: Telnyx,
    	application_id: string,
    	body: {
    		ApplicationSid: string
    		To: string
    		From: string
    		Url?: string
    		UrlMethod?: 'GET' | 'POST'
    		FallbackUrl?: string
    		StatusCallback?: string
    		StatusCallbackMethod?: 'GET' | 'POST'
    		StatusCallbackEvent?: 'initiated' | 'ringing' | 'answered' | 'completed'
    		MachineDetection?: 'Enable' | 'Disable' | 'DetectMessageEnd'
    		DetectionMode?: 'Premium' | 'Regular'
    		AsyncAmd?: false | true
    		AsyncAmdStatusCallback?: string
    		AsyncAmdStatusCallbackMethod?: 'GET' | 'POST'
    		MachineDetectionTimeout?: number
    		MachineDetectionSpeechThreshold?: number
    		MachineDetectionSpeechEndThreshold?: number
    		MachineDetectionSilenceTimeout?: number
    		CancelPlaybackOnMachineDetection?: false | true
    		CancelPlaybackOnDetectMessageEnd?: false | true
    		PreferredCodecs?: string
    		Record?: false | true
    		RecordingChannels?: 'mono' | 'dual'
    		RecordingStatusCallback?: string
    		RecordingStatusCallbackMethod?: 'GET' | 'POST'
    		RecordingStatusCallbackEvent?: string
    		RecordingTimeout?: number
    		RecordingTrack?: 'inbound' | 'outbound' | 'both'
    		SipAuthPassword?: string
    		SipAuthUsername?: string
    		Trim?: 'trim-silence' | 'do-not-trim'
    	}
    ) {
    	const url = new URL(`https://api.telnyx.com/v2/texml/calls/${application_id}`)
    
    	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