[英]Node and DialogFlow Error: UnhandledPromiseRejectionWarning: TypeError: sessionClient.projectAgentSessionPath is not a function
I'm trying to connect from Nodejs to DialogFlow.我正在尝试从 Nodejs 连接到 DialogFlow。 I have completed all the steps to configure the user agent, the intent, etc. If I lunch with NODEMON the app, all its ok, but when I send a GET or POST request I get this error: "UnhandledPromiseRejectionWarning: TypeError: sessionClient.projectAgentSessionPath" and more.
我已经完成了配置用户代理、意图等的所有步骤。如果我与 NODEMON 应用程序共进午餐,一切正常,但是当我发送 GET 或 POST 请求时,我收到此错误:“UnhandledPromiseRejectionWarning: TypeError: sessionClient. projectAgentSessionPath”等等。 But I think the most relevant mistake is this.
但我认为最相关的错误是这个。 The code I used it's the same as the APi docs.
我使用的代码与 APi 文档相同。 I don't know why I get this error.
我不知道为什么会出现此错误。
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);
i had the same error.我有同样的错误。 i had installed
我已经安装
npm i dialogflow
instead of代替
npm install @google-cloud/dialogflow
I tried to change the Express Version version with an earlier version 4.17.0 instead 4.17.1.我试图用早期版本 4.17.0 而不是 4.17.1 更改 Express 版本。 Now it goes.
现在它走了。
change "sessionClient.projectAgentSessionPath" -> "sessionClient.sessionPath"更改“sessionClient.projectAgentSessionPath”->“sessionClient.sessionPath”
Found this solution on github: https://github.com/googleapis/nodejs-dialogflow/issues/127在 github 上找到了这个解决方案: https://github.com/googleapis/nodejs-dialogflow/issues/127
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.