@tiledesk/tiledesk-server 2.13.51 → 2.13.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,8 +5,12 @@
5
5
  🚀 IN PRODUCTION 🚀
6
6
  (https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77)
7
7
 
8
- # 2.13.51
8
+ # 2.14.1
9
9
  - Refactoring of route() and create() method on RequestService in order to improve performance for firt message
10
+ - Fix bug: missing embedding apikey on add single content
11
+
12
+ # 2.13.51 - aborted
13
+ - Refactoring of route() and create() method on RequestService in order to improve performance for first message
10
14
  - Updated tests
11
15
 
12
16
  # 2.13.50
@@ -43,6 +43,7 @@ requestEvent.on('request.create.simple', function(request) {
43
43
 
44
44
  winston.debug('emitting request.create', requestComplete.toObject());
45
45
 
46
+ requestEvent.emit("request.snapshot.update", { request: request, snapshot: snapshot });
46
47
  requestEvent.emit('request.create', requestComplete);
47
48
 
48
49
  //with request.create no messages are sent. So don't load messages
@@ -3,6 +3,15 @@ var Schema = mongoose.Schema;
3
3
  // mongoose.set('debug', true);
4
4
  var winston = require('../config/winston');
5
5
 
6
+
7
+ var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI || config.database;
8
+
9
+ var readPreference = process.env.ANALYTICS_READ_PREFERENCE || "primary";
10
+ winston.info("Annalytics readPreference: " + readPreference);
11
+
12
+ var conn = mongoose.createConnection(databaseUri, { "autoIndex": true, readPreference: readPreference});
13
+
14
+
6
15
  var AnalyticResultSchema = new Schema({
7
16
  // _id: {
8
17
  // type: String,
@@ -14,7 +23,7 @@ var AnalyticResultSchema = new Schema({
14
23
  }}, { collection: 'requests' }
15
24
  );
16
25
 
17
- var analyticResult= mongoose.model('analyticResult', AnalyticResultSchema);
26
+ var analyticResult= conn.model('analyticResult', AnalyticResultSchema);
18
27
 
19
28
  if (process.env.MONGOOSE_SYNCINDEX) {
20
29
  analyticResult.syncIndexes();
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.13.51",
4
+ "version": "2.13.52",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
@@ -229,7 +229,9 @@ listen() {
229
229
  if (project_users && project_users.length>0) {
230
230
  project_users.forEach(project_user => {
231
231
  if (project_user.id_user && project_user.id_user.email) {
232
- return that.sendTranscriptByEmail(project_user.id_user.email, request_id, id_project, project);
232
+ return that.sendTranscriptByEmail(project_user.id_user.email, request_id, id_project, project).catch((err) => {
233
+ winston.error("(RequestNotification) sendTranscriptByEmail error for admin", err);
234
+ });
233
235
  } else {
234
236
  }
235
237
  });
@@ -242,7 +244,9 @@ listen() {
242
244
  return Lead.findById(request.requester_id, function(err, lead){
243
245
  //if (lead && lead.email) {
244
246
  if (lead && lead.email) {
245
- return that.sendTranscriptByEmail(lead.email, request_id, id_project, project);
247
+ return that.sendTranscriptByEmail(lead.email, request_id, id_project, project).catch((err) => {
248
+ winston.error("(RequestNotification) sendTranscriptByEmail error for lead", err);
249
+ });
246
250
  }
247
251
 
248
252
  });
@@ -156,7 +156,9 @@ class MessageActionsInterceptor {
156
156
 
157
157
  // closeRequestByRequestId(request_id, id_project, skipStatsUpdate, notify, closed_by)
158
158
  const closed_by = message.sender;
159
- requestService.closeRequestByRequestId(request.request_id, request.id_project, false, true, closed_by );
159
+ requestService.closeRequestByRequestId(request.request_id, request.id_project, false, true, closed_by ).catch((err) => {
160
+ winston.error("(MessageActionsInterceptor) closeRequestByRequestId error", err);
161
+ });
160
162
  // }, 1500);
161
163
 
162
164
 
@@ -413,7 +413,6 @@ function listen() {
413
413
  requestEvent.on('request.snapshot.update', function(data) {
414
414
  setImmediate(() => {
415
415
  winston.debug("reconnect request.snapshot.update")
416
- console.log("reconnect request.snapshot.update")
417
416
  publish(exchange, "request_snapshot_update", Buffer.from(JSON.stringify(data)));
418
417
  });
419
418
  });
@@ -25,7 +25,9 @@ class ConciergeBot {
25
25
  winston.info(" ConciergeBot request create", request);
26
26
  if (request.status < 100 && request.department.id_bot) {
27
27
  // addParticipantByRequestId(request_id, id_project, member) {
28
- requestService.addParticipantByRequestId(request.request_id, request.id_project, "bot_"+request.department.id_bot);
28
+ requestService.addParticipantByRequestId(request.request_id, request.id_project, "bot_"+request.department.id_bot).catch((err) => {
29
+ winston.error("(ConciergeBot) addParticipantByRequestId error", err);
30
+ });
29
31
  devi mandare un messaggio welcome tu altrimenti il bot inserito successivamente al primo messaggio non riceve il welcome iniziale
30
32
  }
31
33
  });
@@ -598,7 +598,9 @@ class RulesTrigger {
598
598
 
599
599
  // closeRequestByRequestId(request_id, id_project, skipStatsUpdate, notify, closed_by)
600
600
  const closed_by = "_trigger";
601
- requestService.closeRequestByRequestId(request_id, id_project, false, true, closed_by);
601
+ requestService.closeRequestByRequestId(request_id, id_project, false, true, closed_by).catch((err) => {
602
+ winston.error("(RulesTrigger) closeRequestByRequestId error", err);
603
+ });
602
604
 
603
605
  } catch(e) {
604
606
  winston.error("Error runAction", e);
@@ -634,7 +636,9 @@ class RulesTrigger {
634
636
  winston.debug('runAction action id_project: ' + id_project);
635
637
 
636
638
  // reopenRequestByRequestId(request_id, id_project) {
637
- requestService.reopenRequestByRequestId(request_id, id_project);
639
+ requestService.reopenRequestByRequestId(request_id, id_project).catch((err) => {
640
+ winston.error("(RulesTrigger) reopenRequestByRequestId error", err);
641
+ });
638
642
 
639
643
  } catch(e) {
640
644
  winston.error("Error runAction", e);
@@ -674,7 +678,9 @@ class RulesTrigger {
674
678
  winston.debug('runAction action id_project: ' + id_project);
675
679
 
676
680
  // addParticipantByRequestId(request_id, id_project, member) {
677
- requestService.addParticipantByRequestId(request_id, id_project, member);
681
+ requestService.addParticipantByRequestId(request_id, id_project, member).catch((err) => {
682
+ winston.error("(RulesTrigger) addParticipantByRequestId error", err);
683
+ });
678
684
 
679
685
 
680
686
  } catch(e) {
@@ -845,7 +851,9 @@ class RulesTrigger {
845
851
  winston.debug('runAction action id_project: ' + id_project);
846
852
 
847
853
  // addTagByRequestId(request_id, id_project, tag) {
848
- requestService.addTagByRequestId(request_id, id_project, {tag:tag});
854
+ requestService.addTagByRequestId(request_id, id_project, {tag:tag}).catch((err) => {
855
+ winston.error("(RulesTrigger) addTagByRequestId error", err);
856
+ });
849
857
 
850
858
 
851
859
  } catch(e) {
package/routes/kb.js CHANGED
@@ -1387,7 +1387,7 @@ router.post('/', async (req, res) => {
1387
1387
  new_kb.refresh_rate = body.refresh_rate;
1388
1388
  if (!body.scrape_type || body.scrape_type === 2) {
1389
1389
  new_kb.scrape_type = 2;
1390
- new_kb.scrape_options = await aiManager.setDefaultScrapeOptions();
1390
+ new_kb.scrape_options = aiManager.setDefaultScrapeOptions();
1391
1391
  } else {
1392
1392
  new_kb.scrape_type = body.scrape_type;
1393
1393
  new_kb.scrape_options = body.scrape_options;
@@ -1430,8 +1430,11 @@ router.post('/', async (req, res) => {
1430
1430
  json.parameters_scrape_type_4 = saved_kb.scrape_options;
1431
1431
  }
1432
1432
  json.engine = namespace.engine || default_engine;
1433
- json.embedding = namespace.embedding || default_embedding;
1434
1433
  json.hybrid = namespace.hybrid;
1434
+
1435
+ let embedding = namespace.embedding || default_embedding;
1436
+ embedding.api_key = process.env.EMBEDDING_API_KEY || process.env.GPTKEY;
1437
+ json.embedding = embedding;
1435
1438
 
1436
1439
  let resources = [];
1437
1440
 
@@ -1441,7 +1444,7 @@ router.post('/', async (req, res) => {
1441
1444
  return res.status(200).send({ success: true, message: "Schedule scrape skipped in test environment", data: raw_content, schedule_json: json });
1442
1445
  }
1443
1446
 
1444
- aiManager.scheduleScrape(resources, ns.hybrid);
1447
+ aiManager.scheduleScrape(resources, namespace.hybrid);
1445
1448
  return res.status(200).send(raw_content);
1446
1449
 
1447
1450
  }
package/routes/request.js CHANGED
@@ -363,6 +363,9 @@ router.put('/:requestid/close', async function (req, res) {
363
363
  return requestService.closeRequestByRequestId(req.params.requestid, req.projectid, false, true, closed_by, req.body.force).then(function (closedRequest) {
364
364
  winston.verbose("request closed", closedRequest);
365
365
  return res.json(closedRequest);
366
+ }).catch(function(err) {
367
+ winston.error("Error closing request", err);
368
+ return res.status(500).send({ success: false, error: "Error closing request" });
366
369
  });
367
370
 
368
371
  });
@@ -376,6 +379,9 @@ router.put('/:requestid/reopen', function (req, res) {
376
379
  winston.verbose("request reopen", reopenRequest);
377
380
 
378
381
  return res.json(reopenRequest);
382
+ }).catch(function(err) {
383
+ winston.error("Error reopening request", err);
384
+ return res.status(500).send({ success: false, error: "Error reopening request" });
379
385
  });
380
386
 
381
387
 
@@ -407,6 +413,9 @@ router.post('/:requestid/participants',
407
413
  winston.verbose("participant added", updatedRequest);
408
414
 
409
415
  return res.json(updatedRequest);
416
+ }).catch(function(err) {
417
+ winston.error("Error adding participant", err);
418
+ return res.status(500).send({ success: false, error: "Error adding participant" });
410
419
  });
411
420
 
412
421
  });
@@ -433,6 +442,9 @@ router.put('/:requestid/participants', function (req, res) {
433
442
  winston.debug("participant set", updatedRequest);
434
443
 
435
444
  return res.json(updatedRequest);
445
+ }).catch(function(err) {
446
+ winston.error("Error setting participants", err);
447
+ return res.status(500).send({ success: false, error: "Error setting participants" });
436
448
  });
437
449
 
438
450
  });
@@ -907,6 +919,9 @@ router.post('/:requestid/followers',
907
919
  winston.verbose("participant added", updatedRequest);
908
920
 
909
921
  return res.json(updatedRequest);
922
+ }).catch(function(err) {
923
+ winston.error("Error adding follower", err);
924
+ return res.status(500).send({ success: false, error: "Error adding follower" });
910
925
  });
911
926
 
912
927
  });
@@ -927,6 +942,9 @@ router.put('/:requestid/followers', function (req, res) {
927
942
  winston.debug("followers set", updatedRequest);
928
943
 
929
944
  return res.json(updatedRequest);
945
+ }).catch(function(err) {
946
+ winston.error("Error setting followers", err);
947
+ return res.status(500).send({ success: false, error: "Error setting followers" });
930
948
  });
931
949
 
932
950
  });
@@ -1010,6 +1028,9 @@ router.delete('/:requestid/followers/:followerid', function (req, res) {
1010
1028
  winston.verbose("follower removed", updatedRequest);
1011
1029
 
1012
1030
  return res.json(updatedRequest);
1031
+ }).catch(function(err) {
1032
+ winston.error("Error removing follower", err);
1033
+ return res.status(500).send({ success: false, error: "Error removing follower" });
1013
1034
  });
1014
1035
 
1015
1036
 
@@ -70,6 +70,9 @@ router.put('/:requestid/closeg', function (req, res) {
70
70
 
71
71
  return res.json(closedRequest);
72
72
 
73
+ }).catch(function(err) {
74
+ winston.error("Error closing request", err);
75
+ return res.status(500).send({ success: false, error: "Error closing request" });
73
76
  });
74
77
 
75
78
 
@@ -669,19 +669,19 @@ class RequestService {
669
669
  }
670
670
  await q.exec();
671
671
 
672
- requestEvent.emit("request.create.simple", savedRequest);
672
+ requestEvent.emit("request.create.simple", savedRequest, snapshot);
673
673
 
674
674
  if (isStandardConversation) {
675
675
  requestEvent.emit("request.create.quote", payload);
676
676
  }
677
677
 
678
678
  // Emit event to update snapshot in queue
679
- if (Object.keys(snapshot).length > 0) {
680
- requestEvent.emit("request.snapshot.update", {
681
- request: savedRequest,
682
- snapshot: snapshot
683
- });
684
- }
679
+ // if (Object.keys(snapshot).length > 0) {
680
+ // requestEvent.emit("request.snapshot.update", {
681
+ // request: savedRequest,
682
+ // snapshot: snapshot
683
+ // });
684
+ // }
685
685
 
686
686
  return savedRequest;
687
687