简体   繁体   English

节点和 DialogFlow 错误:UnhandledPromiseRejectionWarning:TypeError:sessionClient.projectAgentSessionPath 不是 function

[英]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.

相关问题 如何修复 UnhandledPromiseRejectionWarning: TypeError? - How to fix UnhandledPromiseRejectionWarning: TypeError? 上传 Intent 函数 Dialogflow V2 - Upload Intent function Dialogflow V2 Cloud Functions 部署错误对话框流 - Cloud Functions Deployment error dialogflow 无法修复“Uncaught TypeError: posts.map is not a function”错误 - Cannot fix "Uncaught TypeError: posts.map is not a function" error Dialogflow API - 类型错误:BatchUpdateIntentsRequest 的构造函数输入无效:意图 - Dialogflow API - TypeError: Invalid constructor input for BatchUpdateIntentsRequest: intents 服务器错误类型错误:firebaseApp.firestore 不是 function 错误 - Server Error TypeError: firebaseApp.firestore is not a function error 如何将dialogflow与node.js成功集成 - How to successfully integrate dialogflow with node.js 异步代码设计错误。 UnhandledPromiseRejectionWarning:错误 [ERR_HTTP_HEADERS_SENT], - Error with async code design. UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT], 尝试启用 Dialogflow Messenger 时出错 - Getting Error While Trying to Enable Dialogflow Messenger Dialogflow 代理在调用时出现忙错误 - Dialogflow Agent gives Busy Error while calling
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM