本文介绍了Google CloudDialogflow意图检测Node.js示例不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试与nodejs实现一个非常简单的dialogflow代理集成.

I am trying to implement a very simple dialogflow agent integration with nodejs.

这是我到目前为止所做的

Here is what I did so far

  • 我遵循的代码来自意图检测
  • 我将服务帐户私钥文件.json添加到了我的服务器.
  • 我添加了环境变量GOOGLE_APPLICATION_CREDENTIALS以及我的.json私钥文件的路径.
  • I followed the code from Intent detection
  • I added the service account private key file .json to my server.
  • I added the environment variable GOOGLE_APPLICATION_CREDENTIALS with the path to my .json private key file.

这是我现在要运行的代码:

Here is the code I am trying to run right now:

require('dotenv').config()
const projectId = 'gg-chatbot-216808';
const sessionId = 'quickstart-session-id';
const query = 'hello';
const languageCode = 'en-US';

// Instantiate a DialogFlow client.
const dialogflow = require('dialogflow');
const sessionClient = new dialogflow.SessionsClient();

// Define session path
const sessionPath = sessionClient.sessionPath(projectId, sessionId);

// The text query request.
const request = {
    session: sessionPath,
    queryInput: {
        text: {
            text: query,
            languageCode: languageCode,
        },
    },
};

// This prints the private key path correctly.
console.log(process.env.GOOGLE_APPLICATION_CREDENTIALS);

// Send request and log result
sessionClient
    .detectIntent(request)
    .then(responses => {
        console.log('Detected intent');
        const result = responses[0].queryResult;
        console.log(`  Query: ${result.queryText}`);
        console.log(`  Response: ${result.fulfillmentText}`);
        if (result.intent) {
            console.log(`  Intent: ${result.intent.displayName}`);
        } else {
            console.log(`  No intent matched.`);
        }
    })
    .catch(err => {
        console.error('ERROR:', err);
    });

然后我在运行此文件时在控制台中收到此错误

Then I get this error in the console when I run this file

Auth error:Error: invalid_user: Robot is disabled.
ERROR: { Error: 14 UNAVAILABLE: Getting metadata from plugin failed with error: invalid_user: Robot is disabled.
    at Object.exports.createStatusError (/var/www/html/google_auth/node_modules/grpc/src/common.js:87:15)
    at Object.onReceiveStatus (/var/www/html/google_auth/node_modules/grpc/src/client_interceptors.js:1188:28)
    at InterceptingListener._callNext (/var/www/html/google_auth/node_modules/grpc/src/client_interceptors.js:564:42)
    at InterceptingListener.onReceiveStatus (/var/www/html/google_auth/node_modules/grpc/src/client_interceptors.js:614:8)
    at callback (/var/www/html/google_auth/node_modules/grpc/src/client_interceptors.js:841:24)
  code: 14,
  metadata: Metadata { _internal_repr: {} },
  details: 'Getting metadata from plugin failed with error: invalid_user: Robot is disabled.' }

推荐答案

如果尚未解决,则解决方案是在sessionClient内部提供"fileKey".

If this has not been resolved yet , the solution is to provide "fileKey" inside sessionClient.

const sessionClient = new dialogflow.SessionsClient({
fileKey:" path of your credentials.json file"
});

let filePath = process.env.GOOGLE_APPLICATION_CREDENTIALS ="Location of credentials file".

const sessionClient = new dialogflow.SessionsClient({
fileKey:filePath
});

如果没有将系统环境变量设置为GOOGLE_APPLICATION_CREDENTIALS,这甚至将起作用.

this will even work if there is no system env variable is set as GOOGLE_APPLICATION_CREDENTIALS.

希望这会有所帮助.

这篇关于Google CloudDialogflow意图检测Node.js示例不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-24 19:04