Edits history of script submission #11182 for ' Set an admin to away (intercom)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Intercom = {
    	apiVersion: string
    	token: string
    }
    /**
     * Set an admin to away
     * You can set an Admin as away for the Inbox.
     */
    export async function main(
    	auth: Intercom,
    	id: string,
    	body: { away_mode_enabled: false | true; away_mode_reassign: false | true }
    ) {
    	const url = new URL(`https://api.intercom.io/admins/${id}/away`)
    
    	const response = await fetch(url, {
    		method: 'PUT',
    		headers: {
    			'Intercom-Version': auth.apiVersion,
    			'Content-Type': 'application/json',
    			Authorization: 'Bearer ' + auth.token
    		},
    		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 536 days ago