@tiledesk/tiledesk-server 2.13.50 → 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,6 +5,14 @@
5
5
  🚀 IN PRODUCTION 🚀
6
6
  (https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77)
7
7
 
8
+ # 2.14.1
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
14
+ - Updated tests
15
+
8
16
  # 2.13.50
9
17
  - Updated kb route to support embeddings
10
18
  - Updated tybot-connector to 2.0.41
package/app.js CHANGED
@@ -182,6 +182,7 @@ var geoService = require('./services/geoService');
182
182
  // geoService.listen(); //queued
183
183
 
184
184
  var updateLeadQueued = require('./services/updateLeadQueued');
185
+ var updateRequestSnapshotQueued = require('./services/updateRequestSnapshotQueued');
185
186
 
186
187
  let JobsManager = require('./jobsManager');
187
188
 
@@ -191,7 +192,7 @@ if (process.env.JOB_WORKER_ENABLED=="true" || process.env.JOB_WORKER_ENABLED ==
191
192
  }
192
193
  winston.info("JobsManager jobWorkerEnabled: "+ jobWorkerEnabled);
193
194
 
194
- let jobsManager = new JobsManager(jobWorkerEnabled, geoService, botEvent, subscriptionNotifierQueued, botSubscriptionNotifier, updateLeadQueued);
195
+ let jobsManager = new JobsManager(jobWorkerEnabled, geoService, botEvent, subscriptionNotifierQueued, botSubscriptionNotifier, updateLeadQueued, updateRequestSnapshotQueued);
195
196
 
196
197
  var faqBotHandler = require('./services/faqBotHandler');
197
198
  faqBotHandler.listen();
@@ -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
package/jobs.js CHANGED
@@ -29,6 +29,7 @@ const botEvent = require('./event/botEvent');
29
29
  var channelManager = require('./channels/channelManager');
30
30
 
31
31
  var updateLeadQueued = require('./services/updateLeadQueued');
32
+ var updateRequestSnapshotQueued = require('./services/updateRequestSnapshotQueued');
32
33
 
33
34
 
34
35
  require('./services/mongoose-cache-fn')(mongoose);
@@ -86,7 +87,7 @@ async function main()
86
87
 
87
88
 
88
89
 
89
- let jobsManager = new JobsManager(undefined, geoService, botEvent, subscriptionNotifierQueued, botSubscriptionNotifier, updateLeadQueued);
90
+ let jobsManager = new JobsManager(undefined, geoService, botEvent, subscriptionNotifierQueued, botSubscriptionNotifier, updateLeadQueued, updateRequestSnapshotQueued);
90
91
 
91
92
  jobsManager.listen();
92
93
 
package/jobsManager.js CHANGED
@@ -2,7 +2,7 @@
2
2
  var winston = require('./config/winston');
3
3
 
4
4
  class JobsManager {
5
- constructor(jobWorkerEnabled, geoService, botEvent, subscriptionNotifierQueued, botSubscriptionNotifier, updateLeadQueued) {
5
+ constructor(jobWorkerEnabled, geoService, botEvent, subscriptionNotifierQueued, botSubscriptionNotifier, updateLeadQueued, updateRequestSnapshotQueued) {
6
6
  this.geoService = geoService;
7
7
  this.botEvent = botEvent;
8
8
  // this.subscriptionNotifier = subscriptionNotifier;
@@ -22,6 +22,7 @@ class JobsManager {
22
22
  // winston.info("JobsManager jobWorkerEnabled: "+ this.jobWorkerEnabled);
23
23
 
24
24
  this.updateLeadQueued = updateLeadQueued;
25
+ this.updateRequestSnapshotQueued = updateRequestSnapshotQueued;
25
26
  }
26
27
 
27
28
 
@@ -39,6 +40,10 @@ class JobsManager {
39
40
 
40
41
  this.updateLeadQueued.listen();
41
42
 
43
+ if (this.updateRequestSnapshotQueued) {
44
+ this.updateRequestSnapshotQueued.listen();
45
+ }
46
+
42
47
  // this.botSubscriptionNotifier.start(); // disabled
43
48
  }
44
49
 
@@ -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.50",
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
 
@@ -204,9 +204,10 @@ function startWorker() {
204
204
  winston.info("Data queue", oka)
205
205
  });
206
206
 
207
-
208
-
209
-
207
+ ch.bindQueue(_ok.queue, exchange, "request_snapshot_update", {}, function(err3, oka) {
208
+ winston.info("Queue bind: "+_ok.queue+ " err: "+err3+ " key: request_snapshot_update");
209
+ winston.info("Data queue", oka)
210
+ });
210
211
 
211
212
 
212
213
  ch.consume(queueName, processMsg, { noAck: false });
@@ -320,6 +321,11 @@ function work(msg, cb) {
320
321
  leadEvent.emit('lead.fullname.email.update.queue', JSON.parse(message_string));
321
322
  }
322
323
 
324
+ if (topic === 'request_snapshot_update') {
325
+ winston.debug("reconnect here topic request_snapshot_update:" + topic);
326
+ requestEvent.emit('request.snapshot.update.queue', JSON.parse(message_string));
327
+ }
328
+
323
329
 
324
330
 
325
331
  cb(true);
@@ -404,6 +410,12 @@ function listen() {
404
410
  });
405
411
  });
