@tiledesk/tiledesk-server 2.3.92 → 2.3.93

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -5,8 +5,26 @@
5
5
  🚀 IN PRODUCTION 🚀
6
6
  (https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77)
7
7
 
8
+ # 2.3.93 -> PROD v3
9
+ - subscriptionNotifier secret fix
8
10
 
9
- # 2.3.87 -> PROD v3
11
+ # 2.3.92
12
+ - Apps module fix for public secret key
13
+
14
+ # 2.3.91
15
+ - subscription webhook fix for global webhook secret creation for token
16
+ - added jsonRequest field to subscriptionLog to save request body payload
17
+
18
+ # 2.3.90
19
+ - Dependency updated tiledesk-tybot-connector 0.1.59
20
+
21
+ # 2.3.89
22
+ - added as_attachment query parameter to images endpoint to download the images
23
+
24
+ # 2.3.88
25
+ - added score, publishedBy and publishedAt to bot model
26
+
27
+ # 2.3.87
10
28
  - Geo Service fix with queue enabled
11
29
 
12
30
  # 2.3.86
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.92",
4
+ "version": "2.3.93",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
package/routes/faq_kb.js CHANGED
@@ -525,7 +525,7 @@ router.post('/fork/:id_faq_kb', async (req, res) => {
525
525
  })
526
526
 
527
527
 
528
- router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), (req, res) => {
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
531
  winston.info('import on id_faq_kb: ', id_faq_kb);
@@ -545,7 +545,7 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), (req, res) =>
545
545
 
546
546
  winston.info("intents only")
547
547
 
548
- json.intents.forEach((intent) => {
548
+ await json.intents.forEach((intent) => {
549
549
 
550
550
  let new_faq = {
551
551
  id_faq_kb: id_faq_kb,
@@ -573,7 +573,7 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), (req, res) =>
573
573
  winston.info("updated existing intent")
574
574
  faqBotEvent.emit('faq.update', savingResult.value);
575
575
  } else {
576
- winston.info("new intent crated")
576
+ winston.info("new intent created")
577
577
  faqBotEvent.emit('faq.create', savingResult.value);
578
578
  }
579
579
  }
@@ -588,7 +588,7 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), (req, res) =>
588
588
  winston.error("Duplicate intent_display_name.");
589
589
  winston.info("Skip duplicated intent_display_name");
590
590
  } else {
591
- winston.info("new intent crated")
591
+ winston.info("new intent created")
592
592
  faqBotEvent.emit('faq.create', savedFaq);
593
593
  }
594
594
  }
@@ -596,17 +596,17 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), (req, res) =>
596
596
  }
597
597
 
598
598
  })
599
-
599
+ faqBotEvent.emit('faq_train.importedall', id_faq_kb);
600
600
  return res.status(200).send({ success: true, msg: "Intents imported successfully" })
601
601
 
602
602
  } else {
603
603
 
604
604
  if (req.query.create && req.query.create == 'true') {
605
- 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) => {
605
+ 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( async (savedFaq_kb) => {
606
606
  winston.debug("saved (and imported) faq kb: ", savedFaq_kb);
607
607
  botEvent.emit('faqbot.create', savedFaq_kb);
608
608
 
609
- json.intents.forEach((intent) => {
609
+ await json.intents.forEach((intent) => {
610
610
 
611
611
  let new_faq = {
612
612
  id_faq_kb: savedFaq_kb._id,
@@ -635,7 +635,7 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), (req, res) =>
635
635
  winston.info("updated existing intent")
636
636
  faqBotEvent.emit('faq.update', savingResult.value);
637
637
  } else {
638
- winston.info("new intent crated")
638
+ winston.info("new intent created")
639
639
  faqBotEvent.emit('faq.create', savingResult.value);
640
640
  }
641
641
 
@@ -652,7 +652,7 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), (req, res) =>
652
652
  winston.error("Duplicate intent_display_name.");
653
653
  winston.info("Skip duplicated intent_display_name");
654
654
  } else {
655
- winston.info("new intent crated")
655
+ winston.info("new intent created")
656
656
  faqBotEvent.emit('faq.create', savedFaq);
657
657
  }
658
658
  }
@@ -660,6 +660,7 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), (req, res) =>
660
660
  }
661
661
 
662
662
  })
663
+ faqBotEvent.emit('faq_train.importedall', savedFaq_kb._id);
663
664
  return res.status(200).send(savedFaq_kb);
664
665
 
