0

Set an admin to away

by
Published Dec 20, 2024

You can set an Admin as away for the Inbox.

Script intercom Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Intercom = {
3
	apiVersion: string
4
	token: string
5
}
6
/**
7
 * Set an admin to away
8
 * You can set an Admin as away for the Inbox.
9
 */
10
export async function main(
11
	auth: Intercom,
12
	id: string,
13
	body: { away_mode_enabled: false | true; away_mode_reassign: false | true }
14
) {
15
	const url = new URL(`https://api.intercom.io/admins/${id}/away`)
16

17
	const response = await fetch(url, {
18
		method: 'PUT',
19
		headers: {
20
			'Intercom-Version': auth.apiVersion,
21
			'Content-Type': 'application/json',
22
			Authorization: 'Bearer ' + auth.token
23
		},
24
		body: JSON.stringify(body)
25
	})
26
	if (!response.ok) {
27
		const text = await response.text()
28
		throw new Error(`${response.status} ${text}`)
29
	}
30
	return await response.json()
31
}
32