Edits history of script submission #13616 for ' Update a phone number with voice settings (telnyx)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Telnyx = {
    	apiKey: string
    }
    /**
     * Update a phone number with voice settings
     *
     */
    export async function main(
    	auth: Telnyx,
    	id: string,
    	body: {
    		tech_prefix_enabled?: false | true
    		translated_number?: string
    		caller_id_name_enabled?: false | true
    		call_forwarding?: {
    			call_forwarding_enabled?: false | true
    			forwards_to?: string
    			forwarding_type?: 'always' | 'on_failure'
    		}
    		cnam_listing?: {
    			cnam_listing_enabled?: false | true
    			cnam_listing_details?: string
    		}
    		usage_payment_method?: 'pay-per-minute' | 'channel'
    		media_features?: {
    			rtp_auto_adjust_enabled?: false | true
    			accept_any_rtp_packets_enabled?: false | true
    			t38_fax_gateway_enabled?: false | true
    		}
    		call_recording?: {
    			inbound_call_recording_enabled?: false | true
    			inbound_call_recording_format?: 'wav' | 'mp3'
    			inbound_call_recording_channels?: 'single' | 'dual'
    		}
    		inbound_call_screening?: 'disabled' | 'reject_calls' | 'flag_calls'
    	}
    ) {
    	const url = new URL(`https://api.telnyx.com/v2/phone_numbers/${id}/voice`)
    
    	const response = await fetch(url, {
    		method: 'PATCH',
    		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