0

Create an outbound voice profile

by
Published Apr 8, 2025

Create an outbound voice profile.

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 an outbound voice profile
7
 * Create an outbound voice profile.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	body: {
12
		name: string
13
		traffic_type?: 'conversational'
14
		service_plan?: 'global'
15
		concurrent_call_limit?: number
16
		enabled?: false | true
17
		tags?: string[]
18
		usage_payment_method?: 'rate-deck'
19
		whitelisted_destinations?: string[]
20
		max_destination_rate?: number
21
		daily_spend_limit?: string
22
		daily_spend_limit_enabled?: false | true
23
		call_recording?: {
24
			call_recording_type?: 'all' | 'none' | 'by_caller_phone_number'
25
			call_recording_caller_phone_numbers?: string[]
26
			call_recording_channels?: 'single' | 'dual'
27
			call_recording_format?: 'wav' | 'mp3'
28
		}
29
		billing_group_id?: string
30
	}
31
) {
32
	const url = new URL(`https://api.telnyx.com/v2/outbound_voice_profiles`)
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