@tiledesk/tiledesk-server 2.2.39 → 2.3.1-8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +121 -0
- package/LICENSE +14 -657
- package/README.md +17 -3
- package/app.js +21 -60
- package/channels/chat21/chat21Handler.js +18 -3
- package/channels/chat21/chat21WebHook.js +31 -15
- package/channels/chat21/package-lock.json +663 -706
- package/channels/chat21/package.json +2 -2
- package/deploy.sh +2 -0
- package/event/botEvent.js +1 -1
- package/event/subscriptionEvent.js +11 -0
- package/fonts/Roboto-Italic.ttf +0 -0
- package/fonts/Roboto-Medium.ttf +0 -0
- package/fonts/Roboto-MediumItalic.ttf +0 -0
- package/fonts/Roboto-Regular.ttf +0 -0
- package/middleware/ipFilter.js +220 -0
- package/middleware/passport.js +11 -2
- package/models/lead.js +2 -0
- package/models/project.js +10 -0
- package/models/project_user.js +4 -0
- package/models/request.js +50 -12
- package/models/subscriptionLog.js +34 -0
- package/models/tagLibrary.js +42 -0
- package/package.json +6 -12
- package/pubmodules/activities/activityArchiver.js +314 -0
- package/pubmodules/activities/index.js +3 -0
- package/pubmodules/activities/models/activity.js +88 -0
- package/pubmodules/activities/routes/activity.js +710 -0
- package/pubmodules/activities/test/activityRoute.js +85 -0
- package/pubmodules/analytics/analytics.js +1719 -0
- package/pubmodules/analytics/index.js +3 -0
- package/pubmodules/canned/cannedResponse.js +55 -0
- package/pubmodules/canned/cannedResponseRoute.js +163 -0
- package/pubmodules/canned/index.js +3 -0
- package/pubmodules/emailNotification/requestNotification.js +215 -28
- package/pubmodules/events/eventRoute.js +37 -7
- package/pubmodules/messageActions/messageActionsInterceptor.js +4 -2
- package/pubmodules/pubModulesManager.js +129 -5
- package/pubmodules/rasa/listener.js +5 -5
- package/pubmodules/rules/conciergeBot.js +4 -4
- package/pubmodules/scheduler/tasks/closeAgentUnresponsiveRequestTask.js +3 -1
- package/pubmodules/scheduler/tasks/closeBotUnresponsiveRequestTask.js +3 -1
- package/pubmodules/tilebot/index.js +11 -0
- package/pubmodules/tilebot/listener.js +69 -0
- package/pubmodules/trigger/default.js +271 -0
- package/pubmodules/trigger/event/actionEventEmitter.js +10 -0
- package/pubmodules/trigger/event/flowEventEmitter.js +10 -0
- package/pubmodules/trigger/event/triggerEventEmitter.js +10 -0
- package/pubmodules/trigger/index.js +3 -0
- package/pubmodules/trigger/models/trigger.js +149 -0
- package/pubmodules/trigger/rulesTrigger.js +1181 -0
- package/pubmodules/trigger/start.js +118 -0
- package/pubmodules/trigger/triggerRoute.js +150 -0
- package/routes/auth.js +7 -2
- package/routes/department.js +51 -0
- package/routes/faq.js +7 -0
- package/routes/faq_kb.js +1 -1
- package/routes/group.js +140 -0
- package/routes/lead.js +24 -1
- package/routes/message.js +6 -3
- package/routes/project.js +118 -0
- package/routes/project_user.js +9 -0
- package/routes/public-request.js +280 -2
- package/routes/request.js +122 -16
- package/routes/subscription.js +140 -0
- package/routes/tag.js +138 -0
- package/routes/user-request.js +3 -2
- package/routes/users.js +1 -1
- package/routes/widget.js +80 -3
- package/routes/widgetLoader.js +31 -0
- package/services/banUserNotifier.js +86 -0
- package/services/emailService.js +189 -11
- package/services/faqService.js +2 -2
- package/services/geoService.js +30 -4
- package/services/leadService.js +2 -0
- package/services/modulesManager.js +7 -188
- package/services/requestService.js +364 -6
- package/services/subscriptionNotifier.js +485 -0
- package/template/email/assignedEmailMessage.html +1 -1
- package/template/email/assignedRequest.html +1 -1
- package/template/email/newMessage.html +1 -1
- package/template/email/newMessageFollower.html +236 -0
- package/template/email/passwordChanged.html +1 -1
- package/template/email/pooledEmailMessage.html +1 -1
- package/template/email/pooledRequest.html +1 -1
- package/template/email/resetPassword.html +2 -2
- package/template/email/ticket.html +1 -1
- package/test/cannedRoute.js +166 -0
- package/test/messageRoute.js +69 -0
- package/test/requestService.js +3 -1
- package/utils/orgUtil.js +3 -3
- package/views/messages.jade +2 -2
- package/websocket/webSocketServer.js +23 -5
|
@@ -2,7 +2,6 @@ var express = require('express');
|
|
|
2
2
|
var router = express.Router({mergeParams: true});
|
|
3
3
|
var Event = require("./event");
|
|
4
4
|
var winston = require('../../config/winston');
|
|
5
|
-
const eventEvent = require('./eventEvent');
|
|
6
5
|
var validtoken = require('../../middleware/valid-token');
|
|
7
6
|
const eventService = require('./eventService');
|
|
8
7
|
const { check, validationResult } = require('express-validator');
|
|
@@ -10,6 +9,9 @@ var passport = require('passport');
|
|
|
10
9
|
require('../../middleware/passport')(passport);
|
|
11
10
|
var roleChecker = require('../../middleware/has-role');
|
|
12
11
|
|
|
12
|
+
const messageEvent = require('../../event/messageEvent');
|
|
13
|
+
|
|
14
|
+
|
|
13
15
|
router.post('/', [
|
|
14
16
|
passport.authenticate(['basic', 'jwt'],
|
|
15
17
|
{ session: false }),
|
|
@@ -37,13 +39,41 @@ router.post('/', [
|
|
|
37
39
|
pu = req.projectuser.id
|
|
38
40
|
}
|
|
39
41
|
|
|
42
|
+
// console.log("************* emit event"+new Date().toISOString());
|
|
43
|
+
|
|
44
|
+
// // message.senderFullname, message.recipient,
|
|
45
|
+
// // message.recipient_fullname, message.text, message.sender, attributes, message.type, message.metadata, timestamp, message.group
|
|
46
|
+
// var recipient = req.body.attributes.request_id;
|
|
47
|
+
// console.log("recipient",recipient);
|
|
48
|
+
// var sender = req.user.id;
|
|
49
|
+
// console.log("sender",sender);
|
|
50
|
+
|
|
51
|
+
// messageEvent.emit("message.test",
|
|
52
|
+
// {
|
|
53
|
+
// recipient: recipient,
|
|
54
|
+
// recipient_fullname: "pluto",
|
|
55
|
+
// // sender:"bb0d809b-b093-419b-8b48-11a192cc3619",
|
|
56
|
+
// sender: sender,
|
|
57
|
+
// senderFullname: "Tiledesk",
|
|
58
|
+
// text:"welcome",
|
|
59
|
+
// group: {
|
|
60
|
+
// members: {
|
|
61
|
+
// // "bb0d809b-b093-419b-8b48-11a192cc3619": 1,
|
|
62
|
+
// sender: 1
|
|
63
|
+
|
|
64
|
+
// }
|
|
65
|
+
// }
|
|
66
|
+
// }
|
|
67
|
+
// );
|
|
68
|
+
|
|
40
69
|
// emit(name, attributes, id_project, project_user, createdBy, status, user) {
|
|
41
70
|
eventService.emit(req.body.name, req.body.attributes, req.projectid, pu, req.user.id, undefined, req.user).then(function(event) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
71
|
+
|
|
72
|
+
res.json(event);
|
|
73
|
+
}).catch(function(err) {
|
|
74
|
+
winston.error('Error saving the event '+ JSON.stringify(event), err)
|
|
75
|
+
return res.status(500).send({success: false, msg: 'Error saving the event '+ JSON.stringify(event)});
|
|
76
|
+
});
|
|
47
77
|
|
|
48
78
|
// var newEvent = new Event({
|
|
49
79
|
// name: req.body.name,
|
|
@@ -137,7 +167,7 @@ router.get('/', [passport.authenticate(['basic', 'jwt'],
|
|
|
137
167
|
}
|
|
138
168
|
|
|
139
169
|
// collection.count is deprecated, and will be removed in a future version. Use Collection.countDocuments or Collection.estimatedDocumentCount instead
|
|
140
|
-
return Event.
|
|
170
|
+
return Event.countDocuments(query, function (err, totalRowCount) {
|
|
141
171
|
|
|
142
172
|
var objectToReturn = {
|
|
143
173
|
perPage: limit,
|
|
@@ -149,8 +149,10 @@ class MessageActionsInterceptor {
|
|
|
149
149
|
if (request) {
|
|
150
150
|
// setTimeout(function() {
|
|
151
151
|
// winston.info("delayed")
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
|
|
153
|
+
// closeRequestByRequestId(request_id, id_project, skipStatsUpdate, notify, closed_by)
|
|
154
|
+
const closed_by = message.sender;
|
|
155
|
+
requestService.closeRequestByRequestId(request.request_id, request.id_project, false, true, closed_by );
|
|
154
156
|
// }, 1500);
|
|
155
157
|
|
|
156
158
|
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
|
|
2
2
|
var winston = require('../config/winston');
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
var validtoken = require('../middleware/valid-token');
|
|
4
|
+
var roleChecker = require('../middleware/has-role');
|
|
5
|
+
var passport = require('passport');
|
|
6
|
+
require('../middleware/passport')(passport);
|
|
8
7
|
|
|
9
8
|
class PubModulesManager {
|
|
10
9
|
|
|
@@ -21,6 +20,19 @@ class PubModulesManager {
|
|
|
21
20
|
|
|
22
21
|
this.rasa = undefined;
|
|
23
22
|
this.rasaRoute = undefined;
|
|
23
|
+
|
|
24
|
+
this.activityArchiver = undefined;
|
|
25
|
+
this.activityRoute = undefined;
|
|
26
|
+
|
|
27
|
+
this.analyticsRoute = undefined;
|
|
28
|
+
|
|
29
|
+
this.cannedResponseRoute = undefined;
|
|
30
|
+
|
|
31
|
+
this.trigger = undefined;
|
|
32
|
+
this.triggerRoute = undefined;
|
|
33
|
+
|
|
34
|
+
this.tilebot = undefined;
|
|
35
|
+
this.tilebotRoute = undefined;
|
|
24
36
|
}
|
|
25
37
|
|
|
26
38
|
|
|
@@ -31,6 +43,10 @@ class PubModulesManager {
|
|
|
31
43
|
app.use('/modules/rasa', this.rasaRoute);
|
|
32
44
|
winston.info("ModulesManager rasaRoute controller loaded");
|
|
33
45
|
}
|
|
46
|
+
if (this.tilebotRoute) {
|
|
47
|
+
app.use('/modules/tilebot', this.tilebotRoute);
|
|
48
|
+
winston.info("ModulesManager tilebot controller loaded");
|
|
49
|
+
}
|
|
34
50
|
|
|
35
51
|
}
|
|
36
52
|
useUnderProjects(app) {
|
|
@@ -45,6 +61,27 @@ class PubModulesManager {
|
|
|
45
61
|
winston.info("ModulesManager eventsRoute controller loaded");
|
|
46
62
|
}
|
|
47
63
|
|
|
64
|
+
|
|
65
|
+
if (this.activityRoute) {
|
|
66
|
+
app.use('/:projectid/activities', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRole('admin')], this.activityRoute);
|
|
67
|
+
winston.info("ModulesManager activities controller loaded");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (this.analyticsRoute) {
|
|
71
|
+
app.use('/:projectid/analytics', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRole('agent')], this.analyticsRoute);
|
|
72
|
+
winston.info("ModulesManager analytics controller loaded");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (this.cannedResponseRoute) {
|
|
76
|
+
app.use('/:projectid/canned', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRole('agent')], this.cannedResponseRoute);
|
|
77
|
+
winston.info("ModulesManager canned controller loaded");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (this.triggerRoute) {
|
|
81
|
+
app.use('/:projectid/modules/triggers', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRole('admin')], this.triggerRoute);
|
|
82
|
+
winston.info("ModulesManager trigger controller loaded");
|
|
83
|
+
}
|
|
84
|
+
|
|
48
85
|
}
|
|
49
86
|
|
|
50
87
|
|
|
@@ -166,8 +203,85 @@ class PubModulesManager {
|
|
|
166
203
|
|
|
167
204
|
|
|
168
205
|
|
|
206
|
+
|
|
207
|
+
try {
|
|
208
|
+
this.activityArchiver = require('./activities').activityArchiver;
|
|
209
|
+
// this.activityArchiver.listen();
|
|
210
|
+
winston.debug("this.activityArchiver:"+ this.activityArchiver);
|
|
211
|
+
|
|
212
|
+
this.activityRoute = require('./activities').activityRoute;
|
|
213
|
+
winston.debug("this.activityRoute:"+ this.activityRoute);
|
|
214
|
+
|
|
215
|
+
winston.info("ModulesManager activities initialized");
|
|
216
|
+
} catch(err) {
|
|
217
|
+
if (err.code == 'MODULE_NOT_FOUND') {
|
|
218
|
+
winston.info("ModulesManager init activities module not found");
|
|
219
|
+
}else {
|
|
220
|
+
winston.error("ModulesManager error initializing init activities module", err);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
try {
|
|
226
|
+
this.analyticsRoute = require('./analytics').analyticsRoute;
|
|
227
|
+
winston.debug("this.analyticsRoute:"+ this.analyticsRoute);
|
|
228
|
+
winston.info("ModulesManager analyticsRoute initialized");
|
|
229
|
+
} catch(err) {
|
|
230
|
+
if (err.code == 'MODULE_NOT_FOUND') {
|
|
231
|
+
winston.info("ModulesManager init analytics module not found");
|
|
232
|
+
}else {
|
|
233
|
+
winston.error("ModulesManager error initializing init analytics module", err);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
try {
|
|
240
|
+
this.cannedResponseRoute = require('./canned').cannedResponseRoute;
|
|
241
|
+
winston.debug("this.cannedResponseRoute:"+ this.cannedResponseRoute);
|
|
242
|
+
winston.info("ModulesManager cannedResponseRoute initialized");
|
|
243
|
+
} catch(err) {
|
|
244
|
+
if (err.code == 'MODULE_NOT_FOUND') {
|
|
245
|
+
winston.info("ModulesManager init canned module not found");
|
|
246
|
+
}else {
|
|
247
|
+
winston.error("ModulesManager error initializing init canned module", err);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
169
251
|
|
|
252
|
+
try {
|
|
253
|
+
this.trigger = require('./trigger').start;
|
|
254
|
+
winston.debug("this.trigger:"+ this.trigger);
|
|
255
|
+
this.triggerRoute = require('./trigger').triggerRoute;
|
|
256
|
+
winston.debug("this.triggerRoute:"+ this.triggerRoute);
|
|
257
|
+
winston.info("ModulesManager trigger initialized");
|
|
258
|
+
} catch(err) {
|
|
259
|
+
if (err.code == 'MODULE_NOT_FOUND') {
|
|
260
|
+
winston.info("ModulesManager init trigger module not found");
|
|
261
|
+
}else {
|
|
262
|
+
winston.error("ModulesManager error initializing init trigger module", err);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
170
265
|
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
try {
|
|
270
|
+
this.tilebot = require('./tilebot');
|
|
271
|
+
winston.debug("this.tilebot:"+ this.tilebot);
|
|
272
|
+
this.tilebot.listener.listen(config);
|
|
273
|
+
this.tilebotRoute = this.tilebot.tilebotRoute;
|
|
274
|
+
|
|
275
|
+
winston.info("PubModulesManager initialized tilebot.");
|
|
276
|
+
} catch(err) {
|
|
277
|
+
if (err.code == 'MODULE_NOT_FOUND') {
|
|
278
|
+
winston.info("PubModulesManager init tilebot module not found");
|
|
279
|
+
}else {
|
|
280
|
+
winston.info("PubModulesManager error initializing init tilebot module", err);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
|
|
171
285
|
}
|
|
172
286
|
|
|
173
287
|
start() {
|
|
@@ -221,6 +335,16 @@ class PubModulesManager {
|
|
|
221
335
|
}
|
|
222
336
|
|
|
223
337
|
|
|
338
|
+
if (this.activityArchiver) {
|
|
339
|
+
try {
|
|
340
|
+
this.activityArchiver.listen();
|
|
341
|
+
winston.info("ModulesManager activityArchiver started");
|
|
342
|
+
} catch(err) {
|
|
343
|
+
winston.info("ModulesManager error starting activityArchiver module", err);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
|
|
224
348
|
}
|
|
225
349
|
|
|
226
350
|
|
|
@@ -6,7 +6,7 @@ var configGlobal = require('../../config/global');
|
|
|
6
6
|
|
|
7
7
|
var port = process.env.PORT || '3000';
|
|
8
8
|
|
|
9
|
-
const BOT_RASA_ENDPOINT = "http://localhost:" + port+ "/modules/rasa/rasabot"
|
|
9
|
+
const BOT_RASA_ENDPOINT = process.env.BOT_RASA_ENDPOINT || "http://localhost:" + port+ "/modules/rasa/rasabot";
|
|
10
10
|
winston.debug("BOT_RASA_ENDPOINT: " + BOT_RASA_ENDPOINT);
|
|
11
11
|
|
|
12
12
|
// if (BOT_RASA_ENDPOINT) {
|
|
@@ -23,7 +23,7 @@ class Listener {
|
|
|
23
23
|
listen(config) {
|
|
24
24
|
|
|
25
25
|
winston.info('Rasa Listener listen');
|
|
26
|
-
winston.debug("config databaseUri: " + config.databaseUri);
|
|
26
|
+
winston.debug("rasa config databaseUri: " + config.databaseUri);
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
var that = this;
|
|
@@ -34,7 +34,7 @@ class Listener {
|
|
|
34
34
|
KVBASE_COLLECTION : process.env.KVBASE_COLLECTION,
|
|
35
35
|
MONGODB_URI: config.databaseUri,
|
|
36
36
|
API_ENDPOINT: apiUrl,
|
|
37
|
-
log:
|
|
37
|
+
log: process.env.RASABOT_LOG
|
|
38
38
|
}, () => {
|
|
39
39
|
winston.info("RASA proxy server successfully started.");
|
|
40
40
|
});
|
|
@@ -44,10 +44,10 @@ class Listener {
|
|
|
44
44
|
botEvent.on('faqbot.create', function(bot) {
|
|
45
45
|
if (BOT_RASA_ENDPOINT) {
|
|
46
46
|
|
|
47
|
-
winston.
|
|
47
|
+
winston.debug('bot.type:'+bot.type);
|
|
48
48
|
if (bot.type==="rasa") {
|
|
49
49
|
|
|
50
|
-
winston.
|
|
50
|
+
winston.debug('qui.type:'+bot.type);
|
|
51
51
|
|
|
52
52
|
|
|
53
53
|
Faq_kb.findByIdAndUpdate(bot.id, {"url":BOT_RASA_ENDPOINT}, { new: true, upsert: true }, function (err, savedFaq_kb) {
|
|
@@ -188,7 +188,7 @@ devi mandare un messaggio welcome tu altrimenti il bot inserito successivamente
|
|
|
188
188
|
|
|
189
189
|
setImmediate(() => {
|
|
190
190
|
|
|
191
|
-
winston.debug("ConciergeBot send close bot message");
|
|
191
|
+
winston.debug("ConciergeBot send close bot message",request);
|
|
192
192
|
|
|
193
193
|
// send(sender, senderFullname, recipient, text, id_project, createdBy, attributes, type, metadata, language)
|
|
194
194
|
messageService.send(
|
|
@@ -198,7 +198,7 @@ devi mandare un messaggio welcome tu altrimenti il bot inserito successivamente
|
|
|
198
198
|
"Chat closed",
|
|
199
199
|
request.id_project,
|
|
200
200
|
'system',
|
|
201
|
-
{subtype:"info/support", "updateconversation" : false, messagelabel: {key: "CHAT_CLOSED"}},
|
|
201
|
+
{subtype:"info/support", "updateconversation" : false, messagelabel: {key: "CHAT_CLOSED"}},
|
|
202
202
|
undefined,
|
|
203
203
|
request.language
|
|
204
204
|
);
|
|
@@ -228,8 +228,8 @@ devi mandare un messaggio welcome tu altrimenti il bot inserito successivamente
|
|
|
228
228
|
request.request_id,
|
|
229
229
|
"Chat reopened",
|
|
230
230
|
request.id_project,
|
|
231
|
-
'system',
|
|
232
|
-
{subtype:"info/support", "updateconversation" :
|
|
231
|
+
'system',
|
|
232
|
+
{subtype:"info/support", "updateconversation" : true, messagelabel: {key: "CHAT_REOPENED"}},
|
|
233
233
|
undefined,
|
|
234
234
|
request.language
|
|
235
235
|
|
|
@@ -84,7 +84,9 @@ findUnresponsiveRequests() {
|
|
|
84
84
|
requests.forEach(request => {
|
|
85
85
|
winston.debug("********unresponsive request ", request);
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
// closeRequestByRequestId(request_id, id_project, skipStatsUpdate, notify, closed_by)
|
|
88
|
+
const closed_by = "_bot_unresponsive";
|
|
89
|
+
return requestService.closeRequestByRequestId(request.request_id, request.id_project, false, false, closed_by).then(function(updatedStatusRequest) {
|
|
88
90
|
winston.verbose("CloseAgentUnresponsiveRequestTask: Request closed with request_id: " + request.request_id);
|
|
89
91
|
// winston.info("Request closed",updatedStatusRequest);
|
|
90
92
|
}).catch(function(err) {
|
|
@@ -95,7 +95,9 @@ findUnresponsiveRequests() {
|
|
|
95
95
|
|
|
96
96
|
winston.debug("********unresponsive request ", request);
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
// closeRequestByRequestId(request_id, id_project, skipStatsUpdate, notify, closed_by)
|
|
99
|
+
const closed_by = "_bot_unresponsive";
|
|
100
|
+
return requestService.closeRequestByRequestId(request.request_id, request.id_project, false, false, closed_by).then(function(updatedStatusRequest) {
|
|
99
101
|
winston.info("CloseBotUnresponsiveRequestTask: Request closed with request_id: " + request.request_id);
|
|
100
102
|
// winston.info("Request closed",updatedStatusRequest);
|
|
101
103
|
}).catch(function(err) {
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const botEvent = require('../../event/botEvent');
|
|
2
|
+
var Faq_kb = require("../../models/faq_kb");
|
|
3
|
+
var winston = require('../../config/winston');
|
|
4
|
+
var configGlobal = require('../../config/global');
|
|
5
|
+
|
|
6
|
+
var port = process.env.PORT || '3000';
|
|
7
|
+
|
|
8
|
+
const TILEBOT_ENDPOINT = process.env.TILEBOT_ENDPOINT || "http://localhost:" + port+ "/modules/tilebot/ext/";
|
|
9
|
+
winston.debug("TILEBOT_ENDPOINT: " + TILEBOT_ENDPOINT);
|
|
10
|
+
|
|
11
|
+
winston.info("Tilebot endpoint: " + TILEBOT_ENDPOINT);
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const apiUrl = process.env.API_URL || configGlobal.apiUrl;
|
|
15
|
+
winston.info('Rasa apiUrl: '+ apiUrl);
|
|
16
|
+
|
|
17
|
+
const tybot = require("@tiledesk/tiledesk-tybot-connector");
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class Listener {
|
|
21
|
+
|
|
22
|
+
listen(config) {
|
|
23
|
+
|
|
24
|
+
winston.info('Tilebot Listener listen');
|
|
25
|
+
winston.debug("Tilebot config databaseUri: " + config.databaseUri);
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
var that = this;
|
|
29
|
+
|
|
30
|
+
tybot.startApp(
|
|
31
|
+
{
|
|
32
|
+
MONGODB_URI: config.databaseUri,
|
|
33
|
+
API_ENDPOINT: apiUrl,
|
|
34
|
+
log: process.env.TILEBOT_LOG
|
|
35
|
+
}, () => {
|
|
36
|
+
winston.info("TileBot proxy server successfully started.");
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
botEvent.on('faqbot.create', function(bot) {
|
|
42
|
+
if (TILEBOT_ENDPOINT) {
|
|
43
|
+
|
|
44
|
+
winston.debug('bot.type:'+bot.type);
|
|
45
|
+
if (bot.type==="tilebot") {
|
|
46
|
+
|
|
47
|
+
winston.debug('qui.type:'+bot.type);
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
Faq_kb.findByIdAndUpdate(bot.id, {"url":TILEBOT_ENDPOINT+bot.id}, { new: true, upsert: true }, function (err, savedFaq_kb) {
|
|
51
|
+
|
|
52
|
+
// bot.save(function (err, savedFaq_kb) {
|
|
53
|
+
if (err) {
|
|
54
|
+
return winston.error('error saving faqkb tilebot ', err)
|
|
55
|
+
}
|
|
56
|
+
winston.verbose('Saved faqkb tilebot', savedFaq_kb.toObject())
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
var listener = new Listener();
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
module.exports = listener;
|