Skip to content

Commit

Permalink
dialogflow connector embedded
Browse files Browse the repository at this point in the history
  • Loading branch information
andrealeo83 committed Oct 2, 2022
1 parent 0fcb529 commit 7c0c4ec
Show file tree
Hide file tree
Showing 7 changed files with 802 additions and 95 deletions.
711 changes: 686 additions & 25 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"tiledesk-server": "./bin/www"
},
"optionalDependencies": {
"@tiledesk-ent/tiledesk-server-dialogflow": "^1.1.6",
"@tiledesk-ent/tiledesk-server-jwthistory": "^1.1.9",
"@tiledesk-ent/tiledesk-server-payments": "^1.1.6",
"@tiledesk-ent/tiledesk-server-request-history": "^1.1.5",
Expand All @@ -42,6 +41,7 @@
"@tiledesk/tiledesk-json-rules-engine": "^4.0.3",
"@tiledesk/tiledesk-rasa-connector": "^1.0.10",
"@tiledesk/tiledesk-tybot-connector": "^0.1.14",
"@tiledesk/tiledesk-dialogflow-connector": "^1.7.3",
"app-root-path": "^3.0.0",
"bcrypt-nodejs": "0.0.3",
"body-parser": "^1.20.0",
Expand Down
2 changes: 1 addition & 1 deletion pubmodules/cache/mongoose-cachegoose-fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

var cachegoose = require('cachegoose');

var defaultTTL = process.env.CACHE_DEFAULT_TTL || 120;
var defaultTTL = process.env.CACHE_DEFAULT_TTL || 300;


function listen(client) {
Expand Down
10 changes: 10 additions & 0 deletions pubmodules/dialogflow/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const listener = require("./listener");

const dialogflow = require("@tiledesk/tiledesk-dialogflow-connector");
const dialogflowRoute = dialogflow.router;





module.exports = { listener: listener, dialogflowRoute: dialogflowRoute };
66 changes: 66 additions & 0 deletions pubmodules/dialogflow/listener.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const botEvent = require('../../event/botEvent');
var Faq_kb = require("../../models/faq_kb");
var winston = require('../../config/winston');
const df = require("@tiledesk/tiledesk-dialogflow-connector");
var configGlobal = require('../../config/global');

var port = process.env.PORT || '3000';

const BOT_DIALOGFLOW_ENDPOINT = process.env.BOT_DIALOGFLOW_ENDPOINT || "http://localhost:" + port+ "/modules/dialogflow";
winston.debug("BOT_DIALOGFLOW_ENDPOINT: " + BOT_DIALOGFLOW_ENDPOINT);

// if (BOT_DIALOGFLOW_ENDPOINT) {
winston.info("Dialogflow endpoint: " + BOT_DIALOGFLOW_ENDPOINT);
// } else {
// winston.info("Dialogflow endpoint not configured");
// }


const apiUrl = process.env.API_URL || configGlobal.apiUrl;
winston.info('Dialogflow apiUrl: '+ apiUrl);

class Listener {

listen(config) {

winston.debug('dialogflow Listener listen');

var that = this;


df.startApp(
{
MONGODB_URI: config.databaseUri,
API_ENDPOINT: apiUrl,
log: process.env.DIALOGFLOW_LOG
}, () => {
winston.info("Dialogflow route successfully started.");
}
);

botEvent.on('faqbot.create', function(bot) {
if (BOT_DIALOGFLOW_ENDPOINT) {

if (bot.type==="dialogflow") {
// bot.url = BOT_DIALOGFLOW_ENDPOINT;

Faq_kb.findByIdAndUpdate(bot.id, {"url":BOT_DIALOGFLOW_ENDPOINT}, { new: true, upsert: true }, function (err, savedFaq_kb) {

// bot.save(function (err, savedFaq_kb) {
if (err) {
return winston.error('error saving faqkb dialogflow ', err)
}
winston.verbose('Saved faqkb dialogflow', savedFaq_kb.toObject())
});
}
}
});

}

}

var listener = new Listener();


module.exports = listener;
26 changes: 25 additions & 1 deletion pubmodules/pubModulesManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class PubModulesManager {
this.routingQueue = undefined;

this.cache = undefined;

this.dialogFlow = undefined;
}


Expand Down Expand Up @@ -335,7 +337,20 @@ class PubModulesManager {
}
}



try {
this.dialogFlow = require('./dialogflow').listener;
winston.debug("this.dialogFlow:"+ this.dialogFlow);
this.dialogFlow.listen(config);
winston.info("PubModulesManager dialogFlow initialized");
} catch(err) {
// if (err.code == 'MODULE_NOT_FOUND') {
// winston.info("PubModulesManager init dialogFlow module not found");
// }else {
winston.error("PubModulesManager error initializing init dialogFlow module", err);
// }
}
}

