Commit ce52f3ff authored by Navodya Pasqual's avatar Navodya Pasqual

Dialogflow backend

parent e3fa89b0
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -20,7 +20,10 @@
"lodash": "^4.17.21",
"mongoose": "^6.0.8",
"nodeJS": "^1.0.0",
"nodemon": "^2.0.13"
"nodemon": "^2.0.13",
"actions-on-google": "^2.6.0",
"dialogflow": "^0.10.2",
"dialogflow-fulfillment": "^0.6.1"
},
"devDependencies": {
"formidable": "^1.2.2",
......
......@@ -4,6 +4,9 @@ const dotenv = require('dotenv');
const cors = require('cors');
const bodyParser = require('body-parser');
//Importing chatbot api
const chatbotAPI = require('./src/routes/chatbot/dialogFlow');
dotenv.config();
const app = express();
app.use(cors());
......@@ -45,6 +48,8 @@ app.route('/').get((req, res) => {
require('./src/routes/auth.routes')(app);
require('./src/routes/user.routes')(app);
app.use('/api/dialogflow', chatbotAPI);
app.listen(PORT, () => {
console.log('######################################################');
console.log(`Server is ON and running on PORT : ${PORT}`);
......
module.exports = {
googleProjectID: 'test-chat-bot-app-348111',
dialogFlowSessionID: 'bot-session',
dialogFlowSessionLanguageCode: 'en-US',
googleClientEmail: 'chat-bot-app-test@test-chat-bot-app-348111.iam.gserviceaccount.com',
googlePrivateKey: "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCkloXDObe/iKVG\n5VShLLT8X/qP+WUuL9pqkz+CbrbPMKpWVErRomsaUpvZzUnqRGGFizy9Q7jLdtBv\nJCBAhBq3Jdaeq+a0D2qt/gz2kTodbLKdWZ4WK4dXLRu4I+VhJWpu4W8ay5gDtHz/\nB7KI762QRSUuX58gnnPb9gg5692TtTzgKO+pRLpnTB36Jwb8uIcfE8S1VnmNPdM/\nEb1XjeAEhFXBdpULq0aXrKm6bu0Vv3ON0bUzHUR3VhQR+fDYJfK7MmfxwvymXXCM\nAHReTVxuIGBUh6DSq/CrcyAZykIEewrLK3Yyyeiy/1cku2X3t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n8uL+QINNHYT5a7ArTLLww/S7LPsWid3bRZ8dHg3JAoGBAINwfzZlODC0DaRjkN0O\n8NAIOVzdwP95/U3BEWsoZglaoA3NafWfzo6tFKXGFL35CXCDcjfI6TZWvZItqsUd\n2A/zR9ExY/fjTFCE5tnZj+qJgLDI6bCN/cyB5SFA1EwFn5IPUHVzwCWM2qhq35qQ\nRk6+eGP3mpMDg9Fp1fa6fnRi\n-----END PRIVATE KEY-----\n",
mongoURI: 'mongodb+srv://admin:admin123@db.i2rza.mongodb.net/myFirstDatabase?retryWrites=true&w=majority',
}
\ No newline at end of file
const mongoose = require('mongoose');
const opinionSchema = mongoose.Schema({
name: String,
opinion: String,
email: String,
registerDate: Date
});
const Opinion = mongoose.model('Opinion', opinionSchema);
module.exports = { Opinion }
const express = require('express');
const router = express.Router();
const dialogflow = require('dialogflow');
const config = require('../../config/chatbot/config');
const projectId = config.googleProjectID
const sessionId = config.dialogFlowSessionID
const languageCode = config.dialogFlowSessionLanguageCode
const credentials={
client_email: config.googleClientEmail,
private_key: config.googlePrivateKey
}
// Create a new session
const sessionClient = new dialogflow.SessionsClient({
projectId, credentials
});
const sessionPath = sessionClient.sessionPath(projectId, sessionId);
router.post('/textQuery', async (req, res) => {
const request = {
session: sessionPath,
queryInput: {
text: {
// The query to send to the dialogflow agent
text: req.body.text,
// The language used by the client (en-US)
languageCode: languageCode,
},
},
};
// 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}`);
res.send(result)
})
//Event Query Route
router.post('/eventQuery', async (req, res) => {
const request = {
session: sessionPath,
queryInput: {
event: {
// The query to send to the dialogflow agent
name: req.body.event,
// The language used by the client (en-US)
languageCode: languageCode,
},
},
};
// 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}`);
res.send(result)
})
module.exports = router;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment