//native
type Intercom = {
apiVersion: string
token: string
}
/**
* Convert a visitor
* You can merge a Visitor to a Contact of role type `lead` or `user`.
> 📘 What happens upon a visitor being converted?
>
> If the User exists, then the Visitor will be merged into it, the Visitor deleted and the User returned. If the User does not exist, the Visitor will be converted to a User, with the User identifiers replacing it's Visitor identifiers.
*/
export async function main(auth: Intercom, body: { type: string; user: {}; visitor: {} }) {
const url = new URL(`https://api.intercom.io/visitors/convert`)
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