-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
42 lines (36 loc) · 996 Bytes
/
main.go
File metadata and controls
42 lines (36 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"context"
"fmt"
"log"
dialogflow "google.golang.org/api/dialogflow/v3"
"google.golang.org/api/option"
)
func main() {
// Replace with your project ID and service account key file path
projectID := "your-project-id"
keyFilePath := "path/to/your/key.json"
// Create a new Dialogflow CX client
ctx := context.Background()
client, err := dialogflow.NewService(ctx, option.WithCredentialsFile(keyFilePath))
if err != nil {
log.Fatalf("Error creating Dialogflow CX client: %v", err)
}
// Create a new agent
agent := &dialogflow.Agent{
DisplayName: "My Agent",
}
createdAgent, err := client.Agents.Create(projectID, agent).Do()
if err != nil {
log.Fatalf("Error creating agent: %v", err)
}
fmt.Println("Agent created:", createdAgent.Name)
// List agents
agents, err := client.Agents.List(projectID).Do()
if err != nil {
log.Fatalf("Error listing agents: %v", err)
}
for _, agent := range agents.Agents {
fmt.Println(agent.DisplayName)
}
}