//native
type Intercom = {
apiVersion: string
token: string
}
/**
* Manage a conversation
* For managing conversations you can:
- Close a conversation
- Snooze a conversation to reopen on a future date
- Open a conversation which is `snoozed` or `closed`
- Assign a conversation to an admin and/or team.
*/
export async function main(
auth: Intercom,
id: string,
body:
| { message_type: 'close'; type: 'admin'; admin_id: string; body?: string }
| { message_type: 'snoozed'; admin_id: string; snoozed_until: number }
| { message_type: 'open'; admin_id: string }
| {
message_type: 'assignment'
type: 'admin' | 'team'
admin_id: string
assignee_id: string
body?: string
}
) {
const url = new URL(`https://api.intercom.io/conversations/${id}/parts`)
const response = await fetch(url, {
method: 'POST',
headers: {
'Intercom-Version': auth.apiVersion,
'Content-Type': 'application/json',
Authorization: 'Bearer ' + auth.token
},
body: JSON.stringify(body)
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 536 days ago