@tiledesk/tiledesk-server 2.4.69 → 2.4.70

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@
5
5
  🚀 IN PRODUCTION 🚀
6
6
  (https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77)
7
7
 
8
+ # 2.4.70
9
+ - campaign direct refactoring with job worker
10
+ - segment filter fix for lead
11
+
8
12
  # 2.4.69
9
13
  - update tiledesk-tybot-connector to 0.2.15
10
14
 
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.69",
4
+ "version": "2.4.70",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
package/routes/faq.js CHANGED
@@ -350,19 +350,28 @@ router.delete('/:faqid', function (req, res) {
350
350
  winston.debug('DELETE FAQ - FAQ ID ', req.params.faqid);
351
351
 
352
352
  let faqid = req.params.faqid;
353
+ let id_faq_kb;
354
+ if (req.query && req.query.id_faq_kb) {
355
+ id_faq_kb = req.query.id_faq_kb;
356
+ }
353
357
 
354
358
  if (faqid.startsWith("intentId")) {
355
- console.log("faqid is an intent_id")
356
359
  let intent_id = faqid.substring(8);
357
- console.log("faq intent_id: ", intent_id);
360
+ if (!id_faq_kb) {
361
+ return res.status(500).send({ success: false, msg: "Unable to delete object. Query param 'id_faq_kb' is mandatory if you want to delete via intent_id"})
362
+ }
358
363
 
359
- Faq.findOneAndDelete({ intent_id: intent_id }, (err, faq) => {
364
+ Faq.findOneAndDelete({ intent_id: intent_id, id_faq_kb: id_faq_kb }, (err, faq) => {
360
365
  if (err) {
361
366
  return res.status(500).send({ success: false, msg: "Error deleting object." });
362
367
  }
363
368
 
369
+ if (!faq) {
370
+ return res.status(404).send({ success: false, msg: "Error deleting object. The object does not exists."})
371
+ }
372
+
364
373
  winston.debug('Deleted FAQ ', faq);
365
-
374
+
366
375
  faqBotEvent.emit('faq.delete', faq);
367
376
  faqBotEvent.emit('faq_train.delete', faq.id_faq_kb);
368
377
 
package/routes/lead.js CHANGED
@@ -411,6 +411,15 @@ router.get('/', async(req, res) => {
411
411
 
412
412
  var query = {};
413
413
 
414
+
415
+ if (req.query.segment) {
416
+ let segment = await Segment.findOne({id_project: req.projectid, _id: req.query.segment }).exec();
417
+ if (!segment) {
418
+ return res.status(404).send({ success: false, msg: 'Error segment not found' });
419
+ }
420
+ Segment2MongoConverter.convert(query, segment);
421
+ }
422
+
414
423
  if (req.query.full_text) {
415
424
  winston.debug('LEAD ROUTE req.query.fulltext', req.query.full_text);
416
425
  query.$text = { "$search": req.query.full_text };
@@ -433,30 +442,21 @@ router.get('/', async(req, res) => {
433
442
 
434
443
  // aggiungi filtro per data
435
444
 
436
- if (req.query.status) {
437
- query.status = req.query.status;
438
- }
439
445
 
440
446
  if (req.query.tags) {
441
447
  winston.debug('req.query.tags', req.query.tags);
442
448
  query["tags"] = req.query.tags;
443
449
  }
444
450
 
445
-
446
- if (req.query.segment) {
447
- let segment = await Segment.findOne({id_project: req.projectid, _id: req.query.segment }).exec();
448
- if (!segment) {
449
- return res.status(404).send({ success: false, msg: 'Error segment not found' });
450
- }
451
- Segment2MongoConverter.convert(query, segment);
452
- }
453
-
454
-
455
451
 
456
452
  // last query modifier
457
453
  query["id_project"] = req.projectid;
458
454
  query["status"] = LeadConstants.NORMAL;
459
455
 
456
+ if (req.query.status) {
457
+ query.status = req.query.status;
458
+ }
459
+
460
460
  winston.debug("query", query);
461
461
 
462
462
 
package/test/faqRoute.js CHANGED
@@ -12,6 +12,7 @@ let server = require('../app');
12
12
  let should = chai.should();
13
13
  var fs = require('fs');
14
14
  const path = require('path');
15
+ const uuidv4 = require('uuid/v4');
15
16
 
16
17
 
17
18
  // chai.config.includeStack = true;
@@ -579,7 +580,7 @@ describe('FaqKBRoute', () => {
579
580
  })
580
581
  });
581
582
 
582
- it('delete with intent_id', (done) => {
583
+ it('deleteWithIntentId', (done) => {
583
584
 
584
585
  var email = "test-signup-" + Date.now() + "@email.com";
585
586
  var pwd = "pwd";
@@ -601,14 +602,14 @@ describe('FaqKBRoute', () => {
601
602
  chai.request(server)
602
603
  .post('/' + savedProject._id + '/faq')
603
604
  .auth(email, pwd)
604
- .send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1" })
605
+ .send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1", intent_id: uuidv4() })
605
606
  .end((err, res) => {
606
607
  if (log) { console.log("create intent res.body", res.body); }
607
608
  res.should.have.status(200);
608
609
  let faqid = res.body.intent_id;
609
610
 
610
611
  chai.request(server)
611
- .delete('/' + savedProject._id + '/faq/intentId' + faqid)
612
+ .delete('/' + savedProject._id + '/faq/intentId' + faqid + "?id_faq_kb=" + id_faq_kb)
612
613
  .auth(email, pwd)
613
614
  .end((err, res) => {
614
615
  if (log) { console.log("delete intent res.body", res.body); }
@@ -623,6 +624,96 @@ describe('FaqKBRoute', () => {
623
624
  })
624
625
  });
625
626
 
627
+ it('deleteWithIntentIdError', (done) => {
628
+
629
+ var email = "test-signup-" + Date.now() + "@email.com";
630
+ var pwd = "pwd";
631
+
632
+ userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
633
+ projectService.create("test-search-faqs", savedUser._id).then((savedProject) => {
634
+
635
+ chai.request(server)
636
+ .post('/' + savedProject._id + '/faq_kb')
637
+ .auth(email, pwd)
638
+ .send({ "name": "testbot", type: "internal", template: "example", intentsEngine: 'tiledesk-ai' })
639
+ .end((err, res) => {
640
+ if (log) { console.log("create chatbot res.body", res.body); }
641
+ res.should.have.status(200);
642
+ res.body.should.be.a('object');
643
+ expect(res.body.name).to.equal("testbot");
644
+ var id_faq_kb = res.body._id;
645
+
646
+ chai.request(server)
647
+ .post('/' + savedProject._id + '/faq')
648
+ .auth(email, pwd)
649
+ .send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1", intent_id: uuidv4() })
650
+ .end((err, res) => {
651
+ if (log) { console.log("create intent res.body", res.body); }
652
+ res.should.have.status(200);
653
+ let faqid = res.body.intent_id;
654
+
655
+ chai.request(server)
656
+ .delete('/' + savedProject._id + '/faq/intentId' + faqid)
657
+ // .delete('/' + savedProject._id + '/faq/intentId' + faqid + "?id_faq_kb=" + id_faq_kb)
658
+ .auth(email, pwd)
659
+ .end((err, res) => {
660
+ if (log) { console.log("delete intent res.body", res.body); }
661
+ res.should.have.status(500);
662
+
663
+ done();
664
+ })
665
+
666
+ })
667
+ })
668
+ })
669
+ })
670
+ });
671
+
672
+ it('deleteWithIntentIdErroWrongChatbotId', (done) => {
673
+
674
+ var email = "test-signup-" + Date.now() + "@email.com";
675
+ var pwd = "pwd";
676
+
677
+ userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
678
+ projectService.create("test-search-faqs", savedUser._id).then((savedProject) => {
679
+
680
+ chai.request(server)
681
+ .post('/' + savedProject._id + '/faq_kb')
682
+ .auth(email, pwd)
683
+ .send({ "name": "testbot", type: "internal", template: "example", intentsEngine: 'tiledesk-ai' })
684
+ .end((err, res) => {
685
+ if (log) { console.log("create chatbot res.body", res.body); }
686
+ res.should.have.status(200);
687
+ res.body.should.be.a('object');
688
+ expect(res.body.name).to.equal("testbot");
689
+ var id_faq_kb = res.body._id;
690
+
691
+ chai.request(server)
692
+ .post('/' + savedProject._id + '/faq')
693
+ .auth(email, pwd)
694
+ .send({ id_faq_kb: id_faq_kb, question: "question1", answer: "answer1", intent_id: uuidv4() })
695
+ .end((err, res) => {
696
+ if (log) { console.log("create intent res.body", res.body); }
697
+ res.should.have.status(200);
698
+ let faqid = res.body.intent_id;
699
+
700
+ chai.request(server)
701
+ .delete('/' + savedProject._id + '/faq/intentId' + faqid + "?id_faq_kb=11233")
702
+ // .delete('/' + savedProject._id + '/faq/intentId' + faqid + "?id_faq_kb=" + id_faq_kb)
703
+ .auth(email, pwd)
704
+ .end((err, res) => {
705
+ if (log) { console.log("delete intent res.body", res.body); }
706
+ res.should.have.status(404);
707
+
708
+ done();
709
+ })
710
+
711
+ })
712
+ })
713
+ })
714
+ })
715
+ });
716
+
626
717
 
627
718
  });
628
719