Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Biasanya, Anda membuat dan menghapus agen menggunakan konsol.
Namun, dalam skenario lanjutan tertentu, Anda mungkin merasa lebih mudah menggunakan API.
Buat agen
Contoh berikut menunjukkan cara memanggil metode SetAgent untuk jenis
Agent.
Contoh ini membuat agen, tetapi metode yang sama dapat digunakan untuk memperbarui setelan agen, seperti edisi agen.
REST
Sebelum menggunakan salah satu data permintaan,
lakukan penggantian berikut:
PROJECT_ID: project ID Google Cloud Anda
Metode HTTP dan URL:
POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/agent
importcom.google.cloud.dialogflow.v2.Agent;importcom.google.cloud.dialogflow.v2.Agent.Builder;importcom.google.cloud.dialogflow.v2.AgentsClient;importcom.google.cloud.dialogflow.v2.AgentsSettings;importjava.io.IOException;publicclassSetAgent{publicstaticvoidmain(String[]args)throwsIOException{StringprojectId="my-project-id";// The display name will set the name of your agentStringdisplayName="my-display-name";setAgent(projectId,displayName);}publicstaticAgentsetAgent(Stringparent,StringdisplayName)throwsIOException{AgentsSettingsagentsSettings=AgentsSettings.newBuilder().build();try(AgentsClientclient=AgentsClient.create(agentsSettings)){// Set the details of the Agent to createBuilderbuild=Agent.newBuilder();build.setDefaultLanguageCode("en");build.setDisplayName(displayName);Agentagent=build.build();// Make API request to create agentAgentresponse=client.setAgent(agent);System.out.println(response);returnresponse;}}}
const{AgentsClient}=require('@google-cloud/dialogflow');// make sure to pass projectID as the input parameterconstparent='projects/'+parentId+'/locations/global';constagent={parent:parent,displayName:displayName,defaultLanguageCode:'en',timeZone:'America/Los_Angeles',};constclient=newAgentsClient();asyncfunctionsetAgent(){constrequest={agent,};const[response]=awaitclient.setAgent(request);console.log(`response: ${JSON.stringify(response,null,2)}`);}awaitsetAgent();
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-18 UTC."],[[["\u003cp\u003eThe API can be used to create and delete agents, which are operations typically done via the console, in certain advanced scenarios.\u003c/p\u003e\n"],["\u003cp\u003eCreating or updating agents via the API involves using the \u003ccode\u003eSetAgent\u003c/code\u003e method and provides the ability to configure agent settings like display name, default language, and time zone.\u003c/p\u003e\n"],["\u003cp\u003eDeleting agents via the API is achieved using the \u003ccode\u003eDeleteAgent\u003c/code\u003e method, and successful deletion returns a 2xx status code with an empty response.\u003c/p\u003e\n"],["\u003cp\u003eBoth creating and deleting agents via the API requires a role with full or edit access.\u003c/p\u003e\n"],["\u003cp\u003eAuthentication for API interactions with Dialogflow requires setting up Application Default Credentials, as outlined in the documentation.\u003c/p\u003e\n"]]],[],null,[]]