Alguns produtos e recursos estão sendo renomeados. Os recursos de playbook generativo e de fluxo também estão sendo migrados para um único console consolidado. Confira os detalhes.
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Alguns métodos da API Conversational Agents (Dialogflow CX) retornam uma operação de longa duração.
Esses métodos são assíncronos e a operação pode não ser concluída quando o método retornar uma resposta.
É possível verificar o status, aguardar a conclusão ou cancelar operações.
Aguardar a conclusão de uma operação
Veja a seguir como aguardar a conclusão de uma operação.
REST
Para pesquisar o status de uma operação, chame o método get para o recurso
Operations.
Quando a operação for concluída, o campo done será definido como "true".
Antes de usar os dados da solicitação abaixo, faça as substituições a seguir:
importcom.google.api.gax.longrunning.OperationFuture;importcom.google.cloud.dialogflow.cx.v3.AgentName;importcom.google.cloud.dialogflow.cx.v3.AgentsClient;importcom.google.cloud.dialogflow.cx.v3.AgentsSettings;importcom.google.cloud.dialogflow.cx.v3.ExportAgentRequest;importcom.google.cloud.dialogflow.cx.v3.ExportAgentResponse;importcom.google.protobuf.Struct;importjava.io.IOException;importjava.util.concurrent.ExecutionException;publicclassExportAgent{publicstaticvoidmain(String[]args)throwsIOException,InterruptedException,ExecutionException{// TODO(developer): Replace these variables before running the sample.StringprojectId="my-project-id";StringagentId="my-agent-id";Stringlocation="my-location";exportAgent(projectId,agentId,location);}publicstaticvoidexportAgent(StringprojectId,StringagentId,Stringlocation)throwsIOException,InterruptedException,ExecutionException{// Sets the api endpoint to specified locationStringapiEndpoint=String.format("%s-dialogflow.googleapis.com:443",location);AgentsSettingsagentsSettings=AgentsSettings.newBuilder().setEndpoint(apiEndpoint).build();// Note: close() needs to be called on the AgentsClient object to clean up resources// such as threads. In the example below, try-with-resources is used,// which automatically calls close().try(AgentsClientagentsClient=AgentsClient.create(agentsSettings)){ExportAgentRequestrequest=ExportAgentRequest.newBuilder().setName(AgentName.of(projectId,location,agentId).toString()).build();// Returns a future of the operationOperationFuture<ExportAgentResponse,Struct>future=agentsClient.exportAgentOperationCallable().futureCall(request);// get the export agent response after the operation is completedExportAgentResponseresponse=future.get();System.out.println(response);}}}
const{AgentsClient,protos}=require('@google-cloud/dialogflow-cx');constapi_endpoint=`${location}-dialogflow.googleapis.com`;constclient=newAgentsClient({apiEndpoint:api_endpoint});constexportAgentRequest=newprotos.google.cloud.dialogflow.cx.v3.ExportAgentRequest();exportAgentRequest.name=`projects/${projectId}/locations/${location}/agents/${agentId}`;// exportAgent call returns a promise to a long running operationconst[operation]=awaitclient.exportAgent(exportAgentRequest);// Waiting for the long running opporation to finishconst[response]=awaitoperation.promise();// Prints the result of the operation when the operation is doneconsole.log(response);
fromgoogle.cloud.dialogflowcx_v3.services.agents.clientimportAgentsClientfromgoogle.cloud.dialogflowcx_v3.types.agentimportExportAgentRequestdefexport_long_running_agent(project_id,agent_id,location):api_endpoint=f"{location}-dialogflow.googleapis.com:443"client_options={"api_endpoint":api_endpoint}agents_client=AgentsClient(client_options=client_options)export_request=ExportAgentRequest()export_request.name=(f"projects/{project_id}/locations/{location}/agents/{agent_id}")# export_agent returns a long running operationoperation=agents_client.export_agent(request=export_request)# Returns the result of the operation when the operation is donereturnoperation.result()
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-04 UTC."],[[["\u003cp\u003eSome Dialogflow CX API methods involve long-running operations that are asynchronous and may not be immediately completed upon method return.\u003c/p\u003e\n"],["\u003cp\u003eYou can monitor the status of these operations by using the \u003ccode\u003eget\u003c/code\u003e method on the \u003ccode\u003eOperations\u003c/code\u003e resource, where the \u003ccode\u003edone\u003c/code\u003e field indicates completion.\u003c/p\u003e\n"],["\u003cp\u003eWhen checking multiple operations, consider implementing rate limiting or use the \u003ccode\u003elist\u003c/code\u003e method to manage calls effectively.\u003c/p\u003e\n"],["\u003cp\u003eTo wait for an operation to complete, utilize the \u003ccode\u003eget\u003c/code\u003e method (REST), \u003ccode\u003efuture.get()\u003c/code\u003e (Java), \u003ccode\u003eoperation.promise()\u003c/code\u003e (Node.js), or \u003ccode\u003eoperation.result()\u003c/code\u003e (Python), depending on the language being used.\u003c/p\u003e\n"],["\u003cp\u003eThe code examples in REST, Java, Node.js and Python illustrate how to make requests to the API and how to handle long-running operations.\u003c/p\u003e\n"]]],[],null,["# Long-running operations\n\nSome methods of the Conversational Agents (Dialogflow CX) API return a long-running operation.\nThese methods are asynchronous,\nand the operation may not be completed when the method returns a response.\nYou can check on the status, wait for completion, or cancel operations.\n\nWait for an operation to complete\n---------------------------------\n\nThe following shows how to wait for an operation to complete. \n\n### REST\n\nTo poll an operation's status, call the `get` method for the\n[`Operations`](/dialogflow/cx/docs/reference/rest/v3/projects.locations.operations)\nresource.\nWhen the operation has completed,\nthe `done` field is set to true.\n| **Note:** If you have many operations to check, you should rate limit your calls or use the `list` method instead.\n\n\nBefore using any of the request data,\nmake the following replacements:\n\n- \u003cvar translate=\"no\"\u003eREGION_ID\u003c/var\u003e: your [region ID](/dialogflow/cx/docs/concept/region)\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: your Google Cloud project ID\n- \u003cvar translate=\"no\"\u003eOPERATION_ID\u003c/var\u003e: your operation ID\n\n\nHTTP method and URL:\n\n```\nGET https://REGION_ID-dialogflow.googleapis.com/v3/projects/PROJECT_ID/locations/REGION_ID/operations/OPERATION_ID\n```\n\nTo send your request, expand one of these options:\n\n#### curl (Linux, macOS, or Cloud Shell)\n\n| **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](/sdk/gcloud/reference/init) or [`gcloud auth login`](/sdk/gcloud/reference/auth/login) , or by using [Cloud Shell](/shell/docs), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](/sdk/gcloud/reference/auth/list).\n\n\nExecute the following command:\n\n```\ncurl -X GET \\\n -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n -H \"x-goog-user-project: PROJECT_ID\" \\\n \"https://REGION_ID-dialogflow.googleapis.com/v3/projects/PROJECT_ID/locations/REGION_ID/operations/OPERATION_ID\"\n```\n\n#### PowerShell (Windows)\n\n| **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](/sdk/gcloud/reference/init) or [`gcloud auth login`](/sdk/gcloud/reference/auth/login) . You can check the currently active account by running [`gcloud auth list`](/sdk/gcloud/reference/auth/list).\n\n\nExecute the following command:\n\n```\n$cred = gcloud auth print-access-token\n$headers = @{ \"Authorization\" = \"Bearer $cred\"; \"x-goog-user-project\" = \"PROJECT_ID\" }\n\nInvoke-WebRequest `\n -Method GET `\n -Headers $headers `\n -Uri \"https://REGION_ID-dialogflow.googleapis.com/v3/projects/PROJECT_ID/locations/REGION_ID/operations/OPERATION_ID\" | Select-Object -Expand Content\n```\n\nYou should receive a JSON response similar to the following:\n\n```\n{\n \"name\": \"projects/PROJECT_ID/locations/REGION_ID/operations/OPERATION_ID\",\n \"metadata\": {\n \"@type\": \"type.googleapis.com/google.cloud.dialogflow.v3.SomeOperationType\",\n \"state\": \"DONE\"\n },\n \"done\": true,\n ...\n}\n```\n\n### Java\n\n\nTo authenticate to Dialogflow, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n import com.google.api.gax.longrunning.https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.longrunning.OperationFuture.html;\n import com.google.cloud.dialogflow.cx.v3.https://cloud.google.com/java/docs/reference/google-cloud-dialogflow-cx/latest/com.google.cloud.dialogflow.cx.v3.AgentName.html;\n import com.google.cloud.dialogflow.cx.v3.https://cloud.google.com/java/docs/reference/google-cloud-dialogflow-cx/latest/com.google.cloud.dialogflow.cx.v3.AgentsClient.html;\n import com.google.cloud.dialogflow.cx.v3.https://cloud.google.com/java/docs/reference/google-cloud-dialogflow-cx/latest/com.google.cloud.dialogflow.cx.v3.AgentsSettings.html;\n import com.google.cloud.dialogflow.cx.v3.https://cloud.google.com/java/docs/reference/google-cloud-dialogflow-cx/latest/com.google.cloud.dialogflow.cx.v3.ExportAgentRequest.html;\n import com.google.cloud.dialogflow.cx.v3.https://cloud.google.com/java/docs/reference/google-cloud-dialogflow-cx/latest/com.google.cloud.dialogflow.cx.v3.ExportAgentResponse.html;\n import com.google.protobuf.https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Struct.html;\n import java.io.IOException;\n import java.util.concurrent.ExecutionException;\n\n public class ExportAgent {\n\n public static void main(String[] args)\n throws IOException, InterruptedException, ExecutionException {\n // TODO(developer): Replace these variables before running the sample.\n String projectId = \"my-project-id\";\n String agentId = \"my-agent-id\";\n String location = \"my-location\";\n\n exportAgent(projectId, agentId, location);\n }\n\n public static void exportAgent(String projectId, String agentId, String location)\n throws IOException, InterruptedException, ExecutionException {\n\n // Sets the api endpoint to specified location\n String apiEndpoint = String.format(\"%s-dialogflow.googleapis.com:443\", location);\n\n https://cloud.google.com/java/docs/reference/google-cloud-dialogflow-cx/latest/com.google.cloud.dialogflow.cx.v3.AgentsSettings.html agentsSettings = https://cloud.google.com/java/docs/reference/google-cloud-dialogflow-cx/latest/com.google.cloud.dialogflow.cx.v3.AgentsSettings.html.newBuilder().setEndpoint(apiEndpoint).build();\n // Note: close() needs to be called on the AgentsClient object to clean up resources\n // such as threads. In the example below, try-with-resources is used,\n // which automatically calls close().\n try (https://cloud.google.com/java/docs/reference/google-cloud-dialogflow-cx/latest/com.google.cloud.dialogflow.cx.v3.AgentsClient.html agentsClient = https://cloud.google.com/java/docs/reference/google-cloud-dialogflow-cx/latest/com.google.cloud.dialogflow.cx.v3.AgentsClient.html.create(agentsSettings)) {\n https://cloud.google.com/java/docs/reference/google-cloud-dialogflow-cx/latest/com.google.cloud.dialogflow.cx.v3.ExportAgentRequest.html request =\n https://cloud.google.com/java/docs/reference/google-cloud-dialogflow-cx/latest/com.google.cloud.dialogflow.cx.v3.ExportAgentRequest.html.newBuilder()\n .setName(https://cloud.google.com/java/docs/reference/google-cloud-dialogflow-cx/latest/com.google.cloud.dialogflow.cx.v3.AgentName.html.of(projectId, location, agentId).toString())\n .build();\n\n // Returns a future of the operation\n OperationFuture\u003cExportAgentResponse, Struct\u003e future =\n agentsClient.https://cloud.google.com/java/docs/reference/google-cloud-dialogflow-cx/latest/com.google.cloud.dialogflow.cx.v3.AgentsClient.html#com_google_cloud_dialogflow_cx_v3_AgentsClient_exportAgentOperationCallable__().futureCall(request);\n\n // get the export agent response after the operation is completed\n https://cloud.google.com/java/docs/reference/google-cloud-dialogflow-cx/latest/com.google.cloud.dialogflow.cx.v3.ExportAgentResponse.html response = future.get();\n System.out.println(response);\n }\n }\n }\n\n### Node.js\n\n\nTo authenticate to Dialogflow, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n const {AgentsClient, protos} = require('https://cloud.google.com/nodejs/docs/reference/dialogflow-cx/latest/overview.html');\n\n const api_endpoint = `${location}-dialogflow.googleapis.com`;\n\n const client = new https://cloud.google.com/nodejs/docs/reference/dialogflow-cx/latest/overview.html({apiEndpoint: api_endpoint});\n\n const exportAgentRequest =\n new protos.google.cloud.dialogflow.cx.v3.https://cloud.google.com/nodejs/docs/reference/dialogflow-cx/latest/dialogflow-cx/protos.google.cloud.dialogflow.cx.v3.exportagentrequest-class.html();\n\n exportAgentRequest.name = `projects/${projectId}/locations/${location}/agents/${agentId}`;\n\n // exportAgent call returns a promise to a long running operation\n const [operation] = await client.exportAgent(exportAgentRequest);\n\n // Waiting for the long running opporation to finish\n const [response] = await operation.promise();\n\n // Prints the result of the operation when the operation is done\n console.log(response);\n\n### Python\n\n\nTo authenticate to Dialogflow, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n from google.cloud.dialogflowcx_v3.services.agents.client import AgentsClient\n from google.cloud.dialogflowcx_v3.types.agent import ExportAgentRequest\n\n\n def export_long_running_agent(project_id, agent_id, location):\n api_endpoint = f\"{location}-dialogflow.googleapis.com:443\"\n client_options = {\"api_endpoint\": api_endpoint}\n\n agents_client = AgentsClient(client_options=client_options)\n\n export_request = ExportAgentRequest()\n\n export_request.name = (\n f\"projects/{project_id}/locations/{location}/agents/{agent_id}\"\n )\n\n # export_agent returns a long running operation\n operation = agents_client.export_agent(request=export_request)\n\n # Returns the result of the operation when the operation is done\n return operation.result()\n\n\u003cbr /\u003e"]]