0

Detach a contact from a group conversation

by
Published Dec 20, 2024

You can add participants who are contacts to a conversation, on behalf of either another contact or an admin. {% admonition type="attention" name="Contacts without an email" %} If you add a contact via the email parameter and there is no user/lead found on that workspace with he given email, then we will create a new contact with `role` set to `lead`. {% /admonition %}

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
 * Detach a contact from a group conversation
8
 * You can add participants who are contacts to a conversation, on behalf of either another contact or an admin.
9

10
{% admonition type="attention" name="Contacts without an email" %}
11
If you add a contact via the email parameter and there is no user/lead found on that workspace with he given email, then we will create a new contact with `role` set to `lead`.
12
{% /admonition %}
13

14

15
 */
16
export async function main(
17
	auth: Intercom,
18
	conversation_id: string,
19
	contact_id: string,
20
	body: { admin_id: string }
21
) {
22
	const url = new URL(
23
		`https://api.intercom.io/conversations/${conversation_id}/customers/${contact_id}`
24
	)
25

26
	const response = await fetch(url, {
27
		method: 'DELETE',
28
		headers: {
29
			'Intercom-Version': auth.apiVersion,
30
			'Content-Type': 'application/json',
31
			Authorization: 'Bearer ' + auth.token
32
		},
33
		body: JSON.stringify(body)
34
	})
35
	if (!response.ok) {
36
		const text = await response.text()
37
		throw new Error(`${response.status} ${text}`)
38
	}
39
	return await response.json()
40
}
41