0

Create a phone Switch

by
Published Dec 20, 2024

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.

Script intercom Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Intercom = {
3
	apiVersion: string
4
	token: string
5
}
6
/**
7
 * Create a phone Switch
8
 * You can use the API to deflect phone calls to the Intercom Messenger.
9
Calling this endpoint will send an SMS with a link to the Messenger to the phone number specified.
10

11
If custom attributes are specified, they will be added to the user or lead's custom data attributes.
12

13
 */
14
export async function main(auth: Intercom, body: { phone: string; custom_attributes?: {} }) {
15
	const url = new URL(`https://api.intercom.io/phone_call_redirects`)
16

17
	const response = await fetch(url, {
18
		method: 'POST',
19
		headers: {
20
			'Intercom-Version': auth.apiVersion,
21
			'Content-Type': 'application/json',
22
			Authorization: 'Bearer ' + auth.token
23
		},
24
		body: JSON.stringify(body)
25
	})
26
	if (!response.ok) {
27
		const text = await response.text()
28
		throw new Error(`${response.status} ${text}`)
29
	}
30
	return await response.json()
31
}
32