Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
In genere, gli agenti vengono creati ed eliminati utilizzando la console.
Tuttavia, in alcuni scenari avanzati,
potresti trovare più semplice utilizzare l'API.
Crea un agente
Gli esempi seguenti mostrano come chiamare il metodo SetAgent per il tipo
Agente.
Questi esempi creano agenti,
ma gli stessi metodi possono essere utilizzati per aggiornare le impostazioni degli agenti,
come l'edizione dell'agente.
REST
Prima di utilizzare i dati della richiesta,
apporta le seguenti sostituzioni:
PROJECT_ID: l'ID del tuo progetto Google Cloud
Metodo HTTP e 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();
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-04 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,[]]