@tiledesk/tiledesk-server 2.3.74 → 2.3.76
Sign up to get free protection for your applications and to get access to all the features.
- package/middleware/passport.js +18 -1
- package/models/faq_kb.js +4 -1
- package/package.json +7 -6
- package/pubmodules/dialogflow/listener.js +1 -0
- package/pubmodules/emailNotification/requestNotification.js +10 -1
- package/pubmodules/rasa/listener.js +1 -0
- package/pubmodules/tilebot/listener.js +1 -0
- package/routes/auth.js +11 -3
- package/routes/faq_kb.js +16 -4
- package/routes/images.js +2 -2
- package/services/faqService.js +51 -4
- package/services/subscriptionNotifier.js +9 -1
- package/websocket/webSocketServer.js +11 -2
package/middleware/passport.js
CHANGED
@@ -33,9 +33,26 @@ const maskOptions = {
|
|
33
33
|
unmaskedEndDigits : 3 // Should be positive Integer
|
34
34
|
};
|
35
35
|
|
36
|
+
var alg = process.env.GLOBAL_SECRET_ALGORITHM;
|
37
|
+
winston.info('Authentication Global Algorithm : ' + alg);
|
36
38
|
|
37
|
-
|
39
|
+
// TODO STAMPA ANCHE PUBLIC
|
38
40
|
|
41
|
+
var configSecret = process.env.GLOBAL_SECRET || config.secret;
|
42
|
+
|
43
|
+
var pKey = process.env.GLOBAL_SECRET_OR_PUB_KEY;
|
44
|
+
// console.log("pKey",pKey);
|
45
|
+
|
46
|
+
if (pKey) {
|
47
|
+
configSecret = pKey.replace(/\\n/g, '\n');
|
48
|
+
}
|
49
|
+
// console.log("configSecret",configSecret);
|
50
|
+
// if (process.env.GLOBAL_SECRET_OR_PUB_KEY) {
|
51
|
+
// console.log("GLOBAL_SECRET_OR_PUB_KEY defined");
|
52
|
+
|
53
|
+
// }else {
|
54
|
+
// console.log("GLOBAL_SECRET_OR_PUB_KEY undefined");
|
55
|
+
// }
|
39
56
|
|
40
57
|
var maskedconfigSecret = MaskData.maskPhone(configSecret, maskOptions);
|
41
58
|
winston.info('Authentication Global Secret : ' + maskedconfigSecret);
|
package/models/faq_kb.js
CHANGED
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.3.
|
4
|
+
"version": "2.3.76",
|
5
5
|
"scripts": {
|
6
6
|
"start": "node ./bin/www",
|
7
7
|
"pretest": "mongodb-runner start",
|
@@ -37,14 +37,15 @@
|
|
37
37
|
},
|
38
38
|
"dependencies": {
|
39
39
|
"@tiledesk/tiledesk-apps": "^1.0.12",
|
40
|
-
"@tiledesk/tiledesk-whatsapp-connector": "^0.1.19",
|
41
|
-
"@tiledesk/tiledesk-kaleyra-proxy": "^0.1.6",
|
42
40
|
"@tiledesk/tiledesk-chat21-app": "^1.1.7",
|
43
41
|
"@tiledesk/tiledesk-chatbot-util": "^0.8.33",
|
42
|
+
"@tiledesk/tiledesk-dialogflow-connector": "^1.8.3",
|
44
43
|
"@tiledesk/tiledesk-json-rules-engine": "^4.0.3",
|
44
|
+
"@tiledesk/tiledesk-kaleyra-proxy": "^0.1.6",
|
45
45
|
"@tiledesk/tiledesk-rasa-connector": "^1.0.10",
|
46
|
-
"@tiledesk/tiledesk-tybot-connector": "^0.1.
|
47
|
-
"@tiledesk/tiledesk-
|
46
|
+
"@tiledesk/tiledesk-tybot-connector": "^0.1.53",
|
47
|
+
"@tiledesk/tiledesk-whatsapp-connector": "^0.1.19",
|
48
|
+
"amqplib": "^0.5.5",
|
48
49
|
"app-root-path": "^3.0.0",
|
49
50
|
"bcrypt-nodejs": "0.0.3",
|
50
51
|
"body-parser": "^1.20.0",
|
@@ -54,7 +55,6 @@
|
|
54
55
|
"csv-express": "^1.2.2",
|
55
56
|
"debug": "^4.3.4",
|
56
57
|
"dotenv": "^8.6.0",
|
57
|
-
"amqplib": "^0.5.5",
|
58
58
|
"email-templates": "^8.1.0",
|
59
59
|
"eventemitter2": "^6.4.4",
|
60
60
|
"express": "^4.17.3",
|
@@ -64,6 +64,7 @@
|
|
64
64
|
"fast-csv": "^4.3.6",
|
65
65
|
"geoip-lite": "^1.4.5",
|
66
66
|
"handlebars": "^4.7.7",
|
67
|
+
"handlebars-dateformat": "^1.1.3",
|
67
68
|
"html-entities": "^2.3.3",
|
68
69
|
"http": "0.0.0",
|
69
70
|
"immutable": "^4.1.0",
|
@@ -24,7 +24,16 @@ var configGlobal = require('../../config/global');
|
|
24
24
|
|
25
25
|
var widgetConfig = require('../../config/widget');
|
26
26
|
var widgetTestLocation = process.env.WIDGET_TEST_LOCATION || widgetConfig.testLocation;
|
27
|
-
|
27
|
+
|
28
|
+
|
29
|
+
let configSecret = process.env.GLOBAL_SECRET || config.secret;
|
30
|
+
|
31
|
+
var pKey = process.env.GLOBAL_SECRET_OR_PRIVATE_KEY;
|
32
|
+
// console.log("pKey",pKey);
|
33
|
+
|
34
|
+
if (pKey) {
|
35
|
+
configSecret = pKey.replace(/\\n/g, '\n');
|
36
|
+
}
|
28
37
|
|
29
38
|
let apiUrl = process.env.API_URL || configGlobal.apiUrl;
|
30
39
|
winston.debug('********* RequestNotification apiUrl: ' + apiUrl);
|
package/routes/auth.js
CHANGED
@@ -24,7 +24,15 @@ var validtoken = require('../middleware/valid-token');
|
|
24
24
|
var PendingInvitation = require("../models/pending-invitation");
|
25
25
|
const { check, validationResult } = require('express-validator');
|
26
26
|
var UserUtil = require('../utils/userUtil');
|
27
|
-
|
27
|
+
|
28
|
+
let configSecret = process.env.GLOBAL_SECRET || config.secret;
|
29
|
+
var pKey = process.env.GLOBAL_SECRET_OR_PRIVATE_KEY;
|
30
|
+
// console.log("pKey",pKey);
|
31
|
+
|
32
|
+
if (pKey) {
|
33
|
+
configSecret = pKey.replace(/\\n/g, '\n');
|
34
|
+
}
|
35
|
+
|
28
36
|
// const fs = require('fs');
|
29
37
|
// var configSecret = fs.readFileSync('private.key');
|
30
38
|
|
@@ -540,7 +548,7 @@ router.put('/requestresetpsw', function (req, res) {
|
|
540
548
|
emailService.sendPasswordResetRequestEmail(updatedUser.email, updatedUser.resetpswrequestid, updatedUser.firstname, updatedUser.lastname);
|
541
549
|
|
542
550
|
|
543
|
-
|
551
|
+
// TODO emit user.update?
|
544
552
|
authEvent.emit('user.requestresetpassword', {updatedUser:updatedUser, req:req});
|
545
553
|
|
546
554
|
|
@@ -598,7 +606,7 @@ router.put('/resetpsw/:resetpswrequestid', function (req, res) {
|
|
598
606
|
|
599
607
|
emailService.sendYourPswHasBeenChangedEmail(saveUser.email, saveUser.firstname, saveUser.lastname);
|
600
608
|
|
601
|
-
|
609
|
+
// TODO emit user.update?
|
602
610
|
authEvent.emit('user.resetpassword', {saveUser:saveUser, req:req});
|
603
611
|
|
604
612
|
|
package/routes/faq_kb.js
CHANGED
@@ -12,6 +12,7 @@ const { forEach } = require('lodash');
|
|
12
12
|
var multer = require('multer')
|
13
13
|
var upload = multer()
|
14
14
|
var configGlobal = require('../config/global');
|
15
|
+
const faq = require('../models/faq');
|
15
16
|
|
16
17
|
let chatbot_templates_api_url = process.env.CHATBOT_TEMPLATES_API_URL
|
17
18
|
|
@@ -250,6 +251,10 @@ router.put('/:faq_kbid', function (req, res) {
|
|
250
251
|
update.intentsEngine = req.body.intentsEngine;
|
251
252
|
}
|
252
253
|
|
254
|
+
if (req.body.tags != undefined) {
|
255
|
+
update.tags = req.body.tags;
|
256
|
+
}
|
257
|
+
|
253
258
|
Faq_kb.findByIdAndUpdate(req.params.faq_kbid, update, { new: true, upsert: true }, function (err, updatedFaq_kb) {
|
254
259
|
if (err) {
|
255
260
|
return res.status(500).send({ success: false, msg: 'Error updating object.' });
|
@@ -314,6 +319,7 @@ router.delete('/:faq_kbid', function (req, res) {
|
|
314
319
|
|
315
320
|
winston.debug(req.body);
|
316
321
|
|
322
|
+
|
317
323
|
Faq_kb.remove({ _id: req.params.faq_kbid }, function (err, faq_kb) {
|
318
324
|
if (err) {
|
319
325
|
return res.status(500).send({ success: false, msg: 'Error deleting object.' });
|
@@ -475,6 +481,7 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), (req, res) =>
|
|
475
481
|
id_project: req.projectid,
|
476
482
|
createdBy: req.user.id,
|
477
483
|
intent_display_name: intent.intent_display_name,
|
484
|
+
intent_id: intent.intent_id,
|
478
485
|
question: intent.question,
|
479
486
|
answer: intent.answer,
|
480
487
|
reply: intent.reply,
|
@@ -524,7 +531,7 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), (req, res) =>
|
|
524
531
|
} else {
|
525
532
|
|
526
533
|
if (req.query.create && req.query.create == 'true') {
|
527
|
-
faqService.create(json.name, undefined, req.projectid, req.user.id, "tilebot", json.description, json.webhook_url, json.webhook_enabled, json.language, undefined, undefined, undefined).then((savedFaq_kb) => {
|
534
|
+
faqService.create(json.name, undefined, req.projectid, req.user.id, "tilebot", json.description, json.webhook_url, json.webhook_enabled, json.language, undefined, undefined, undefined, json.attributes).then((savedFaq_kb) => {
|
528
535
|
winston.debug("saved (and imported) faq kb: ", savedFaq_kb);
|
529
536
|
botEvent.emit('faqbot.create', savedFaq_kb);
|
530
537
|
|
@@ -535,6 +542,7 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), (req, res) =>
|
|
535
542
|
id_project: req.projectid,
|
536
543
|
createdBy: req.user.id,
|
537
544
|
intent_display_name: intent.intent_display_name,
|
545
|
+
intent_id: intent.intent_id,
|
538
546
|
question: intent.question,
|
539
547
|
answer: intent.answer,
|
540
548
|
reply: intent.reply,
|
@@ -617,6 +625,9 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), (req, res) =>
|
|
617
625
|
if (json.description) {
|
618
626
|
faq_kb.description = json.description;
|
619
627
|
}
|
628
|
+
if (json.attributes) {
|
629
|
+
faq_kb.attributes = json.attributes;
|
630
|
+
}
|
620
631
|
|
621
632
|
Faq_kb.findByIdAndUpdate(id_faq_kb, faq_kb, { new: true }, (err, updatedFaq_kb) => {
|
622
633
|
if (err) {
|
@@ -632,6 +643,7 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), (req, res) =>
|
|
632
643
|
id_project: req.projectid,
|
633
644
|
createdBy: req.user.id,
|
634
645
|
intent_display_name: intent.intent_display_name,
|
646
|
+
intent_id: intent.intent_id,
|
635
647
|
question: intent.question,
|
636
648
|
answer: intent.answer,
|
637
649
|
reply: intent.reply,
|
@@ -687,7 +699,6 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), (req, res) =>
|
|
687
699
|
}
|
688
700
|
|
689
701
|
}
|
690
|
-
|
691
702
|
})
|
692
703
|
|
693
704
|
router.get('/exportjson/:id_faq_kb', (req, res) => {
|
@@ -704,10 +715,10 @@ router.get('/exportjson/:id_faq_kb', (req, res) => {
|
|
704
715
|
} else {
|
705
716
|
winston.debug('FAQ-KB: ', faq_kb)
|
706
717
|
|
707
|
-
|
708
718
|
faqService.getAll(id_faq_kb).then((faqs) => {
|
709
719
|
|
710
|
-
|
720
|
+
// delete from exclude map intent_id
|
721
|
+
const intents = faqs.map(({ _id, id_project, topic, status, id_faq_kb, createdBy, createdAt, updatedAt, __v, ...keepAttrs }) => keepAttrs)
|
711
722
|
|
712
723
|
let json = {
|
713
724
|
webhook_enabled: faq_kb.webhook_enabled,
|
@@ -715,6 +726,7 @@ router.get('/exportjson/:id_faq_kb', (req, res) => {
|
|
715
726
|
language: faq_kb.language,
|
716
727
|
name: faq_kb.name,
|
717
728
|
description: faq_kb.description,
|
729
|
+
attributes: faq_kb.attributes,
|
718
730
|
intents: intents
|
719
731
|
}
|
720
732
|
|
package/routes/images.js
CHANGED
@@ -192,11 +192,11 @@ uploadAvatar.single('file'), (req, res, next) => {
|
|
192
192
|
|
193
193
|
|
194
194
|
var destinationFolder = 'uploads/users/' + userid + "/images/";
|
195
|
-
winston.
|
195
|
+
winston.debug("destinationFolder:"+destinationFolder);
|
196
196
|
|
197
197
|
var thumFilename = destinationFolder+'thumbnails_200_200-photo.jpg';
|
198
198
|
|
199
|
-
winston.
|
199
|
+
winston.debug("req.file.filename:"+req.file.filename);
|
200
200
|
fileService.getFileDataAsBuffer(req.file.filename).then(function(buffer) {
|
201
201
|
|
202
202
|
sharp(buffer).resize(200, 200).toBuffer((err, resizeImage, info) => {
|
package/services/faqService.js
CHANGED
@@ -8,7 +8,7 @@ const ActionsConstants = require('../models/actionsConstants');
|
|
8
8
|
class FaqService {
|
9
9
|
|
10
10
|
|
11
|
-
create(name, url, projectid, user_id, type, description, webhook_url, webhook_enabled, language, template, mainCategory, intentsEngine) {
|
11
|
+
create(name, url, projectid, user_id, type, description, webhook_url, webhook_enabled, language, template, mainCategory, intentsEngine, attributes) {
|
12
12
|
var that = this;
|
13
13
|
return new Promise(function (resolve, reject) {
|
14
14
|
|
@@ -28,7 +28,8 @@ class FaqService {
|
|
28
28
|
intentsEngine: intentsEngine,
|
29
29
|
trashed: false,
|
30
30
|
createdBy: user_id,
|
31
|
-
updatedBy: user_id
|
31
|
+
updatedBy: user_id,
|
32
|
+
attributes: attributes
|
32
33
|
});
|
33
34
|
|
34
35
|
|
@@ -101,9 +102,55 @@ class FaqService {
|
|
101
102
|
|
102
103
|
if (template==="blank") {
|
103
104
|
|
105
|
+
// faqsArray = [
|
106
|
+
// { 'question': '\\start', 'answer': 'Hello', 'intent_display_name': 'start', 'topic': 'internal' },
|
107
|
+
// { 'question': 'defaultFallback', 'answer': 'I can not provide an adequate answer. Write a new question or talk to a human agent.\n* Back to start tdAction:start\n* See the docs https://docs.tiledesk.com/\n* 👨🏻🦰 I want an agent', 'intent_display_name': 'defaultFallback', 'topic': 'internal' }, //TODO se metto spazio n * nn va
|
108
|
+
// ]
|
104
109
|
faqsArray = [
|
105
|
-
{
|
106
|
-
|
110
|
+
{
|
111
|
+
'question': '\\start',
|
112
|
+
"actions" : [
|
113
|
+
{
|
114
|
+
"_tdActionType" : "reply",
|
115
|
+
"text" : "Hi, how can I help you?",
|
116
|
+
"attributes" : {
|
117
|
+
"commands" : [
|
118
|
+
{
|
119
|
+
"type" : "message",
|
120
|
+
"message" : {
|
121
|
+
"type" : "text",
|
122
|
+
"text" : "Hi, how can I help you?"
|
123
|
+
}
|
124
|
+
}
|
125
|
+
]
|
126
|
+
}
|
127
|
+
}
|
128
|
+
],
|
129
|
+
'intent_display_name': 'start',
|
130
|
+
'topic': 'internal'
|
131
|
+
},
|
132
|
+
{
|
133
|
+
'question': 'defaultFallback',
|
134
|
+
"actions" : [
|
135
|
+
{
|
136
|
+
"_tdActionType" : "reply",
|
137
|
+
"text" : "I didn't understand. Can you rephrase your question?",
|
138
|
+
"attributes" : {
|
139
|
+
"commands" : [
|
140
|
+
{
|
141
|
+
"type" : "message",
|
142
|
+
"message" : {
|
143
|
+
"type" : "text",
|
144
|
+
"text" : "I didn't understand. Can you rephrase your question?"
|
145
|
+
}
|
146
|
+
}
|
147
|
+
]
|
148
|
+
}
|
149
|
+
}
|
150
|
+
],
|
151
|
+
'intent_display_name': 'defaultFallback',
|
152
|
+
'topic': 'internal'
|
153
|
+
}, //TODO se metto spazio n * nn va
|
107
154
|
]
|
108
155
|
|
109
156
|
}
|
@@ -92,7 +92,15 @@ class SubscriptionNotifier {
|
|
92
92
|
signOptions.algorithm = alg;
|
93
93
|
}
|
94
94
|
|
95
|
-
secret = process.env.
|
95
|
+
secret = process.env.GLOBAL_SECRET || config.secret;
|
96
|
+
var pKey = process.env.GLOBAL_SECRET_OR_PRIVATE_KEY;
|
97
|
+
// console.log("pKey",pKey);
|
98
|
+
|
99
|
+
if (pKey) {
|
100
|
+
secret = pKey.replace(/\\n/g, '\n');
|
101
|
+
}
|
102
|
+
|
103
|
+
|
96
104
|
}
|
97
105
|
|
98
106
|
var token = jwt.sign(sJson, secret, signOptions); //priv_jwt pp_jwt
|
@@ -22,7 +22,16 @@ var cacheUtil = require('../utils/cacheUtil');
|
|
22
22
|
var mongoose = require('mongoose');
|
23
23
|
const requestConstants = require("../models/requestConstants");
|
24
24
|
var RoleConstants = require('../models/roleConstants');
|
25
|
-
|
25
|
+
|
26
|
+
let configSecretOrPubicKay = process.env.GLOBAL_SECRET || config.secret;
|
27
|
+
|
28
|
+
var pKey = process.env.GLOBAL_SECRET_OR_PUB_KEY;
|
29
|
+
// console.log("pKey",pKey);
|
30
|
+
|
31
|
+
if (pKey) {
|
32
|
+
configSecretOrPubicKay = pKey.replace(/\\n/g, '\n');
|
33
|
+
}
|
34
|
+
|
26
35
|
var cacheEnabler = require("../services/cacheEnabler");
|
27
36
|
|
28
37
|
|
@@ -92,7 +101,7 @@ class WebSocketServer {
|
|
92
101
|
// winston.debug('hasRoleAsPromise project_user',project_user);
|
93
102
|
// winston.debug('ok websocket');
|
94
103
|
|
95
|
-
User.findOne({_id: identifier, status: 100}, 'email firstname lastname emailverified id')
|
104
|
+
User.findOne({_id: identifier, status: 100}, 'email firstname lastname emailverified id') //TODO user_cache_here ma attento select.. ATTENTO SERVER SELECT??
|
96
105
|
//@DISABLED_CACHE .cache(cacheUtil.defaultTTL, "users:id:"+identifier) //user_cache
|
97
106
|
.exec(function (err, user) {
|
98
107
|
|