start() {
Expand Down Expand Up @@ -411,11 +426,20 @@ class PubModulesManager {
}
}

// if (this.dialogFlow) {
// try {
// this.dialogFlow.listen();
// winston.info("PubModulesManager dialogFlow started");
// } catch(err) {
// winston.info("PubModulesManager error starting dialogFlow module", err);
// }
// }


}



}

var pubModulesManager = new PubModulesManager();
Expand Down
80 changes: 13 additions & 67 deletions services/modulesManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,8 @@ class ModulesManager {
this.facebookRoute = undefined;
this.jwthistoryArchiver = undefined;
this.jwthistoryRoute = undefined;
this.dialogflowListener = undefined;
this.requestHistoryArchiver = undefined;
this.requestHistoryRoute = undefined;
// this.routingQueue = undefined;
// this.queue = undefined;
// this.cache = undefined;
this.requestHistoryRoute = undefined;
this.visitorCounterRoute = undefined;
this.visitorCounterMiddleware = undefined;
this.widgetsRoute = undefined;
Expand Down Expand Up @@ -202,62 +198,19 @@ class ModulesManager {



try {
this.dialogflowListener = require('@tiledesk-ent/tiledesk-server-dialogflow').listener;
// this.dialogflowListener.listen();
winston.debug("this.dialogflowListener:"+ this.dialogflowListener);

winston.info("ModulesManager dialogflow initialized");
} catch(err) {
if (err.code == 'MODULE_NOT_FOUND') {
winston.info("ModulesManager init dialogflow module not found");
}else {
winston.error("ModulesManager error initializing init dialogflow module", err);
}
}


// try {
// this.routingQueue = require('@tiledesk-ent/tiledesk-server-routing-queue').listener;
// // this.routingQueue.listen();
// winston.debug("this.routingQueue:"+ this.routingQueue);
// this.dialogflowListener = require('@tiledesk-ent/tiledesk-server-dialogflow').listener;
// // this.dialogflowListener.listen();
// winston.debug("this.dialogflowListener:"+ this.dialogflowListener);

// winston.info("ModulesManager routing queue initialized");
// winston.info("ModulesManager dialogflow initialized");
// } catch(err) {
// if (err.code == 'MODULE_NOT_FOUND') {
// winston.info("ModulesManager init routing queue module not found");
// winston.info("ModulesManager init dialogflow module not found");
// }else {
// winston.error("ModulesManager error initializing init routing queue module", err);
// winston.error("ModulesManager error initializing init dialogflow module", err);
// }
// }



// try {
// this.queue = require('@tiledesk-ent/tiledesk-server-queue');
// winston.debug("this.queue:"+ this.queue);

// winston.info("ModulesManager queue initialized");
// } catch(err) {
// if (err.code == 'MODULE_NOT_FOUND') {
// winston.info("ModulesManager init queue module not found");
// }else {
// winston.error("ModulesManager error initializing init queue module", err);
// }
// }


// try {
// this.cache = require('@tiledesk-ent/tiledesk-server-cache').cachegoose(config.mongoose);
// winston.debug("this.cache:"+ this.cache);
// winston.info("ModulesManager cache initialized");
// } catch(err) {
// if (err.code == 'MODULE_NOT_FOUND') {
// winston.info("ModulesManager init cache module not found");
// }else {
// winston.error("ModulesManager error initializing init cache module", err);
// }
// }
// }



Expand Down Expand Up @@ -330,22 +283,15 @@ class ModulesManager {
winston.info("ModulesManager error starting requestHistoryArchiver module", err);
}
}
// if (this.routingQueue) {

// if (this.dialogflowListener) {
// try {
// this.routingQueue.listen();
// winston.info("ModulesManager routingQueue started");
// this.dialogflowListener.listen();
// winston.info("ModulesManager dialogflowListener started");
// } catch(err) {
// winston.info("ModulesManager error starting routingQueue module", err);
// winston.info("ModulesManager error starting dialogflowListener module", err);
// }
// }
if (this.dialogflowListener) {
try {
this.dialogflowListener.listen();
winston.info("ModulesManager dialogflowListener started");
} catch(err) {
winston.info("ModulesManager error starting dialogflowListener module", err);
}
}



Expand Down

0 comments on commit 7c0c4ec

Please sign in to comment.