//native
type Intercom = {
apiVersion: string
token: string
}
/**
* Create a phone Switch
* You can use the API to deflect phone calls to the Intercom Messenger.
Calling this endpoint will send an SMS with a link to the Messenger to the phone number specified.
If custom attributes are specified, they will be added to the user or lead's custom data attributes.
*/
export async function main(auth: Intercom, body: { phone: string; custom_attributes?: {} }) {
const url = new URL(`https://api.intercom.io/phone_call_redirects`)
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