//native
/**
* Add Comment to Thread
* Add an internal comment to a conversation thread. Comments are visible to your team only, never to the visitor. Requires conversations.write.
*/
export async function main(
auth: RT.Hubspot,
thread_id: string,
text: string,
rich_text: string | undefined,
file_ids: string[] | undefined
) {
const body: { [key: string]: any } = { type: "COMMENT", text }
if (rich_text != null && rich_text !== "") body.richText = rich_text
if (file_ids?.length) {
body.attachments = file_ids.map((fileId) => ({ fileId, type: "FILE" }))
}
const response = await fetch(
`https://api.hubapi.com/conversations/v3/conversations/threads/${thread_id}/messages`,
{
method: "POST",
headers: {
Authorization: `Bearer ${auth.token}`,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify(body),
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 4 hours ago