簡體   English   中英

節點和 DialogFlow 錯誤:UnhandledPromiseRejectionWarning:TypeError:sessionClient.projectAgentSessionPath 不是 function

[英]Node and DialogFlow Error: UnhandledPromiseRejectionWarning: TypeError: sessionClient.projectAgentSessionPath is not a function

我正在嘗試從 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);

我有同樣的錯誤。 我已經安裝

npm i dialogflow 

代替

npm install @google-cloud/dialogflow

我試圖用早期版本 4.17.0 而不是 4.17.1 更改 Express 版本。 現在它走了。

更改“sessionClient.projectAgentSessionPath”->“sessionClient.sessionPath”

在 github 上找到了這個解決方案: https://github.com/googleapis/nodejs-dialogflow/issues/127

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM