0

List Auto-Response Settings

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
 * List Auto-Response Settings
7
 *
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	profile_id: string,
12
	country_code: string | undefined,
13
	created_at_gte_: string | undefined,
14
	created_at_lte_: string | undefined,
15
	updated_at_gte_: string | undefined,
16
	updated_at_lte_: string | undefined
17
) {
18
	const url = new URL(`https://api.telnyx.com/v2/messaging_profiles/${profile_id}/autoresp_configs`)
19
	for (const [k, v] of [
20
		['country_code', country_code],
21
		['created_at[gte]', created_at_gte_],
22
		['created_at[lte]', created_at_lte_],
23
		['updated_at[gte]', updated_at_gte_],
24
		['updated_at[lte]', updated_at_lte_]
25
	]) {
26
		if (v !== undefined && v !== '' && k !== undefined) {
27
			url.searchParams.append(k, v)
28
		}
29
	}
30
	const response = await fetch(url, {
31
		method: 'GET',
32
		headers: {
33
			Authorization: 'Bearer ' + auth.apiKey
34
		},
35
		body: undefined
36
	})
37
	if (!response.ok) {
38
		const text = await response.text()
39
		throw new Error(`${response.status} ${text}`)
40
	}
41
	return await response.json()
42
}
43