Stay organized with collections
Save and categorize content based on your preferences.
Some methods of the Dialogflow API return a long-running operation.
These methods are asynchronous,
and the operation may not be completed when the method returns a response.
You can check on the status, wait for completion, or cancel operations.
Wait for an operation to complete
The following shows how to wait for an operation to complete.
REST
To poll an operation's status, call the get method for the
Operations
resource.
When the operation has completed,
the done field is set to true.
Before using any of the request data,
make the following replacements:
const {AgentsClient, protos} = require('@google-cloud/dialogflow-cx');
const api_endpoint = `${location}-dialogflow.googleapis.com`;
const client = new AgentsClient({apiEndpoint: api_endpoint});
const exportAgentRequest =
new protos.google.cloud.dialogflow.cx.v3.ExportAgentRequest();
exportAgentRequest.name = `projects/${projectId}/locations/${location}/agents/${agentId}`;
// exportAgent call returns a promise to a long running operation
const [operation] = await client.exportAgent(exportAgentRequest);
// Waiting for the long running opporation to finish
const [response] = await operation.promise();
// Prints the result of the operation when the operation is done
console.log(response);
from google.cloud.dialogflowcx_v3.services.agents.client import AgentsClient
from google.cloud.dialogflowcx_v3.types.agent import ExportAgentRequest
def export_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 operation
operation = agents_client.export_agent(request=export_request)
# Returns the result of the operation when the operation is done
return operation.result()