//native
type Intercom = {
apiVersion: string
token: string
}
/**
* List all conversations
* You can fetch a list of all conversations.
*/
export async function main(
auth: Intercom,
per_page: string | undefined,
starting_after: string | undefined
) {
const url = new URL(`https://api.intercom.io/conversations`)
for (const [k, v] of [
['per_page', per_page],
['starting_after', starting_after]
]) {
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 536 days ago