简体   繁体   中英

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

I'm trying to connect from Nodejs to 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. But I think the most relevant mistake is this. The code I used it's the same as the APi docs. 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. Now it goes.

change "sessionClient.projectAgentSessionPath" -> "sessionClient.sessionPath"

Found this solution on github: https://github.com/googleapis/nodejs-dialogflow/issues/127

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM