0

Create a messaging profile

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 messaging profile
7
 *
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	body: {
12
		name: string
13
		whitelisted_destinations: string[]
14
		enabled?: false | true
15
		webhook_url?: string
16
		webhook_failover_url?: string
17
		webhook_api_version?: '1' | '2' | '2010-04-01'
18
		number_pool_settings?: {
19
			toll_free_weight: number
20
			long_code_weight: number
21
			skip_unhealthy: false | true
22
			sticky_sender?: false | true
23
			geomatch?: false | true
24
		}
25
		url_shortener_settings?: {
26
			domain: string
27
			prefix?: string
28
			replace_blacklist_only?: false | true
29
			send_webhooks?: false | true
30
		}
31
		alpha_sender?: string
32
	}
33
) {
34
	const url = new URL(`https://api.telnyx.com/v2/messaging_profiles`)
35

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