Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用“时出错”;“重要性”;dialogflow的接口(node.js)_Node.js_Google Cloud Platform_Dialogflow Es - Fatal编程技术网

使用“时出错”;“重要性”;dialogflow的接口(node.js)

使用“时出错”;“重要性”;dialogflow的接口(node.js),node.js,google-cloud-platform,dialogflow-es,Node.js,Google Cloud Platform,Dialogflow Es,我在Node.js服务器上使用Dialogflow客户端,使用通过Dialogflow控制台导出代理时得到的.zip文件导入代理。 这就是实现- const dialogflow = require("dialogflow"); const fs = require("fs"); const zipFile = "./exported_agent.zip"; const credentials = require("./cr

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

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
设置从您的
.agentclient()
调用移动到您的
.importAgent()
调用-非常糟糕,因为它从未显示
importAgent
调用中的实际设置
agentContent
agentUri
,尽管需要其中一个

我试过你的建议,效果很好。非常感谢。:)没问题!如果这对您有效,请将我的回答标记为正确,以帮助其他有类似问题的人☺