Reputation: 73
I am using Dialogflow client on my Node.js server to import-agent using .zip file which I got from exporting agent through dialogflow console. This is the implementation -
const dialogflow = require("dialogflow");
const fs = require("fs");
const zipFile = "./exported_agent.zip";
const credentials = require("./credentials.json");
async function importAgent() {
try {
// converting zip file to base64 format
const base64ZipFile = await fs.readFileSync(zipFile).toString("base64");
const client = new dialogflow.v2.AgentsClient({
credentials,
agentContent: base64ZipFile,
});
const formattedParent = client.projectPath("[PROJECT-ID]");
[operation] = await client.importAgent({parent: formattedParent});
[response] = await operation.promise();
console.log(response)
} catch(err) {
console.log(err)
}
}
importAgent()
But I am facing this error
Error: 3 INVALID_ARGUMENT: com.google.apps.framework.request.BadRequestException: Invalid agent zip. Missing required json file agent.json
at Object.callErrorFromStatus (/home/ddark/Projects/IntentEntityApiTaskDialogflow/node_modules/@grpc/grpc-js/build/src/call.js:30:26)
at Object.onReceiveStatus (/home/ddark/Projects/IntentEntityApiTaskDialogflow/node_modules/@grpc/grpc-js/build/src/client.js:175:52)
at Object.onReceiveStatus (/home/ddark/Projects/IntentEntityApiTaskDialogflow/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:341:141)
at Object.onReceiveStatus (/home/ddark/Projects/IntentEntityApiTaskDialogflow/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:304:181)
at Http2CallStream.outputStatus (/home/ddark/Projects/IntentEntityApiTaskDialogflow/node_modules/@grpc/grpc-js/build/src/call-stream.js:116:74)
at Http2CallStream.maybeOutputStatus (/home/ddark/Projects/IntentEntityApiTaskDialogflow/node_modules/@grpc/grpc-js/build/src/call-stream.js:155:22)
at Http2CallStream.endCall (/home/ddark/Projects/IntentEntityApiTaskDialogflow/node_modules/@grpc/grpc-js/build/src/call-stream.js:141:18)
at Http2CallStream.handleTrailers (/home/ddark/Projects/IntentEntityApiTaskDialogflow/node_modules/@grpc/grpc-js/build/src/call-stream.js:273:14)
at ClientHttp2Stream.emit (events.js:314:20)
at emit (internal/http2/core.js:291:8) {
code: 3,
details: 'com.google.apps.framework.request.BadRequestException: Invalid agent zip. Missing required json file agent.json',
metadata: Metadata {
internalRepr: Map(1) { 'grpc-server-stats-bin' => [Array] },
options: {}
}
}
On unzipping the .zip file, I can clearly see agent.json file. I have tried directly importing-agent (using same .zip file) through dialogflow console, it is working fine. But it is showing above error when I am trying to do it with the dialogflow client. I am following this.
I appreciate any ideas on how can get this working again. Thanks!
Upvotes: 0
Views: 331
Reputation: 465
I think all you need to do is move the agentContent
setting from your .AgentsClient()
call to your .importAgent()
call - the example in those docs is incredibly bad, as it never shows actually setting agentContent
or agentUri
in the importAgent
call, despite one of them being required!
Upvotes: 1