0

Create a Dialogflow Connection

by
Published Apr 8, 2025

Save Dialogflow Credentiails to Telnyx, so it can be used with other Telnyx services.

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 Dialogflow Connection
7
 * Save Dialogflow Credentiails to Telnyx, so it can be used with other Telnyx services.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	connection_id: string,
12
	body: {
13
		service_account: {}
14
		dialogflow_api?: 'cx' | 'es'
15
		conversation_profile_id?: string
16
		location?: string
17
		environment?: string
18
	}
19
) {
20
	const url = new URL(`https://api.telnyx.com/v2/dialogflow_connections/${connection_id}`)
21

22
	const response = await fetch(url, {
23
		method: 'POST',
24
		headers: {
25
			'Content-Type': 'application/json',
26
			Authorization: 'Bearer ' + auth.apiKey
27
		},
28
		body: JSON.stringify(body)
29
	})
30
	if (!response.ok) {
31
		const text = await response.text()
32
		throw new Error(`${response.status} ${text}`)
33
	}
34
	return await response.json()
35
}
36