0

Add a Notification Setting

by
Published Apr 8, 2025

Add a notification setting.

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Add a Notification Setting
7
 * Add a notification setting.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	body: {
12
		id?: string
13
		notification_event_condition_id?: string
14
		notification_profile_id?: string
15
		associated_record_type?: string
16
		associated_record_type_value?: string
17
		status?:
18
			| 'enabled'
19
			| 'enable-received'
20
			| 'enable-pending'
21
			| 'enable-submtited'
22
			| 'delete-received'
23
			| 'delete-pending'
24
			| 'delete-submitted'
25
			| 'deleted'
26
		notification_channel_id?: string
27
		parameters?: { name?: string; value?: string }[]
28
		created_at?: string
29
		updated_at?: string
30
	}
31
) {
32
	const url = new URL(`https://api.telnyx.com/v2/notification_settings`)
33

34
	const response = await fetch(url, {
35
		method: 'POST',
36
		headers: {
37
			'Content-Type': 'application/json',
38
			Authorization: 'Bearer ' + auth.apiKey
39
		},
40
		body: JSON.stringify(body)
41
	})
42
	if (!response.ok) {
43
		const text = await response.text()
44
		throw new Error(`${response.status} ${text}`)
45
	}
46
	return await response.json()
47
}
48