@tiledesk/tiledesk-server 2.3.94 → 2.3.96
Sign up to get free protection for your applications and to get access to all the features.
package/package.json
CHANGED
@@ -338,7 +338,12 @@ devi mandare un messaggio welcome tu altrimenti il bot inserito successivamente
|
|
338
338
|
if (request.subject) {
|
339
339
|
touchText = request.subject;
|
340
340
|
}
|
341
|
-
|
341
|
+
|
342
|
+
|
343
|
+
// touchText.replace(String.fromCharCode(92),""); //Bugfix when a conversation has a first_text with \agent
|
344
|
+
touchText = touchText.replace(/\\/g, "");
|
345
|
+
|
346
|
+
winston.debug("touchText: " + touchText);
|
342
347
|
|
343
348
|
// messageService.send(sender, senderFullname, recipient, text, id_project, createdBy, attributes, type);
|
344
349
|
messageService.send(
|
package/routes/faq_kb.js
CHANGED
@@ -17,7 +17,7 @@ const faq = require('../models/faq');
|
|
17
17
|
let chatbot_templates_api_url = process.env.CHATBOT_TEMPLATES_API_URL
|
18
18
|
|
19
19
|
router.post('/', function (req, res) {
|
20
|
-
winston.
|
20
|
+
winston.debug('create BOT ', req.body);
|
21
21
|
//create(name, url, projectid, user_id, type, description, webhook_url, webhook_enabled, language, template)
|
22
22
|
faqService.create(req.body.name, req.body.url, req.projectid, req.user.id, req.body.type, req.body.description, undefined, undefined, req.body.language, req.body.template, req.body.mainCategory, req.body.intentsEngine).then(function (savedFaq_kb) {
|
23
23
|
res.json(savedFaq_kb);
|
@@ -464,7 +464,7 @@ router.get('/', function (req, res) {
|
|
464
464
|
}
|
465
465
|
|
466
466
|
|
467
|
-
winston.
|
467
|
+
winston.debug("query", query);
|
468
468
|
|
469
469
|
Faq_kb.find(query, function (err, faq_kb) {
|
470
470
|
if (err) {
|
@@ -481,19 +481,19 @@ router.get('/', function (req, res) {
|
|
481
481
|
router.post('/fork/:id_faq_kb', async (req, res) => {
|
482
482
|
|
483
483
|
let id_faq_kb = req.params.id_faq_kb;
|
484
|
-
winston.
|
484
|
+
winston.debug('id_faq_kb: ' + id_faq_kb);
|
485
485
|
|
486
486
|
const api_url = process.env.API_URL || configGlobal.apiUrl;
|
487
|
-
winston.
|
487
|
+
winston.debug("fork --> base_url: " + api_url); // check if correct
|
488
488
|
|
489
489
|
let current_project_id = req.projectid;
|
490
|
-
winston.
|
490
|
+
winston.debug("current project id: " + current_project_id);
|
491
491
|
|
492
492
|
let landing_project_id = req.query.projectid;
|
493
|
-
winston.
|
493
|
+
winston.debug("landing project id " + landing_project_id)
|
494
494
|
|
495
495
|
let public = req.query.public;
|
496
|
-
winston.
|
496
|
+
winston.debug("public " + public);
|
497
497
|
|
498
498
|
let token = req.headers.authorization;
|
499
499
|
|
@@ -507,14 +507,14 @@ router.post('/fork/:id_faq_kb', async (req, res) => {
|
|
507
507
|
}
|
508
508
|
|
509
509
|
let savedChatbot = await cs.createBot(api_url, token, chatbot, landing_project_id);
|
510
|
-
winston.
|
510
|
+
winston.debug("savedChatbot: ", savedChatbot)
|
511
511
|
|
512
512
|
if (!savedChatbot) {
|
513
513
|
return res.status(500).send({ success: false, message: "Unable to create new chatbot" });
|
514
514
|
}
|
515
515
|
|
516
516
|
let import_result = await cs.importFaqs(api_url, savedChatbot._id, token, chatbot, landing_project_id);
|
517
|
-
winston.
|
517
|
+
winston.debug("imported: ", import_result);
|
518
518
|
|
519
519
|
if (import_result.success == "false") {
|
520
520
|
return res.status(500).send({ success: false, message: "Unable to import intents in the new chatbot" });
|
@@ -528,7 +528,7 @@ router.post('/fork/:id_faq_kb', async (req, res) => {
|
|
528
528
|
router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), async (req, res) => {
|
529
529
|
|
530
530
|
let id_faq_kb = req.params.id_faq_kb;
|
531
|
-
winston.
|
531
|
+
winston.debug('import on id_faq_kb: ', id_faq_kb);
|
532
532
|
|
533
533
|
let json_string;
|
534
534
|
let json;
|
@@ -539,11 +539,11 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), async (req, r
|
|
539
539
|
json = req.body;
|
540
540
|
}
|
541
541
|
|
542
|
-
winston.
|
542
|
+
winston.debug("json source " + json_string)
|
543
543
|
|
544
544
|
if (req.query.intentsOnly && req.query.intentsOnly == "true") {
|
545
545
|
|
546
|
-
winston.
|
546
|
+
winston.debug("intents only")
|
547
547
|
|
548
548
|
await json.intents.forEach((intent) => {
|
549
549
|
|
@@ -570,10 +570,10 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), async (req, r
|
|
570
570
|
winston.error("findOneAndUpdate (upsert) FAQ ERROR ", err);
|
571
571
|
} else {
|
572
572
|
if (savingResult.lastErrorObject.updatedExisting == true) {
|
573
|
-
winston.
|
573
|
+
winston.debug("updated existing intent")
|
574
574
|
faqBotEvent.emit('faq.update', savingResult.value);
|
575
575
|
} else {
|
576
|
-
winston.
|
576
|
+
winston.debug("new intent created")
|
577
577
|
faqBotEvent.emit('faq.create', savingResult.value);
|
578
578
|
}
|
579
579
|
}
|
@@ -586,9 +586,9 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), async (req, r
|
|
586
586
|
winston.debug("create new FAQ ERROR ", err);
|
587
587
|
if (err.code == 11000) {
|
588
588
|
winston.error("Duplicate intent_display_name.");
|
589
|
-
winston.
|
589
|
+
winston.debug("Skip duplicated intent_display_name");
|
590
590
|
} else {
|
591
|
-
winston.
|
591
|
+
winston.debug("new intent created")
|
592
592
|
faqBotEvent.emit('faq.create', savedFaq);
|
593
593
|
}
|
594
594
|
}
|
@@ -632,10 +632,10 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), async (req, r
|
|
632
632
|
} else {
|
633
633
|
|
634
634
|
if (savingResult.lastErrorObject.updatedExisting == true) {
|
635
|
-
winston.
|
635
|
+
winston.debug("updated existing intent")
|
636
636
|
faqBotEvent.emit('faq.update', savingResult.value);
|
637
637
|
} else {
|
638
|
-
winston.
|
638
|
+
winston.debug("new intent created")
|
639
639
|
faqBotEvent.emit('faq.create', savingResult.value);
|
640
640
|
}
|
641
641
|
|
@@ -650,9 +650,9 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), async (req, r
|
|
650
650
|
winston.debug("create new FAQ ERROR ", err);
|
651
651
|
if (err.code == 11000) {
|
652
652
|
winston.error("Duplicate intent_display_name.");
|
653
|
-
winston.
|
653
|
+
winston.debug("Skip duplicated intent_display_name");
|
654
654
|
} else {
|
655
|
-
winston.
|
655
|
+
winston.debug("new intent created")
|
656
656
|
faqBotEvent.emit('faq.create', savedFaq);
|
657
657
|
}
|
658
658
|
}
|
package/routes/images.js
CHANGED
@@ -422,15 +422,22 @@ router.get('/thumbnails', (req, res) => {
|
|
422
422
|
})
|
423
423
|
|
424
424
|
|
425
|
-
router.get("/", (req, res) => {
|
425
|
+
router.get("/", async (req, res) => {
|
426
426
|
winston.debug('path', req.query.path);
|
427
427
|
|
428
428
|
if (req.query.as_attachment) {
|
429
429
|
res.set({ "Content-Disposition": "attachment; filename=\""+req.query.path+"\"" });
|
430
|
+
|
430
431
|
}
|
431
432
|
|
432
433
|
|
433
434
|
// try {
|
435
|
+
let file = await fileService.find(req.query.path);
|
436
|
+
// console.log("file", file);
|
437
|
+
|
438
|
+
res.set({ "Content-Length": file.length});
|
439
|
+
res.set({ "Content-Type": file.contentType});
|
440
|
+
|
434
441
|
fileService.getFileDataAsStream(req.query.path).on('error', (e)=> {
|
435
442
|
if (e.code == "ENOENT") {
|
436
443
|
winston.debug('Image not found: '+req.query.path);
|
@@ -31,7 +31,7 @@ class ChatbotService {
|
|
31
31
|
|
32
32
|
async getBotById(id_faq_kb, published, api_url, chatbot_templates_api_url, token, project_id) {
|
33
33
|
|
34
|
-
winston.
|
34
|
+
winston.debug("[CHATBOT SERVICE] getBotById");
|
35
35
|
|
36
36
|
// private bot
|
37
37
|
if (published == "false") {
|
@@ -44,7 +44,7 @@ class ChatbotService {
|
|
44
44
|
},
|
45
45
|
method: 'GET'
|
46
46
|
}).then((resbody) => {
|
47
|
-
winston.
|
47
|
+
winston.debug("(CHATBOT SERVICE) forking private chatbot " + resbody.data.name)
|
48
48
|
let chatbot = resbody.data;
|
49
49
|
return chatbot;
|
50
50
|
}).catch((err) => {
|
@@ -97,7 +97,7 @@ class ChatbotService {
|
|
97
97
|
|
98
98
|
async importFaqs(api_url, id_faq_kb, token, chatbot, project_id) {
|
99
99
|
|
100
|
-
winston.
|
100
|
+
winston.debug("[CHATBOT SERVICE] importFaqs");
|
101
101
|
|
102
102
|
return await axios({
|
103
103
|
url: api_url + '/' + project_id + '/faq_kb/importjson/' + id_faq_kb + "?intentsOnly=true",
|
@@ -56,6 +56,17 @@ class FileGridFsService extends FileService {
|
|
56
56
|
});
|
57
57
|
}
|
58
58
|
|
59
|
+
async find(filename) {
|
60
|
+
return new Promise(async (resolve, reject) => {
|
61
|
+
let files = await this.gfs.find({filename: filename}).toArray();
|
62
|
+
winston.debug("files", files);
|
63
|
+
if (files.length>0) {
|
64
|
+
return resolve(files[0]);
|
65
|
+
} else {
|
66
|
+
return reject({msg:"File not found"});
|
67
|
+
}
|
68
|
+
});
|
69
|
+
}
|
59
70
|
async deleteFile(filename) {
|
60
71
|
return new Promise(async (resolve, reject) => {
|
61
72
|
let files = await this.gfs.find({filename: filename}).toArray();
|