0

Update call

by
Published Apr 8, 2025

Update TeXML call. Please note that the keys present in the payload MUST BE formatted in CamelCase as specified in the example.

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Update call
7
 * Update TeXML call. Please note that the keys present in the payload MUST BE formatted in CamelCase as specified in the example.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	call_sid: string,
12
	body: {
13
		Status?: string
14
		Url?: string
15
		Method?: 'GET' | 'POST'
16
		FallbackUrl?: string
17
		FallbackMethod?: 'GET' | 'POST'
18
		StatusCallback?: string
19
		StatusCallbackMethod?: 'GET' | 'POST'
20
		Texml?: string
21
	}
22
) {
23
	const url = new URL(`https://api.telnyx.com/v2/texml/calls/${call_sid}/update`)
24

25
	const response = await fetch(url, {
26
		method: 'POST',
27
		headers: {
28
			'Content-Type': 'application/json',
29
			Authorization: 'Bearer ' + auth.apiKey
30
		},
31
		body: JSON.stringify(body)
32
	})
33
	if (!response.ok) {
34
		const text = await response.text()
35
		throw new Error(`${response.status} ${text}`)
36
	}
37
	return await response.json()
38
}
39