665
666
  }).catch((err) => {
@@ -699,15 +700,18 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), (req, res) =>
699
700
  if (json.attributes) {
700
701
  faq_kb.attributes = json.attributes;
701
702
  }
703
+ // if (json.intentsEngine) {
704
+ // faq_kb.intentsEngine = json.intentsEngine;
705
+ // }
702
706
 
703
- Faq_kb.findByIdAndUpdate(id_faq_kb, faq_kb, { new: true }, (err, updatedFaq_kb) => {
707
+ Faq_kb.findByIdAndUpdate(id_faq_kb, faq_kb, { new: true }, async (err, updatedFaq_kb) => {
704
708
  if (err) {
705
709
  return res.status(500).send({ success: false, msg: "Error updating bot." });
706
710
  }
707
711
 
708
712
  botEvent.emit('faqbot.update', updatedFaq_kb);
709
713
 
710
- json.intents.forEach((intent) => {
714
+ await json.intents.forEach((intent) => {
711
715
 
712
716
  let new_faq = {
713
717
  id_faq_kb: updatedFaq_kb._id,
@@ -736,7 +740,7 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), (req, res) =>
736
740
  winston.info("updated existing intent")
737
741
  faqBotEvent.emit('faq.update', savingResult.value);
738
742
  } else {
739
- winston.info("new intent crated")
743
+ winston.info("new intent created")
740
744
  faqBotEvent.emit('faq.create', savingResult.value);
741
745
  }
742
746
 
@@ -753,7 +757,7 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), (req, res) =>
753
757
  winston.error("Duplicate intent_display_name.");
754
758
  winston.info("Skip duplicated intent_display_name");
755
759
  } else {
756
- winston.info("new intent crated")
760
+ winston.info("new intent created")
757
761
  faqBotEvent.emit('faq.create', savedFaq);
758
762
  }
759
763
  }
@@ -761,7 +765,7 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), (req, res) =>
761
765
  }
762
766
 
763
767
  })
764
-
768
+ faqBotEvent.emit('faq_train.importedall', id_faq_kb);
765
769
  return res.send(updatedFaq_kb);
766
770
 
767
771
  })
