Edits history of script submission #13203 for ' Gather (telnyx)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Telnyx = {
    	apiKey: string
    }
    /**
     * Gather
     * Gather DTMF signals to build interactive menus.
    
    You can pass a list of valid digits. The `Answer` command must be issued before the `gather` command.
    
    **Expected Webhooks (see [callback schema](https://developers.telnyx.com/api/call-control/gather-call#callbacks) below):**
    
    - `call.dtmf.received` (you may receive many of these webhooks)
    - `call.gather.ended`
    
     */
    export async function main(
    	auth: Telnyx,
    	call_control_id: string,
    	body: {
    		minimum_digits?: number
    		maximum_digits?: number
    		timeout_millis?: number
    		inter_digit_timeout_millis?: number
    		initial_timeout_millis?: number
    		terminating_digit?: string
    		valid_digits?: string
    		gather_id?: string
    		client_state?: string
    		command_id?: string
    	}
    ) {
    	const url = new URL(`https://api.telnyx.com/v2/calls/${call_control_id}/actions/gather`)
    
    	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