I found this example on the official site of DialogFlow using Node.js and it is working fine, but I dont know how do I integrate this into my web application.
Is it
This way it works for me.
const dialogflow = require('dialogflow');
var projectId = ""; // your dialogflow project id when you click on settings of the DF agent
var sessionId = ""; // session ID
var config = {
// use credentials or keyFilename i'm using keyFile
// credentials: {
// private_key: privateKey,
// client_email: clientEmail,
// }
keyFilename: './google.json'
};
var sessionClient = new dialogflow.SessionsClient(config);
async sendTextMessageToDialogFlow(textMessage) {
// Define session path
const sessionPath = sessionClient.sessionPath(projectId, sessionId);
// The text query request.
const request = {
session: sessionPath,
queryInput: {
text: {
text: textMessage,
languageCode: 'en'
}
}
}
try {
let [responses] = await sessionClient.detectIntent(request)
console.log(responses);
} catch (err) {
console.error('DialogFlow.sendTextMessageToDialogFlow ERROR:', err);
throw err
}
};