【问题标题】:Node and DialogFlow Error: UnhandledPromiseRejectionWarning: TypeError: sessionClient.projectAgentSessionPath is not a function节点和 DialogFlow 错误:UnhandledPromiseRejectionWarning:TypeError:sessionClient.projectAgentSessionPath 不是函数
【发布时间】:2020-11-20 10:48:26
【问题描述】:

我正在尝试从 Nodejs 连接到 DialogFlow。我已经完成了配置用户代理、意图等的所有步骤。如果我与 NODEMON 共进午餐,一切正常,但是当我发送 GET 或 POST 请求时,我收到此错误: “UnhandledPromiseRejectionWarning:TypeError:sessionClient.projectAgentSessionPath”等等。但我认为最相关的错误是这个。 我使用的代码与 APi 文档相同。我不知道为什么会出现这个错误。

const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const dialogflow = require('@google-cloud/dialogflow');
const uuid = require('uuid');
//const sendReq = require('./reqDialogFlow');

async function runSample(projectId = 'helpcenter-qwoj') {
// A unique identifier for the given session
const sessionId = uuid.v4();

// Create a new session
const sessionClient = new dialogflow.SessionsClient();


const sessionPath = sessionClient.projectAgentSessionPath(projectId, sessionId);
console.log(sessionPath);
// The text query request.
const request = {
    session: sessionPath,
    queryInput: {
        text: {
            // The query to send to the dialogflow agent
            text: 'hello',
            // The language used by the client (en-US)
            languageCode: 'it',
        },
    },
};

// Send request and log result
const responses = await sessionClient.detectIntent(request);
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.`);
}
};


 app.get('/', (req, res) => {
        res.send({ "hello": "Daniele Asteggiante" })
    });
    
 app.post('/api/textAPIE', (req, res) => {
        res.send({ "text": "CIAO" });
        runSample();

});

app.use(bodyParser.json());


const PORT = process.env.PORT || 5000;
app.listen(PORT);

【问题讨论】:

    标签: javascript node.js express dialogflow-es node-modules


    【解决方案1】:

    我有同样的错误。 我已经安装了

    npm i dialogflow 
    

    而不是

    npm install @google-cloud/dialogflow
    

    【讨论】:

    • 对我不起作用,因为我使用几乎完全相同的代码并使用正确的库
    【解决方案2】:

    我尝试使用早期版本 4.17.0 而不是 4.17.1 更改 Express 版本。 现在好了。

    【讨论】:

      猜你喜欢
      • 2022-01-07
      • 1970-01-01
      • 2017-03-04
      • 2016-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-24
      • 2013-08-05
      相关资源
      最近更新 更多