@tiledesk/tiledesk-server 2.4.59 → 2.4.60

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -5,7 +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.58
8
+ # 2.4.60
9
+ - improved kbsettings endpoints for qa, scrape and check status
10
+
11
+ # 2.4.59
9
12
  - update tiledesk-whatsapp-connector to 0.1.52
10
13
  - update tiledesk-telegram-connector to 0.1.8
11
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.59",
4
+ "version": "2.4.60",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
@@ -102,28 +102,36 @@ router.delete('/:settings_id/:kb_id', async (req, res) => {
102
102
  // PROXY PUGLIA AI - START
103
103
  router.post('/qa', async (req, res) => {
104
104
  let data = req.body;
105
- console.log("data: ", data);
105
+ winston.debug("/qa data: ", data);
106
+ console.log("/qa data: ", data);
106
107
 
107
108
  openaiService.ask(data).then((resp) => {
108
- // console.log("qa resp: ", resp.data);
109
+ winston.debug("qa resp: ", resp.data);
110
+ console.log("qa resp: ", resp.data);
109
111
  res.status(200).send(resp.data);
110
112
  }).catch((err) => {
111
113
  winston.error("qa err: ", err);
112
- res.status(500).send(err);
114
+ console.error("qa err: ", err);
115
+ let status = err.response.status;
116
+ res.status(status).send({ statusText: err.response.statusText, detail: err.response.data.detail });
113
117
  })
114
118
  })
115
119
 
116
120
  router.post('/startscrape', async (req, res) => {
117
121
 
118
122
  let data = req.body;
119
- console.log("data: ", data);
123
+ winston.debug("/startscrape data: ", data);
124
+ console.log("/startscrape data: ", data);
120
125
 
121
126
  openaiService.startScrape(data).then((resp) => {
122
- // console.log("startScrape resp: ", resp.data);
127
+ winston.debug("startScrape resp: ", resp.data);
128
+ console.log("startScrape resp: ", resp.data);
123
129
  res.status(200).send(resp.data);
124
130
  }).catch((err) => {
125
131
  winston.error("startScrape err: ", err);
126
- res.status(500).send(err);
132
+ console.error("startScrape err: ", err);
133
+ let status = err.response.status;
134
+ res.status(status).send({ statusText: err.response.statusText, detail: err.response.data.detail });
127
135
  })
128
136
  })
129
137
 
@@ -131,14 +139,18 @@ router.post('/startscrape', async (req, res) => {
131
139
  router.post('/checkstatus', async (req, res) => {
132
140
 
133
141
  let data = req.body;
134
- console.log("data: ", data);
142
+ winston.debug("/checkstatus data: ", data);
143
+ console.log("/checkstatus data: ", data);
135
144
 
136
145
  openaiService.checkStatus(data).then((resp) => {
137
- // console.log("checkStatus resp: ", resp.data);
146
+ winston.debug("checkStatus resp: ", resp.data);
147
+ console.log("checkStatus resp: ", resp.data);
138
148
  res.status(200).send(resp.data);
139
149
  }).catch((err) => {
140
- winston.error("checkStatus err: ", err);
141
- res.status(500).send(err);
150
+ winston.error("checkstatus err: ", err);
151
+ console.error("checkstatus err: ", err);
152
+ let status = err.response.status;
153
+ res.status(status).send({ statusText: err.response.statusText, detail: err.response.data.detail });
142
154
  })
143
155
  })
144
156
  // PROXY PUGLIA AI - END
@@ -24,11 +24,8 @@ class OpenaiService {
24
24
  data: data,
25
25
  method: 'POST'
26
26
  }).then((resbody) => {
27
- //winston.debug("[Openai] completions resbody: ", resbody.data);
28
27
  resolve(resbody);
29
28
  }).catch((err) => {
30
- console.log("err: ", err);
31
- // winston.error("[Openai] completions error: ", err);
32
29
  reject(err);
33
30
  })
34
31
 
@@ -53,7 +50,6 @@ class OpenaiService {
53
50
  }).then((resbody) => {
54
51
  resolve(resbody);
55
52
  }).catch((err) => {
56
- console.log("err: ", err);
57
53
  reject(err);
58
54
  })
59
55
 
@@ -75,7 +71,6 @@ class OpenaiService {
75
71
  }).then((resbody) => {
76
72
  resolve(resbody);
77
73
  }).catch((err) => {
78
- console.log("err: ", err);
79
74
  reject(err);
80
75
  })
81
76
 
@@ -244,7 +244,289 @@ describe('KbSettingsRoute', () => {
244
244
 
245
245
 
246
246
 
247
-
247
+ // THE FOLLOWING TEST REQUIRES REAL REQUESTS
248
+ // it('start scrape', (done) => {
249
+
250
+ // var email = "test-signup-" + Date.now() + "@email.com";
251
+ // var pwd = "pwd";
252
+
253
+ // userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
254
+ // projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
255
+
256
+ // chai.request(server)
257
+ // .post('/' + savedProject._id + '/kbsettings')
258
+ // .auth(email, pwd)
259
+ // .send({}) // can be empty
260
+ // .end((err, res) => {
261
+ // if (log) { console.log("create kbsettings res.body: ", res.body); }
262
+ // res.should.have.status(200);
263
+ // res.body.should.be.a('object');
264
+ // expect(res.body.id_project).to.equal(savedProject._id.toString());
265
+
266
+ // chai.request(server)
267
+ // .post('/' + savedProject._id + "/kbsettings/" + res.body._id)
268
+ // .auth(email, pwd)
269
+ // .send({ name: "exampleurl.com/kb/", url: "https://exampleurl.com/kb/" })
270
+ // .end((err, res) => {
271
+ // if (log) { console.log("add kb to kb settings res.body: ", res.body); }
272
+ // res.should.have.status(200);
273
+ // res.body.should.be.a('object');
274
+ // expect(res.body.kbs).to.have.length(1)
275
+
276
+ // chai.request(server)
277
+ // .post('/' + savedProject._id + "/kbsettings/startscrape")
278
+ // .auth(email, pwd)
279
+ // .send({ full_url: "https://developer.tiledesk.com/", gptkey: "valid-key" })
280
+ // .end( async (err, res) => {
281
+ // if (err) {
282
+ // console.log(" test err: ", err);
283
+ // }
284
+ // if (log) { console.log("start scrape res.body: ", res.body); }
285
+
286
+ // res.should.have.status(200);
287
+ // res.body.should.be.a('object');
288
+ // expect(res.body.message).to.not.equal(null);
289
+
290
+ // done();
291
+ // })
292
+
293
+ // })
294
+ // })
295
+
296
+ // });
297
+ // });
298
+
299
+ // }).timeout(20000)
300
+
301
+ // it('start scrape error - invalid key', (done) => {
302
+
303
+ // var email = "test-signup-" + Date.now() + "@email.com";
304
+ // var pwd = "pwd";
305
+
306
+ // userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
307
+ // projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
308
+
309
+ // chai.request(server)
310
+ // .post('/' + savedProject._id + '/kbsettings')
311
+ // .auth(email, pwd)
312
+ // .send({}) // can be empty
313
+ // .end((err, res) => {
314
+ // if (log) { console.log("create kbsettings res.body: ", res.body); }
315
+ // res.should.have.status(200);
316
+ // res.body.should.be.a('object');
317
+ // expect(res.body.id_project).to.equal(savedProject._id.toString());
318
+
319
+ // chai.request(server)
320
+ // .post('/' + savedProject._id + "/kbsettings/" + res.body._id)
321
+ // .auth(email, pwd)
322
+ // .send({ name: "exampleurl.com/kb/", url: "https://exampleurl.com/kb/" })
323
+ // .end((err, res) => {
324
+ // if (log) { console.log("add kb to kb settings res.body: ", res.body); }
325
+ // res.should.have.status(200);
326
+ // res.body.should.be.a('object');
327
+ // expect(res.body.kbs).to.have.length(1)
328
+
329
+ // chai.request(server)
330
+ // .post('/' + savedProject._id + "/kbsettings/startscrape")
331
+ // .auth(email, pwd)
332
+ // .send({ full_url: "https://developer.tiledesk.com/", gptkey: "invalid-gptkey" })
333
+ // .end( async (err, res) => {
334
+ // if (err) {
335
+ // console.log(" test err: ", err);
336
+ // }
337
+ // if (log) { console.log("start scrape res.body: ", res.body); }
338
+
339
+ // res.should.have.status(200);
340
+ // res.body.should.be.a('object');
341
+ // expect(res.body.message).to.not.equal(null);
342
+
343
+ // done();
344
+ // })
345
+
346
+ // })
347
+ // })
348
+
349
+ // });
350
+ // });
351
+
352
+ // }).timeout(20000)
353
+
354
+ // it('start scrape error - missing parameter', (done) => {
355
+
356
+ // var email = "test-signup-" + Date.now() + "@email.com";
357
+ // var pwd = "pwd";
358
+
359
+ // userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
360
+ // projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
361
+
362
+ // chai.request(server)
363
+ // .post('/' + savedProject._id + '/kbsettings')
364
+ // .auth(email, pwd)
365
+ // .send({}) // can be empty
366
+ // .end((err, res) => {
367
+ // if (log) { console.log("create kbsettings res.body: ", res.body); }
368
+ // res.should.have.status(200);
369
+ // res.body.should.be.a('object');
370
+ // expect(res.body.id_project).to.equal(savedProject._id.toString());
371
+
372
+ // chai.request(server)
373
+ // .post('/' + savedProject._id + "/kbsettings/" + res.body._id)
374
+ // .auth(email, pwd)
375
+ // .send({ name: "exampleurl.com/kb/", url: "https://exampleurl.com/kb/" })
376
+ // .end((err, res) => {
377
+ // if (log) { console.log("add kb to kb settings res.body: ", res.body); }
378
+ // res.should.have.status(200);
379
+ // res.body.should.be.a('object');
380
+ // expect(res.body.kbs).to.have.length(1)
381
+
382
+ // chai.request(server)
383
+ // .post('/' + savedProject._id + "/kbsettings/startscrape")
384
+ // .auth(email, pwd)
385
+ // // .send({ full_url: "https://fakeurl.com/support", gptkey: null })
386
+ // // OR
387
+ // .send({ full_url: "https://fakeurl.com/support" })
388
+ // .end((err, res) => {
389
+ // res.should.have.status(422);
390
+ // res.body.should.be.a('object');
391
+ // expect(res.body.statusText).to.equal("Unprocessable Entity");
392
+ // expect(res.body.detail).to.not.equal(null);
393
+
394
+ // done();
395
+ // })
396
+
397
+ // })
398
+ // })
399
+
400
+ // });
401
+ // });
402
+
403
+ // }).timeout(20000)
404
+
405
+ // it('check status error - missing parameter', (done) => {
406
+
407
+ // var email = "test-signup-" + Date.now() + "@email.com";
408
+ // var pwd = "pwd";
409
+
410
+ // userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
411
+ // projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
412
+
413
+ // chai.request(server)
414
+ // .post('/' + savedProject._id + '/kbsettings')
415
+ // .auth(email, pwd)
416
+ // .send({}) // can be empty
417
+ // .end((err, res) => {
418
+ // if (log) { console.log("create kbsettings res.body: ", res.body); }
419
+ // res.should.have.status(200);
420
+ // res.body.should.be.a('object');
421
+ // expect(res.body.id_project).to.equal(savedProject._id.toString());
422
+
423
+ // chai.request(server)
424
+ // .post('/' + savedProject._id + "/kbsettings/" + res.body._id)
425
+ // .auth(email, pwd)
426
+ // .send({ name: "exampleurl.com/kb/", url: "https://exampleurl.com/kb/" })
427
+ // .end((err, res) => {
428
+ // if (log) { console.log("add kb to kb settings res.body: ", res.body); }
429
+ // res.should.have.status(200);
430
+ // res.body.should.be.a('object');
431
+ // expect(res.body.kbs).to.have.length(1)
432
+
433
+ // chai.request(server)
434
+ // .post('/' + savedProject._id + "/kbsettings/checkstatus")
435
+ // .auth(email, pwd)
436
+ // // .send()
437
+ // // OR
438
+ // .send({ full_url: null })
439
+ // .end((err, res) => {
440
+ // res.should.have.status(422);
441
+ // res.body.should.be.a('object');
442
+ // expect(res.body.statusText).to.equal("Unprocessable Entity");
443
+ // expect(res.body.detail).to.not.equal(null);
444
+
445
+ // done();
446
+ // })
447
+
448
+ // })
449
+ // })
450
+
451
+ // });
452
+ // });
453
+
454
+ // }).timeout(20000)
455
+
456
+ // it('check status error - no db created for', (done) => {
457
+
458
+ // var email = "test-signup-" + Date.now() + "@email.com";
459
+ // var pwd = "pwd";
460
+
461
+ // userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
462
+ // projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
463
+
464
+ // chai.request(server)
465
+ // .post('/' + savedProject._id + '/kbsettings')
466
+ // .auth(email, pwd)
467
+ // .send({}) // can be empty
468
+ // .end((err, res) => {
469
+ // if (log) { console.log("create kbsettings res.body: ", res.body); }
470
+ // res.should.have.status(200);
471
+ // res.body.should.be.a('object');
472
+ // expect(res.body.id_project).to.equal(savedProject._id.toString());
473
+
474
+ // chai.request(server)
475
+ // .post('/' + savedProject._id + "/kbsettings/" + res.body._id)
476
+ // .auth(email, pwd)
477
+ // .send({ name: "dbnevercreated.com/kb/", url: "https://exampleurl.com/kb/" })
478
+ // .end((err, res) => {
479
+ // if (log) { console.log("add kb to kb settings res.body: ", res.body); }
480
+ // res.should.have.status(200);
481
+ // res.body.should.be.a('object');
482
+ // expect(res.body.kbs).to.have.length(1)
483
+
484
+ // chai.request(server)
485
+ // .post('/' + savedProject._id + "/kbsettings/checkstatus")
486
+ // .auth(email, pwd)
487
+ // .send({ full_url: "dbnevercreated.com/kb/" })
488
+ // .end((err, res) => {
489
+ // res.should.have.status(200);
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);
493
+
494
+ // done();
495
+ // })
496
+
497
+ // })
498
+ // })
499
+
500
+ // });
501
+ // });
502
+
503
+ // }).timeout(20000)
504
+
505
+ // it('qa error', (done) => {
506
+
507
+ // var email = "test-signup-" + Date.now() + "@email.com";
508
+ // var pwd = "pwd";
509
+
510
+ // userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
511
+ // projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
512
+
513
+ // chai.request(server)
514
+ // .post('/' + savedProject._id + "/kbsettings/qa")
515
+ // .auth(email, pwd)
516
+ // .send({ question: "How to connect Tiledesk with Telegram?", kbid: "https://gethelp.tiledesk.com/", gptkey: "valid-key" })
517
+ // .end((err, res) => {
518
+ // if (log) {}
519
+ // console.log("qa res.body: ", res.body);
520
+ // res.should.have.status(200);
521
+ // res.body.should.be.a('object');
522
+
523
+ // done();
524
+ // })
525
+
526
+ // });
527
+ // });
528
+
529
+ // }).timeout(20000)
248
530
 
249
531
  });
250
532