Edits history of script submission #13628 for ' Update call (telnyx)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Telnyx = {
    	apiKey: string
    }
    /**
     * Update call
     * Update TeXML call. Please note that the keys present in the payload MUST BE formatted in CamelCase as specified in the example.
     */
    export async function main(
    	auth: Telnyx,
    	call_sid: string,
    	body: {
    		Status?: string
    		Url?: string
    		Method?: 'GET' | 'POST'
    		FallbackUrl?: string
    		FallbackMethod?: 'GET' | 'POST'
    		StatusCallback?: string
    		StatusCallbackMethod?: 'GET' | 'POST'
    		Texml?: string
    	}
    ) {
    	const url = new URL(`https://api.telnyx.com/v2/texml/calls/${call_sid}/update`)
    
    	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