0

Create a comment

by
Published Apr 8, 2025
Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Create a comment
7
 *
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	body: {
12
		id?: string
13
		body?: string
14
		commenter?: string
15
		commenter_type?: 'admin' | 'user'
16
		comment_record_type?: 'sub_number_order' | 'requirement_group'
17
		comment_record_id?: string
18
		read_at?: string
19
		created_at?: string
20
		updated_at?: string
21
	}
22
) {
23
	const url = new URL(`https://api.telnyx.com/v2/comments`)
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