@tiledesk/tiledesk-server 2.4.72 → 2.4.73

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,9 @@
5
5
  🚀 IN PRODUCTION 🚀
6
6
  (https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77)
7
7
 
8
+ # 2.4.73
9
+ - Fix KB Settings bugs
10
+
8
11
  # 2.4.72
9
12
  - update tiledesk-messenger-connector to 0.1.11
10
13
 
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.72",
4
+ "version": "2.4.73",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
@@ -44,7 +44,7 @@
44
44
  "@tiledesk/tiledesk-kaleyra-proxy": "^0.1.7",
45
45
  "@tiledesk/tiledesk-messenger-connector": "0.1.11",
46
46
  "@tiledesk/tiledesk-rasa-connector": "^1.0.10",
47
- "@tiledesk/tiledesk-tybot-connector": "^0.2.16",
47
+ "@tiledesk/tiledesk-tybot-connector": "^0.2.17",
48
48
  "@tiledesk/tiledesk-whatsapp-connector": "^0.1.52",
49
49
  "@tiledesk/tiledesk-telegram-connector": "^0.1.8",
50
50
  "amqplib": "^0.5.5",
package/routes/faq.js CHANGED
@@ -122,7 +122,7 @@ router.post('/uploadcsv', upload.single('uploadFile'), function (req, res, next)
122
122
  })
123
123
  .on("end", function () {
124
124
  winston.debug("PARSE DONE");
125
- faqBotEvent.emit('faq_train.create', id_faq_kb)
125
+ //faqBotEvent.emit('faq_train.create', id_faq_kb)
126
126
  res.json({ success: true, msg: 'CSV Parsed' });
127
127
  })
128
128
  .on("error", function (err) {
@@ -191,7 +191,7 @@ router.post('/', function (req, res) {
191
191
  winston.debug('1. ID FAQKB GET IN THE OBJECT OF NEW FAQ CREATED ', savedFaq.id_faq_kb);
192
192
 
193
193
  faqBotEvent.emit('faq.create', savedFaq);
194
- faqBotEvent.emit('faq_train.create', req.body.id_faq_kb)
194
+ //faqBotEvent.emit('faq_train.create', req.body.id_faq_kb)
195
195
 
196
196
  res.json(savedFaq);
197
197
 
@@ -317,7 +317,7 @@ router.put('/:faqid', function (req, res) {
317
317
  }
318
318
 
319
319
  faqBotEvent.emit('faq.update', updatedFaq);
320
- faqBotEvent.emit('faq_train.update', updatedFaq.id_faq_kb);
320
+ //faqBotEvent.emit('faq_train.update', updatedFaq.id_faq_kb);
321
321
 
322
322
  res.status(200).send(updatedFaq);
323
323
  })
@@ -334,7 +334,7 @@ router.put('/:faqid', function (req, res) {
334
334
  }
335
335
 
336
336
  faqBotEvent.emit('faq.update', updatedFaq);
337
- faqBotEvent.emit('faq_train.update', updatedFaq.id_faq_kb);
337
+ //faqBotEvent.emit('faq_train.update', updatedFaq.id_faq_kb);
338
338
 
339
339
  res.status(200).send(updatedFaq);
340
340
  // updateRemoteFaq(updatedFaq)
@@ -373,7 +373,7 @@ router.delete('/:faqid', function (req, res) {
373
373
  winston.debug('Deleted FAQ ', faq);
374
374
 
375
375
  faqBotEvent.emit('faq.delete', faq);
376
- faqBotEvent.emit('faq_train.delete', faq.id_faq_kb);
376
+ //faqBotEvent.emit('faq_train.delete', faq.id_faq_kb);
377
377
 
378
378
  res.status(200).send(faq);
379
379
 
@@ -387,7 +387,7 @@ router.delete('/:faqid', function (req, res) {
387
387
  winston.debug('Deleted FAQ ', faq);
388
388
 
389
389
  faqBotEvent.emit('faq.delete', faq);
390
- faqBotEvent.emit('faq_train.delete', faq.id_faq_kb);
390
+ //faqBotEvent.emit('faq_train.delete', faq.id_faq_kb);
391
391
 
392
392
  res.status(200).send(faq);
393
393
 
package/routes/faq_kb.js CHANGED
@@ -130,6 +130,27 @@ router.post('/train', function (req, res) {
130
130
 
131
131
  });
132
132
 
133
+ router.post('/train/:id_faq_kb', async (req, res) => {
134
+ let id_faq_kb = req.params.id_faq_kb;
135
+
136
+ Faq_kb.findById(id_faq_kb, (err, chatbot) => {
137
+ if (err) {
138
+ return res.status(400).send({ success: false, error: err })
139
+ }
140
+ if (!chatbot) {
141
+ return res.status(404).send({ sucess: false, error: "Chatbot not found" });
142
+ }
143
+ if (chatbot.intentsEngine === 'tiledesk-ai') {
144
+ faqBotEvent.emit('faq_train.train', id_faq_kb);
145
+ return res.status(200).send({ success: true, message: "Training started"})
146
+ } else {
147
+ return res.status(200).send({ success: true, message: "Trained not started", reason: "Training available for intentsEngine equal to tiledesk-ai only" })
148
+ }
149
+ })
150
+
151
+
152
+ })
153
+
133
154
 
134
155
  router.post('/askbot', function (req, res) {
135
156
 
@@ -696,7 +717,7 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), async (req, r
696
717
  }
697
718
 
698
719
  })
699
- faqBotEvent.emit('faq_train.importedall', id_faq_kb);
720
+ //faqBotEvent.emit('faq_train.importedall', id_faq_kb);
700
721
  return res.status(200).send({ success: true, msg: "Intents imported successfully" })
701
722
 
702
723
  } else {
@@ -788,7 +809,7 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), async (req, r
788
809
 
789
810
  })
790
811
  }
791
- faqBotEvent.emit('faq_train.importedall', savedEditedFaq_kb._id);
812
+ //faqBotEvent.emit('faq_train.importedall', savedEditedFaq_kb._id);
792
813
  return res.status(200).send(savedEditedFaq_kb);
793
814
  })
794
815
 
@@ -914,7 +935,7 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), async (req, r
914
935
  })
