@tiledesk/tiledesk-server 2.4.1 → 2.4.3
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/package.json +3 -3
- package/pubmodules/trigger/rulesTrigger.js +136 -1
- package/routes/faq_kb.js +49 -5
- package/services/modulesManager.js +4 -4
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@tiledesk/tiledesk-server",
|
3
3
|
"description": "The Tiledesk server module",
|
4
|
-
"version": "2.4.
|
4
|
+
"version": "2.4.3",
|
5
5
|
"scripts": {
|
6
6
|
"start": "node ./bin/www",
|
7
7
|
"pretest": "mongodb-runner start",
|
@@ -30,7 +30,7 @@
|
|
30
30
|
},
|
31
31
|
"optionalDependencies": {
|
32
32
|
"@tiledesk-ent/tiledesk-server-jwthistory": "^1.1.9",
|
33
|
-
"@tiledesk-ent/tiledesk-server-payments": "^1.1.
|
33
|
+
"@tiledesk-ent/tiledesk-server-payments": "^1.1.11",
|
34
34
|
"@tiledesk-ent/tiledesk-server-request-history": "^1.1.5",
|
35
35
|
"@tiledesk-ent/tiledesk-server-visitorcounter": "^1.1.1",
|
36
36
|
"@tiledesk-ent/tiledesk-server-enterprise": "^1.0.0"
|
@@ -45,7 +45,7 @@
|
|
45
45
|
"@tiledesk/tiledesk-messenger-connector": "0.1.9",
|
46
46
|
"@tiledesk/tiledesk-rasa-connector": "^1.0.10",
|
47
47
|
"@tiledesk/tiledesk-tybot-connector": "^0.1.77",
|
48
|
-
"@tiledesk/tiledesk-whatsapp-connector": "^0.1.
|
48
|
+
"@tiledesk/tiledesk-whatsapp-connector": "^0.1.45",
|
49
49
|
"amqplib": "^0.5.5",
|
50
50
|
"app-root-path": "^3.0.0",
|
51
51
|
"bcrypt-nodejs": "0.0.3",
|
@@ -23,7 +23,18 @@ var cacheUtil = require("../../utils/cacheUtil");
|
|
23
23
|
var cacheEnabler = require("../../services/cacheEnabler");
|
24
24
|
var UIDGenerator = require("../../utils/UIDGenerator");
|
25
25
|
const RequestConstants = require('../../models/requestConstants');
|
26
|
+
var Bot = require("../../models/faq_kb");
|
26
27
|
|
28
|
+
var request = require('retry-request', {
|
29
|
+
request: require('request')
|
30
|
+
});
|
31
|
+
const uuidv4 = require('uuid/v4');
|
32
|
+
|
33
|
+
var jwt = require('jsonwebtoken');
|
34
|
+
|
35
|
+
const port = process.env.PORT || '3000';
|
36
|
+
const TILEBOT_ENDPOINT = process.env.TILEBOT_ENDPOINT || "http://localhost:" + port+ "/modules/tilebot/ext/";
|
37
|
+
winston.debug("TILEBOT_ENDPOINT: " + TILEBOT_ENDPOINT);
|
27
38
|
|
28
39
|
class RulesTrigger {
|
29
40
|
|
@@ -285,7 +296,7 @@ class RulesTrigger {
|
|
285
296
|
var to = eventTrigger.event.request.lead.email;
|
286
297
|
winston.debug('to ' + to);
|
287
298
|
|
288
|
-
// sendEmailDirect(to, text,
|
299
|
+
// sendEmailDirect(to, text, id_project, recipient, subject, message)
|
289
300
|
sendEmailUtil.sendEmailDirect(to, text, id_project, recipient, subject, message);
|
290
301
|
} else {
|
291
302
|
winston.info('email.send trigger. Lead email is undefined ');
|
@@ -302,6 +313,130 @@ class RulesTrigger {
|
|
302
313
|
|
303
314
|
|
304
315
|
|
316
|
+
triggerEventEmitter.on('bot.calling', async (eventTrigger) => {
|
317
|
+
|
318
|
+
try {
|
319
|
+
|
320
|
+
winston.debug('runAction eventTrigger.eventSuccess:', eventTrigger.eventSuccess);
|
321
|
+
var trigger = eventTrigger.trigger;
|
322
|
+
winston.debug('runAction trigger', trigger.toObject());
|
323
|
+
|
324
|
+
|
325
|
+
var action = eventTrigger.action;
|
326
|
+
winston.debug('runAction action', action.toObject());
|
327
|
+
|
328
|
+
|
329
|
+
var intentName = action.parameters.intentName;
|
330
|
+
winston.debug('runAction action intentName: ' + intentName);
|
331
|
+
|
332
|
+
var botId = action.parameters.botId;
|
333
|
+
winston.debug('runAction action botId: ' + botId);
|
334
|
+
|
335
|
+
|
336
|
+
var url = TILEBOT_ENDPOINT+botId;
|
337
|
+
if (action.parameters.url) {
|
338
|
+
url = action.parameters.url;
|
339
|
+
}
|
340
|
+
winston.debug('runAction action url: ' + url);
|
341
|
+
|
342
|
+
|
343
|
+
var message = action.parameters.message;
|
344
|
+
winston.debug('runAction action message: ' + message);
|
345
|
+
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
if (eventTrigger.eventKey=="request.create" || eventTrigger.eventKey=="request.participants.join") {
|
350
|
+
// recipient = eventTrigger.event.request_id;
|
351
|
+
}
|
352
|
+
if (eventTrigger.eventKey=="message.create.from.requester" || eventTrigger.eventKey=="message.received") {
|
353
|
+
// recipient = eventTrigger.event.recipient;
|
354
|
+
}
|
355
|
+
if (eventTrigger.eventKey=="event.emit") {
|
356
|
+
winston.debug('runAction action event.emit: ', eventTrigger.event.toObject());
|
357
|
+
// recipient = eventTrigger.event.project_user.id_user;
|
358
|
+
}
|
359
|
+
|
360
|
+
// console.log("eventTrigger.event", eventTrigger.event);
|
361
|
+
|
362
|
+
var id_project = eventTrigger.event.id_project;
|
363
|
+
winston.debug('runAction action id_project: ' + id_project);
|
364
|
+
|
365
|
+
|
366
|
+
var payload = Object.assign({}, eventTrigger.event);;
|
367
|
+
winston.debug('runAction action payload: ', payload);
|
368
|
+
|
369
|
+
|
370
|
+
delete payload.request.snapshot
|
371
|
+
|
372
|
+
var json = {timestamp: Date.now(), payload: payload};
|
373
|
+
|
374
|
+
|
375
|
+
json["hook"] = trigger;
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
|
380
|
+
var bot = await Bot.findById(botId).select("+secret").exec();
|
381
|
+
winston.debug("bot: ", bot);
|
382
|
+
|
383
|
+
var signOptions = {
|
384
|
+
issuer: 'https://tiledesk.com',
|
385
|
+
subject: 'bot',
|
386
|
+
audience: 'https://tiledesk.com/bots/'+bot._id,
|
387
|
+
jwtid: uuidv4()
|
388
|
+
};
|
389
|
+
|
390
|
+
|
391
|
+
let botPayload = bot.toObject();
|
392
|
+
|
393
|
+
let botSecret = botPayload.secret;
|
394
|
+
|
395
|
+
delete botPayload.secret;
|
396
|
+
delete botPayload.description;
|
397
|
+
delete botPayload.attributes;
|
398
|
+
|
399
|
+
var token = jwt.sign(botPayload, botSecret, signOptions);
|
400
|
+
json["token"] = token;
|
401
|
+
|
402
|
+
|
403
|
+
var webhook_origin = process.env.WEBHOOK_ORIGIN || "http://localhost:3000";
|
404
|
+
winston.debug("webhook_origin: "+webhook_origin);
|
405
|
+
|
406
|
+
winston.debug("Rules trigger notify json ", json );
|
407
|
+
|
408
|
+
request({
|
409
|
+
url: url,
|
410
|
+
headers: {
|
411
|
+
'Content-Type' : 'application/json',
|
412
|
+
'User-Agent': 'tiledesk-bot',
|
413
|
+
'Origin': webhook_origin
|
414
|
+
//'x-hook-secret': s.secret
|
415
|
+
},
|
416
|
+
json: json,
|
417
|
+
method: 'POST'
|
418
|
+
|
419
|
+
}, function(err, result, json){
|
420
|
+
winston.verbose("SENT notify for bot with url " + url + " with err " + err);
|
421
|
+
winston.debug("SENT notify for bot with url ", result);
|
422
|
+
if (err) {
|
423
|
+
winston.error("Error sending notify for bot with url " + url + " with err " + err);
|
424
|
+
//TODO Reply with error
|
425
|
+
// next(err, json);
|
426
|
+
}
|
427
|
+
});
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
} catch(e) {
|
432
|
+
winston.error("Error runAction", e);
|
433
|
+
}
|
434
|
+
|
435
|
+
});
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
|
305
440
|
triggerEventEmitter.on('request.department.route', function(eventTrigger) {
|
306
441
|
|
307
442
|
try {
|
package/routes/faq_kb.js
CHANGED
@@ -13,6 +13,8 @@ var multer = require('multer')
|
|
13
13
|
var upload = multer()
|
14
14
|
var configGlobal = require('../config/global');
|
15
15
|
const faq = require('../models/faq');
|
16
|
+
var jwt = require('jsonwebtoken');
|
17
|
+
const uuidv4 = require('uuid/v4');
|
16
18
|
|
17
19
|
let chatbot_templates_api_url = process.env.CHATBOT_TEMPLATES_API_URL
|
18
20
|
|
@@ -311,7 +313,7 @@ router.put('/:faq_kbid', function (req, res) {
|
|
311
313
|
}
|
312
314
|
|
313
315
|
|
314
|
-
Faq_kb.findByIdAndUpdate(req.params.faq_kbid, update, { new: true, upsert: true }, function (err, updatedFaq_kb) {
|
316
|
+
Faq_kb.findByIdAndUpdate(req.params.faq_kbid, update, { new: true, upsert: true }, function (err, updatedFaq_kb) { //TODO add cache_bot_here
|
315
317
|
if (err) {
|
316
318
|
return res.status(500).send({ success: false, msg: 'Error updating object.' });
|
317
319
|
}
|
@@ -322,7 +324,7 @@ router.put('/:faq_kbid', function (req, res) {
|
|
322
324
|
});
|
323
325
|
|
324
326
|
|
325
|
-
router.patch('/:faq_kbid/attributes', function (req, res) {
|
327
|
+
router.patch('/:faq_kbid/attributes', function (req, res) { //TODO add cache_bot_here
|
326
328
|
var data = req.body;
|
327
329
|
|
328
330
|
// TODO use service method
|
@@ -388,7 +390,7 @@ router.get('/:faq_kbid', function (req, res) {
|
|
388
390
|
|
389
391
|
winston.debug(req.query);
|
390
392
|
|
391
|
-
Faq_kb.findById(req.params.faq_kbid, function (err, faq_kb) {
|
393
|
+
Faq_kb.findById(req.params.faq_kbid, function (err, faq_kb) { //TODO add cache_bot_here
|
392
394
|
if (err) {
|
393
395
|
return res.status(500).send({ success: false, msg: 'Error getting object.' });
|
394
396
|
}
|
@@ -430,6 +432,48 @@ router.get('/:faq_kbid', function (req, res) {
|
|
430
432
|
});
|
431
433
|
|
432
434
|
|
435
|
+
|
436
|
+
router.get('/:faq_kbid/jwt', function (req, res) {
|
437
|
+
|
438
|
+
winston.debug(req.query);
|
439
|
+
|
440
|
+
Faq_kb.findById(req.params.faq_kbid).select("+secret").exec(function (err, faq_kb) { //TODO add cache_bot_here
|
441
|
+
if (err) {
|
442
|
+
return res.status(500).send({ success: false, msg: 'Error getting object.' });
|
443
|
+
}
|
444
|
+
if (!faq_kb) {
|
445
|
+
return res.status(404).send({ success: false, msg: 'Object not found.' });
|
446
|
+
}
|
447
|
+
|
448
|
+
|
449
|
+
var signOptions = {
|
450
|
+
issuer: 'https://tiledesk.com',
|
451
|
+
subject: 'bot',
|
452
|
+
audience: 'https://tiledesk.com/bots/'+faq_kb._id,
|
453
|
+
jwtid: uuidv4()
|
454
|
+
};
|
455
|
+
|
456
|
+
// TODO metti bot_? a user._id
|
457
|
+
|
458
|
+
// tolgo description, attributes
|
459
|
+
let botPayload = faq_kb.toObject();
|
460
|
+
|
461
|
+
let botSecret = botPayload.secret;
|
462
|
+
// winston.info("botSecret: " + botSecret);
|
463
|
+
|
464
|
+
delete botPayload.secret;
|
465
|
+
delete botPayload.description;
|
466
|
+
delete botPayload.attributes;
|
467
|
+
|
468
|
+
var token = jwt.sign(botPayload, botSecret, signOptions);
|
469
|
+
|
470
|
+
|
471
|
+
res.json({"jwt":token});
|
472
|
+
|
473
|
+
});
|
474
|
+
});
|
475
|
+
|
476
|
+
|
433
477
|
// NEW - GET ALL FAQKB WITH THE PASSED PROJECT ID
|
434
478
|
router.get('/', function (req, res) {
|
435
479
|
|
@@ -467,7 +511,7 @@ router.get('/', function (req, res) {
|
|
467
511
|
|
468
512
|
winston.debug("query", query);
|
469
513
|
|
470
|
-
Faq_kb.find(query, function (err, faq_kb) {
|
514
|
+
Faq_kb.find(query, function (err, faq_kb) { //TODO add cache_bot_here
|
471
515
|
if (err) {
|
472
516
|
winston.error('GET FAQ-KB ERROR ', err)
|
473
517
|
return res.status(500).send({ success: false, message: "Unable to get chatbots" });
|
@@ -749,7 +793,7 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), async (req, r
|
|
749
793
|
// }
|
750
794
|
|
751
795
|
|
752
|
-
Faq_kb.findByIdAndUpdate(id_faq_kb, faq_kb, { new: true }, async (err, updatedFaq_kb) => {
|
796
|
+
Faq_kb.findByIdAndUpdate(id_faq_kb, faq_kb, { new: true }, async (err, updatedFaq_kb) => { //TODO add cache_bot_here
|
753
797
|
if (err) {
|
754
798
|
return res.status(500).send({ success: false, msg: "Error updating bot." });
|
755
799
|
}
|
@@ -148,11 +148,11 @@ class ModulesManager {
|
|
148
148
|
this.stripe = require('@tiledesk-ent/tiledesk-server-payments').stripeRoute;
|
149
149
|
winston.info("ModulesManager stripe initialized");
|
150
150
|
} catch(err) {
|
151
|
-
|
152
|
-
|
153
|
-
|
151
|
+
// if (err.code == 'MODULE_NOT_FOUND') {
|
152
|
+
// winston.info("ModulesManager init stripe module not found");
|
153
|
+
// }else {
|
154
154
|
winston.error("ModulesManager error initializing init stripe module", err);
|
155
|
-
|
155
|
+
// }
|
156
156
|
}
|
157
157
|
|
158
158
|
|