0

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

42
	const response = await fetch(url, {
43
		method: 'PATCH',
44
		headers: {
45
			'Content-Type': 'application/json',
46
			Authorization: 'Bearer ' + auth.apiKey
47
		},
48
		body: JSON.stringify(body)
49
	})
50
	if (!response.ok) {
51
		const text = await response.text()
52
		throw new Error(`${response.status} ${text}`)
53
	}
54
	return await response.json()
55
}
56