0

Redact a conversation part

by
Published Dec 20, 2024

You can redact a conversation part or the source message of a conversation (as seen in the source object). {% admonition type="info" name="Redacting parts and messages" %} If you are redacting a conversation part, it must have a `body`. If you are redacting a source message, it must have been created by a contact. We will return a `conversation_part_not_redactable` error if these criteria are not met. {% /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
 * Redact a conversation part
8
 * You can redact a conversation part or the source message of a conversation (as seen in the source object).
9

10
{% admonition type="info" name="Redacting parts and messages" %}
11
If you are redacting a conversation part, it must have a `body`. If you are redacting a source message, it must have been created by a contact. We will return a `conversation_part_not_redactable` error if these criteria are not met.
12
{% /admonition %}
13

14

15
 */
16
export async function main(
17
	auth: Intercom,
18
	body:
19
		| {
20
				type: 'conversation_part'
21
				conversation_id: string
22
				conversation_part_id: string
23
		  }
24
		| { type: 'source'; conversation_id: string; source_id: string }
25
) {
26
	const url = new URL(`https://api.intercom.io/conversations/redact`)
27

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