0

Dial a new conference participant

by
Published Apr 8, 2025

Dials a new conference participant

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Dial a new conference participant
7
 * Dials a new conference participant
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	account_sid: string,
12
	conference_sid: string,
13
	body: {
14
		Beep?: 'true' | 'false' | 'onEnter' | 'onExit'
15
		StatusCallback?: string
16
		StatusCallbackMethod?: 'GET' | 'POST'
17
		StatusCallbackEvent?: string
18
		To?: string
19
		From?: string
20
		Timeout?: number
21
		Muted?: false | true
22
		StartConferenceOnEnter?: false | true
23
		EndConferenceOnExit?: false | true
24
		EarlyMedia?: false | true
25
		ConferenceStatusCallback?: string
26
		ConferenceStatusCallbackMethod?: 'GET' | 'POST'
27
		ConferenceStatusCallbackEvent?: string
28
		WaitUrl?: string
29
		MaxParticipants?: number
30
		Coaching?: false | true
31
		CallSidToCoach?: string
32
		CallerId?: string
33
		TimeLimit?: number
34
		MachineDetection?: 'Enable' | 'DetectMessageEnd'
35
		MachineDetectionTimeout?: number
36
		MachineDetectionSpeechThreshold?: number
37
		MachineDetectionSpeechEndThreshold?: number
38
		MachineDetectionSilenceTimeout?: number
39
		AmdStatusCallback?: string
40
		AmdStatusCallbackMethod?: 'GET' | 'POST'
41
		CancelPlaybackOnMachineDetection?: false | true
42
		CancelPlaybackOnDetectMessageEnd?: false | true
43
		PreferredCodecs?: string
44
		Record?: false | true
45
		RecordingChannels?: 'mono' | 'dual'
46
		RecordingStatusCallback?: string
47
		RecordingStatusCallbackMethod?: 'GET' | 'POST'
48
		RecordingStatusCallbackEvent?: string
49
		RecordingTrack?: 'inbound' | 'outbound' | 'both'
50
		SipAuthPassword?: string
51
		SipAuthUsername?: string
52
		Trim?: 'trim-silence' | 'do-not-trim'
53
		ConferenceRecord?: 'true' | 'false' | 'record-from-start' | 'do-not-record'
54
		ConferenceRecordingStatusCallback?: string
55
		ConferenceRecordingStatusCallbackMethod?: 'GET' | 'POST'
56
		ConferenceRecordingStatusCallbackEvent?: string
57
		ConferenceRecordingTimeout?: number
58
		ConferenceTrim?: 'trim-silence' | 'do-not-trim'
59
	}
60
) {
61
	const url = new URL(
62
		`https://api.telnyx.com/v2/texml/Accounts/${account_sid}/Conferences/${conference_sid}/Participants`
63
	)
64

65
	const response = await fetch(url, {
66
		method: 'POST',
67
		headers: {
68
			'Content-Type': 'application/x-www-form-urlencoded',
69
			Authorization: 'Bearer ' + auth.apiKey
70
		},
71
		body: new URLSearchParams(body as Record<string, string>)
72
	})
73
	if (!response.ok) {
74
		const text = await response.text()
75
		throw new Error(`${response.status} ${text}`)
76
	}
77
	return await response.json()
78
}
79