406
412
 
413
+ requestEvent.on('request.snapshot.update', function(data) {
414
+ setImmediate(() => {
415
+ winston.debug("reconnect request.snapshot.update")
416
+ publish(exchange, "request_snapshot_update", Buffer.from(JSON.stringify(data)));
417
+ });
418
+ });
407
419
 
408
420
 
409
421
  messageEvent.on('message.create', function(message) {
@@ -184,6 +184,10 @@ function work(msg, cb) {
184
184
  winston.debug("reconnectfanout here topic faqbot_update:" + topic);
185
185
  botEvent.emit('faqbot.update.queue.pubsub', JSON.parse(message_string));
186
186
  }
187
+ if (topic === 'request_snapshot_add') {
188
+ winston.debug("reconnectfanout here topic request_snapshot_add:" + topic);
189
+ requestEvent.emit('request.snapshot.add.queue.pubsub', JSON.parse(message_string));
190
+ }
187
191
  cb(true);
188
192
  // WebSocket.cb(true);
189
193
  // requestEvent.on(msg.KEYYYYYYY+'.ws', msg.content);
@@ -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
  });
@@ -570,6 +582,7 @@ router.put('/:requestid/assign', function (req, res) {
570
582
  return res.json(updatedRequest);
571
583
  }).catch(function (error) {
572
584
  // TODO: error log removed due to attempt to reduces logs when no department is found
585
+ console.log('Error changing the department.', error)
573
586
  winston.verbose('Error changing the department.', error)
574
587
  return res.status(500).send({ success: false, msg: 'Error changing the department.' });
575
588
  })
@@ -587,6 +600,7 @@ router.put('/:requestid/departments', function (req, res) {
587
600
  return res.json(updatedRequest);
588
601
  }).catch(function (error) {
589
602
  // TODO: error log removed due to attempt to reduces logs when no department is found
603
+ console.log('Error changing the department.', error)
590
604
  winston.verbose('Error changing the department.', error)
591
605
  return res.status(500).send({ success: false, msg: 'Error changing the department.' });
592
606
  })
@@ -622,6 +636,7 @@ router.put('/:requestid/agent', async (req, res) => {
622
636
  return res.json(updatedRequest);
623
637
  }).catch(function (error) {
624
638
  // TODO: error log removed due to attempt to reduces logs when no department is found
639
+ console.log('Error changing the department.', error)
625
640
  winston.verbose('Error changing the department.', error)
626
641
  return res.status(500).send({ success: false, msg: 'Error changing the department.' });
627
642
  })
@@ -904,6 +919,9 @@ router.post('/:requestid/followers',
904
919
  winston.verbose("participant added", updatedRequest);
905
920
 
906
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" });
907
925
  });
908
926
 
909
927
  });
@@ -924,6 +942,9 @@ router.put('/:requestid/followers', function (req, res) {
924
942
  winston.debug("followers set", updatedRequest);
925
943
 
926
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" });
927
948
  });
928
949
 
929
950
  });
@@ -1007,6 +1028,9 @@ router.delete('/:requestid/followers/:followerid', function (req, res) {
1007
1028
  winston.verbose("follower removed", updatedRequest);
1008
1029
 
1009
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" });
1010
1034
  });
1011
1035
 
1012
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