I'm trying to restore a Dialogflow agent using the Python SDK (google-cloud-dialogflow=2.7.1, google-api-core=2.0, Python 3.7):
import os
import base64
import google.cloud.dialogflow as dialogflow
# Authenticate and open session
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = 'test-a.json'
DIALOGFLOW_PROJECT_ID = 'xxxxxxxx'
SESSION_ID = '#'
session_client = dialogflow.SessionsClient()
session = session_client.session_path(DIALOGFLOW_PROJECT_ID, SESSION_ID)
# Get the agent
agent = dialogflow.AgentsClient()
# Read and encode zip file
encoded_file = base64.b64encode(open("test_A.zip", "rb").read())
# Restore agent
request = {
"parent": f'projects/{DIALOGFLOW_PROJECT_ID}',
"agent_content": encoded_file
}
agent.restore_agent(request=request)
Here's what I get:
google.api_core.exceptions.InvalidArgument: 400 com.google.apps.framework.request.BadRequestException: Invalid agent zip. Missing required json file agent.json
But the file agent.json is in the zip file. In fact, the zip file is the exact file I downloaded from the Dialogflow's console export option:
