Edits history of script submission #13006 for ' Add a Notification Setting (telnyx)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Telnyx = {
    	apiKey: string
    }
    /**
     * Add a Notification Setting
     * Add a notification setting.
     */
    export async function main(
    	auth: Telnyx,
    	body: {
    		id?: string
    		notification_event_condition_id?: string
    		notification_profile_id?: string
    		associated_record_type?: string
    		associated_record_type_value?: string
    		status?:
    			| 'enabled'
    			| 'enable-received'
    			| 'enable-pending'
    			| 'enable-submtited'
    			| 'delete-received'
    			| 'delete-pending'
    			| 'delete-submitted'
    			| 'deleted'
    		notification_channel_id?: string
    		parameters?: { name?: string; value?: string }[]
    		created_at?: string
    		updated_at?: string
    	}
    ) {
    	const url = new URL(`https://api.telnyx.com/v2/notification_settings`)
    
    	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