【发布时间】: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