如何在循环中将单个请求发送到不同的dialogflow代理?

时间:2019-01-01 17:10:44

标签: node.js dialogflow

我正在尝试将单个用户查询发送到不同google项目中的多个代理,以获取置信度得分,然后选择更好的代理进行下一步。当我向单个代理发送请求时,它可以正常工作,但是当我尝试循环时,控制台显示“ IAM访问被拒绝”。

我尝试更新环境变量中的GOOGLE_APPLICATION_CREDENTIALS并创建不同的SessionClient来请求循环中的其他代理。给定的代码与我要执行的操作类似。

let agents = [{projectID:"xyz", keyfile: "xyz.json"}, {projectID:"abc", keyfile: "abc.json"}]    

let sessionClient;
let sessionPath;
let dfRequest = <some queryInput object set>;

for(let agent of agents){
  process.env.GOOGLE_APPLICATION_CREDENTIALS = agent.keyfile;
  sessionClient = new dialogflow.SessionsClient();
  sessionPath = sessionClient.sessionPath(agent.projectID,'123sessionID');
  dfRequest.session = sessionPath;
  sessionClient.detectIntent(dfRequest);
}

我相信detectIntent返回promise,这些事情可以在以后处理。但是这里我的第一个请求给了我正确的响应,但是下一个请求却给了身份验证问题。请帮忙!

我得到的确切错误:

{ Error: 7 PERMISSION_DENIED: IAM permission 'dialogflow.sessions.detectIntent' on 'projects/xyz-123/agent' denied.
    at Object.exports.createStatusError (D:\myProject\node_modules\google-gax\node_modules\grpc\src\common.js:91:15)
    at Object.onReceiveStatus (D:\myProject\node_modules\google-gax\node_modules\grpc\src\client_interceptors.js:1204:28)
    at InterceptingListener._callNext (D:\myProject\node_modules\google-gax\node_modules\grpc\src\client_interceptors.js:568:42)
    at InterceptingListener.onReceiveStatus (D:\myProject\node_modules\google-gax\node_modules\grpc\src\client_interceptors.js:618:8)
    at callback (D:\myProject\node_modules\google-gax\node_modules\grpc\src\client_interceptors.js:845:24)
  code: 7,
  metadata:
   Metadata { _internal_repr: { 'grpc-server-stats-bin': [Array] } },
  details:
   'IAM permission \'dialogflow.sessions.detectIntent\' on \'projects/xyz-123/agent\' denied.' }

0 个答案:

没有答案