使用对话流(node.js "importAgent"接口时出错



我在Node.js服务器上使用Dialogflow客户端,使用.zip文件导入代理,该文件是我通过Dialogflow控制台导出代理时获得的。这就是实现-

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()

但是我面临这个错误

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: {}
}
}

在解压缩.zip文件时,我可以清楚地看到agent.json文件。我尝试过通过dialogflow控制台直接导入代理(使用相同的.zip文件(,它运行良好。但当我尝试使用dialogflow客户端时,它显示了上面的错误。我正在关注这一点。

我很感激任何关于如何让它再次发挥作用的想法。谢谢

我认为您所需要做的就是将agentContent设置从.AgentsClient()调用移动到.importAgent()调用-这些文档中的示例非常糟糕,因为它从未显示在importAgent调用中实际设置agentContentagentUri,尽管其中一个是必需的!

最新更新