@@ -796,7 +800,7 @@ router.get('/exportjson/:id_faq_kb', (req, res) => {
796
800
  webhook_url: faq_kb.webhook_url,
797
801
  language: faq_kb.language,
798
802
  name: faq_kb.name,
799
- description: faq_kb.description,
803
+ type: faq_kb.type,
800
804
  attributes: faq_kb.attributes,
801
805
  intents: intents
802
806
  }
@@ -75,7 +75,7 @@ class ChatbotService {
75
75
 
76
76
  async createBot(api_url, token, chatbot, project_id) {
77
77
 
78
- winston.info("[CHATBOT SERVICE] createBot");
78
+ winston.info("(CHATBOT SERVICE) createBot");
79
79
 
80
80
  return await axios({
81
81
  url: api_url + '/' + project_id + '/faq_kb/',
@@ -69,6 +69,7 @@ class SubscriptionNotifier {
69
69
 
70
70
  // winston.debug("s",s);
71
71
  var secret = s.secret;
72
+ var xHookSecret = secret;
72
73
 
73
74
  let sJson = s.toObject();
74
75
  delete sJson.secret;
@@ -91,17 +92,17 @@ class SubscriptionNotifier {
91
92
  if (alg) {
92
93
  signOptions.algorithm = alg;
93
94
  }
94
- var tokensecret = process.env.GLOBAL_SECRET || config.secret;
95
+ secret = process.env.GLOBAL_SECRET || config.secret;
95
96
  var pKey = process.env.GLOBAL_SECRET_OR_PRIVATE_KEY;
96
97
  // console.log("pKey",pKey);
97
98
 
98
99
  if (pKey) {
99
- tokensecret = pKey.replace(/\\n/g, '\n');
100
+ secret = pKey.replace(/\\n/g, '\n');
100
101
  }
101
102
 
102
103
  }
103
104
 
104
- var token = jwt.sign(sJson, tokensecret, signOptions); //priv_jwt pp_jwt
105
+ var token = jwt.sign(sJson, secret, signOptions); //priv_jwt pp_jwt
105
106
  json["token"] = token;
106
107
 
107
108
  winston.debug("Calling subscription " + s.event + " TO " + s.target + " with secret " +secret+ " with json " , json);
@@ -111,7 +112,7 @@ class SubscriptionNotifier {
111
112
  url: s.target,
112
113
  headers: {
113
114
  'Content-Type' : 'application/json',
114
- 'x-hook-secret': secret,
115
+ 'x-hook-secret': xHookSecret,
115
116
  'User-Agent': 'tiledesk-webhooks',
116
117
  'Origin': webhook_origin
117
118
  },
@@ -10,19 +10,27 @@ let chatbot_training_api_url = "http://34.65.210.38/model/train"
10
10
  class TrainingService {
11
11
 
12
12
 
13
+ train(eventName, id_faq_kb) {
13
14
 
14
- train(eventName, faq) {
15
+ Faq_kb.findById(id_faq_kb, (err, faq_kb) => {
15
16
 
16
- Faq_kb.findById(faq.id_faq_kb, (err, faq_kb) => {
17
- winston.debug("faq_kb: ", faq_kb)
17
+ if (err) {
18
+ winston.error("train error: ", err)
19
+ return null;
20
+ }
21
+
22
+ if (!faq_kb) {
23
+ winston.error("faq_kb is undefined");
24
+ return null;
25
+ }
18
26
 
19
27
  if (faq_kb.intentsEngine !== 'tiledesk-ai') {
20
28
  winston.info("intentsEngine: off")
21
29
  return null;
22
30
  }
23
31
 
24
- winston.info("intentsEngine: on")
25
- Faq.find({ id_faq_kb: faq.id_faq_kb }, (err, faqs) => {
32
+ winston.debug("intentsEngine: on")
33
+ Faq.find({ id_faq_kb: id_faq_kb }, (err, faqs) => {
26
34
 
27
35
  if (err) {
28
36
  winston.error("[Training] find all error: ", err);
@@ -31,7 +39,7 @@ class TrainingService {
31
39
  let json = {
32
40
  "configuration": {
33
41
  "language": faq_kb.language,
34
- "pipeline": [""]
42
+ "pipeline":["lstm"]
35
43
  },
36
44
  "model": faq_kb._id,
37
45
  "nlu": []
@@ -76,23 +84,27 @@ class TrainingService {
76
84
  start() {
77
85
  winston.info('TrainingService start');
78
86
 
79
- faqBotEvent.on('faq.create', (faq) => {
87
+ faqBotEvent.on('faq_train.importedall', (id_faq_kb) => {
88
+ setImmediate(() => {
89
+ trainingService.train('faq.importedall', id_faq_kb);
90
+ })
91
+ })
92
+
93
+ faqBotEvent.on('faq_train.create', (id_faq_kb) => {
80
94
  setImmediate(() => {
81
- trainingService.train('faq.create', faq);
95
+ trainingService.train('faq_train.create', id_faq_kb);
82
96
  })
83
97
  })
84
98
 
85
- faqBotEvent.on('faq.update', (faq) => {
86
- winston.debug("--> event faq: ", faq);
99
+ faqBotEvent.on('faq_train.update', (id_faq_kb) => {
87
100
  setImmediate(() => {
88
- trainingService.train('faq.update', faq);
101
+ trainingService.train('faq_train.update', id_faq_kb);
89
102
  })
90
103
  })
91
104
 
92
- faqBotEvent.on('faq.delete', (faq) => {
93
- console.log("--> event faq: ", faq);
105
+ faqBotEvent.on('faq_train.delete', (id_faq_kb) => {
94
106
  setImmediate(() => {
95
- trainingService.train('faq.delete', faq);
107
+ trainingService.train('faq_train.delete', id_faq_kb);
96
108
  })
97
109
  })
98
110
 
@@ -1,10 +1,10 @@
1
1
  const existing_chatbot_mock = {
2
2
  _id: "63234fd6c69f188814749e1b",
3
3
  webhook_enabled: false,
4
- type: "identity",
4
+ type: "tilebot",
5
5
  secret: "a3577185-a8bf-4547-a000-6ba81ccb0460",
6
6
  language: "en",
7
- description: "An identity bot",
7
+ description: "A Tiledesk bot",
8
8
  id_project: "63234fd6c69f188814749e15",
9
9
  trashed: false,
10
10
  createdBy: "system",
@@ -104,7 +104,7 @@ const existing_chatbot_mock = {
104
104
 
105
105
  const empty_chatbot_mock = {
106
106
  webhook_enabled: false,
107
- type: 'internal',
107
+ type: 'tilebot',
108
108
  secret: '0896478d-8eb3-4240-a6eb-cf2ea27b1a8e',
109
109
  language: 'en',
110
110
  public: false,
@@ -1 +1 @@
1
- {"webhook_enabled":false,"language":"en","name":"examplebot","intents":[{"webhook_enabled":false,"enabled":true,"question":"\\start","answer":"Hi","intent_display_name":"start","language":"en"},{"webhook_enabled":false,"enabled":true,"question":"question1","answer":"question1","intent_display_name":"question1","language":"en"},{"webhook_enabled":false,"enabled":true,"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","language":"en"}]}
1
+ {"webhook_enabled":false,"language":"en","name":"examplebot","intentsEngine":"tiledesk-ai","intents":[{"webhook_enabled":false,"enabled":true,"question":"\\start","answer":"Hi","intent_display_name":"start","language":"en"},{"webhook_enabled":false,"enabled":true,"question":"question1","answer":"question1","intent_display_name":"question1","language":"en"},{"webhook_enabled":false,"enabled":true,"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","language":"en"}]}
@@ -30,6 +30,7 @@ describe('FaqKBRoute', () => {
30
30
  describe('/create', () => {
31
31
 
32
32
 
33
+
33
34
  it('create', (done) => {
34
35
 
35
36
 
@@ -53,7 +54,15 @@ describe('FaqKBRoute', () => {
53
54
  expect(res.body.name).to.equal("testbot");
54
55
  expect(res.body.language).to.equal("fr");
55
56
 
56
- done();
57
+ chai.request(server)
58
+ .get('/' + savedProject._id + '/faq_kb/' + res.body._id)
59
+ .auth(email, pwd)
60
+ .end((err, res) => {
61
+ console.log("res.body", res.body);
62
+ res.should.have.status(200);
63
+
64
+ done();
65
+ });
57
66
  });
58
67
 
59
68