915
936
 
916
937
  }
917
- faqBotEvent.emit('faq_train.importedall', id_faq_kb);
938
+ //faqBotEvent.emit('faq_train.importedall', id_faq_kb);
918
939
  return res.send(updatedFaq_kb);
919
940
 
920
941
  })
@@ -132,12 +132,43 @@ router.post('/startscrape', async (req, res) => {
132
132
 
133
133
  router.post('/checkstatus', async (req, res) => {
134
134
 
135
- let data = req.body;
136
- winston.debug("/checkstatus data: ", data);
135
+ // let data = req.body;
136
+ winston.debug("/checkstatus req.body: ", req.body);
137
+
138
+ let full_url = req.body.full_url;
139
+ let data = {
140
+ url_list: [ req.body.full_url ]
141
+ }
137
142
 
138
143
  openaiService.checkStatus(data).then((resp) => {
139
144
  winston.debug("checkStatus resp: ", resp.data);
140
- res.status(200).send(resp.data);
145
+ winston.debug("checkStatus resp: ", resp.data);
146
+ winston.debug("checkStatus resp: ", resp.data[full_url]);
147
+
148
+ let response = resp.data[full_url];
149
+
150
+ let return_data = {
151
+ status_message: response.status_message
152
+ }
153
+
154
+ if (response.status_code === 3) {
155
+ return_data.status_code = 2;
156
+ }
157
+
158
+ if (response.status_code === 1 || response.status_code === 2 ) {
159
+ return_data.status_code = 1;
160
+ }
161
+
162
+ if (response.status_code === 0) {
163
+ return_data.status_code = 0;
164
+ }
165
+
166
+ if (!response.status_code) {
167
+ return_data.status_code = 0;
168
+ }
169
+
170
+
171
+ res.status(200).send(return_data);
141
172
  }).catch((err) => {
142
173
  winston.error("checkstatus err: ", err);
143
174
  let status = err.response.status;
@@ -62,7 +62,7 @@ class OpenaiService {
62
62
  return new Promise((resolve, reject) => {
63
63
 
64
64
  axios({
65
- url: kb_endpoint + "/scrape/",
65
+ url: kb_endpoint + "/scrape",
66
66
  headers: {
67
67
  'Content-Type': 'application/json'
68
68
  },
@@ -83,7 +83,7 @@ class OpenaiService {
83
83
  return new Promise((resolve, reject) => {
84
84
 
85
85
  axios({
86
- url: kb_endpoint + "/qa/",
86
+ url: kb_endpoint + "/qa",
87
87
  headers: {
88
88
  'Content-Type': 'application/json'
89
89
  },
@@ -89,6 +89,12 @@ class TrainingService {
89
89
  start() {
90
90
  winston.info('TrainingService start');
91
91
 
92
+ faqBotEvent.on('faq_train.train', (id_faq_kb) => {
93
+ setImmediate(() => {
94
+ trainingService.train('faq_train.train', id_faq_kb);
95
+ })
96
+ })
97
+
92
98
  faqBotEvent.on('faq_train.importedall', (id_faq_kb) => {
93
99
  setImmediate(() => {
94
100
  trainingService.train('faq.importedall', id_faq_kb);
@@ -73,6 +73,53 @@ describe('FaqKBRoute', () => {
73
73
 
74
74
  }).timeout(20000);
75
75
 
76
+ it('train with tiledesk-ai qwerty', (done) => {
77
+ var email = "test-signup-" + Date.now() + "@email.com";
78
+ var pwd = "pwd";
79
+
80
+ userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
81
+ projectService.create("test-faqkb-create", savedUser._id).then((savedProject) => {
82
+
83
+ chai.request(server)
84
+ .post('/' + savedProject._id + '/faq_kb')
85
+ .auth(email, pwd)
86
+ .send({ "name": "testbot", type: "internal", template: "example", intentsEngine: "tiledesk-ai" })
87
+ .end((err, res) => {
88
+ if (log) {
89
+ console.log("res.body", res.body);
90
+ }
91
+ res.should.have.status(200);
92
+ res.body.should.be.a('object');
93
+ expect(res.body.name).to.equal("testbot");
94
+ var id_faq_kb = res.body._id;
95
+
96
+ chai.request(server)
97
+ .get('/' + savedProject._id + '/faq?id_faq_kb=' + id_faq_kb)
98
+ .auth(email, pwd)
99
+ .end((err, res) => {
100
+ console.log("faq_list: ", res.body);
101
+ res.should.have.status(200);
102
+ res.body.should.be.an('array').that.is.not.empty;
103
+
104
+ chai.request(server)
105
+ .post('/' + savedProject._id + '/faq_kb/train/' + id_faq_kb)
106
+ .auth(email, pwd)
107
+ .send({})
108
+ .end((err, res) => {
109
+ console.log("train res.body: ", res.body);
110
+ })
111
+
112
+ done();
113
+
114
+ })
115
+
116
+
117
+
118
+ });
119
+ })
120
+ })
121
+ })
122
+
76
123
 
77
124
  it('create with template example', (done) => {
78
125
 
@@ -453,7 +453,7 @@ describe('KbSettingsRoute', () => {
453
453
 
454
454
  // }).timeout(20000)
455
455
 
456
- // it('check status error - no db created for', (done) => {
456
+ // it('checkstatuserror - no db created for', (done) => {
457
457
 
458
458
  // var email = "test-signup-" + Date.now() + "@email.com";
459
459
  // var pwd = "pwd";
@@ -474,7 +474,7 @@ describe('KbSettingsRoute', () => {
474
474
  // chai.request(server)
475
475
  // .post('/' + savedProject._id + "/kbsettings/" + res.body._id)
476
476
  // .auth(email, pwd)
477
- // .send({ name: "dbnevercreated.com/kb/", url: "https://exampleurl.com/kb/" })
477
+ // .send({ name: "gethelp.tiledesk.com/", url: "https://gethelp.tiledesk.com/" })
478
478
  // .end((err, res) => {
479
479
  // if (log) { console.log("add kb to kb settings res.body: ", res.body); }
480
480
  // res.should.have.status(200);
@@ -484,12 +484,12 @@ describe('KbSettingsRoute', () => {
484
484
  // chai.request(server)
485
485
  // .post('/' + savedProject._id + "/kbsettings/checkstatus")
486
486
  // .auth(email, pwd)
487
- // .send({ full_url: "dbnevercreated.com/kb/" })
487
+ // .send({ full_url: "https://gethelp.tiledesk.com/" })
488
488
  // .end((err, res) => {
489
489
  // res.should.have.status(200);
490
490
  // res.body.should.be.a('object');
491
- // expect(res.body.status_message).to.equal("Database is not created yet for dbnevercreated.com/kb/, please wait a few minutes and try again");
492
- // expect(res.body.status_code).to.equal(0);
491
+ // // expect(res.body.status_message).to.equal("Database is not created yet for dbnevercreated.com/kb/, please wait a few minutes and try again");
492
+ // // expect(res.body.status_code).to.equal(0);
493
493
 
494
494
  // done();
495
495
  // })