gpt4 book ai didi

javascript - Node 和 DialogFlow 错误 : UnhandledPromiseRejectionWarning: TypeError: sessionClient. projectAgentSessionPath 不是函数

转载 作者:行者123 更新时间:2023-12-03 07:10:38 27 4
gpt4 key购买 nike

我正在尝试从 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

关于javascript - Node 和 DialogFlow 错误 : UnhandledPromiseRejectionWarning: TypeError: sessionClient. projectAgentSessionPath 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63177431/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com