0

Creates a TeXML Application

by
Published Apr 8, 2025

Creates a TeXML Application.

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Creates a TeXML Application
7
 * Creates a TeXML Application.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	body: {
12
		friendly_name: string
13
		active?: false | true
14
		anchorsite_override?:
15
			| 'Latency'
16
			| 'Chicago, IL'
17
			| 'Ashburn, VA'
18
			| 'San Jose, CA'
19
			| 'Sydney, Australia'
20
			| 'Amsterdam, Netherlands'
21
			| 'London, UK'
22
			| 'Toronto, Canada'
23
			| 'Vancouver, Canada'
24
			| 'Frankfurt, Germany'
25
		dtmf_type?: 'RFC 2833' | 'Inband' | 'SIP INFO'
26
		first_command_timeout?: false | true
27
		first_command_timeout_secs?: number
28
		voice_url: string
29
		voice_fallback_url?: string
30
		voice_method?: 'get' | 'post'
31
		status_callback?: string
32
		status_callback_method?: 'get' | 'post'
33
		inbound?: {
34
			channel_limit?: number
35
			shaken_stir_enabled?: false | true
36
			sip_subdomain?: string
37
			sip_subdomain_receive_settings?: 'only_my_connections' | 'from_anyone'
38
		}
39
		outbound?: { channel_limit?: number; outbound_voice_profile_id?: string }
40
	}
41
) {
42
	const url = new URL(`https://api.telnyx.com/v2/texml_applications`)
43

44
	const response = await fetch(url, {
45
		method: 'POST',
46
		headers: {
47
			'Content-Type': 'application/json',
48
			Authorization: 'Bearer ' + auth.apiKey
49
		},
50
		body: JSON.stringify(body)
51
	})
52
	if (!response.ok) {
53
		const text = await response.text()
54
		throw new Error(`${response.status} ${text}`)
55
	}
56
	return await response.json()
57
}
58