//native
type Intercom = {
apiVersion: string
token: string
}
/**
* Retrieve a conversation
*
You can fetch the details of a single conversation.
*/
export async function main(auth: Intercom, id: string, display_as: string | undefined) {
const url = new URL(`https://api.intercom.io/conversations/${id}`)
for (const [k, v] of [['display_as', display_as]]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'GET',
headers: {
'Intercom-Version': auth.apiVersion,
Authorization: 'Bearer ' + auth.token
},
body: undefined
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 537 days ago