0

Update a conversation

by
Published Dec 20, 2024

You can update an existing conversation. {% admonition type="info" name="Replying and other actions" %} If you want to reply to a coveration or take an action such as assign, unassign, open, close or snooze, take a look at the reply and manage endpoints. {% /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
 * Update a conversation
8
 * 
9
You can update an existing conversation.
10

11
{% admonition type="info" name="Replying and other actions" %}
12
If you want to reply to a coveration or take an action such as assign, unassign, open, close or snooze, take a look at the reply and manage endpoints.
13
{% /admonition %}
14

15

16
 */
17
export async function main(
18
	auth: Intercom,
19
	id: string,
20
	display_as: string | undefined,
21
	body: { read?: false | true; custom_attributes?: {} }
22
) {
23
	const url = new URL(`https://api.intercom.io/conversations/${id}`)
24
	for (const [k, v] of [['display_as', display_as]]) {
25
		if (v !== undefined && v !== '' && k !== undefined) {
26
			url.searchParams.append(k, v)
27
		}
28
	}
29
	const response = await fetch(url, {
30
		method: 'PUT',
31
		headers: {
32
			'Intercom-Version': auth.apiVersion,
33
			'Content-Type': 'application/json',
34
			Authorization: 'Bearer ' + auth.token
35
		},
36
		body: JSON.stringify(body)
37
	})
38
	if (!response.ok) {
39
		const text = await response.text()
40
		throw new Error(`${response.status} ${text}`)
41
	}
42
	return await response.json()
43
}
44