@tiledesk/tiledesk-server 2.19.12 → 2.19.14

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.
@@ -6,6 +6,8 @@ const leadEvent = require('../../event/leadEvent');
6
6
 
7
7
  const botEvent = require('../../event/botEvent');
8
8
  const authEvent = require('../../event/authEvent');
9
+ const kbEvent = require('../../event/kbEvent');
10
+ const projectUserUpdateContextUtil = require('../../utils/projectUserUpdateContextUtil');
9
11
  // https://elements.heroku.com/addons/cloudamqp
10
12
  // https://gist.github.com/carlhoerberg/006b01ac17a0a94859ba#file-reconnect-js
11
13
  // http://www.rabbitmq.com/tutorials/tutorial-one-javascript.html
@@ -160,6 +162,11 @@ function startWorker() {
160
162
  winston.info("Data queue", oka)
161
163
  });
162
164
 
165
+ ch.bindQueue(_ok.queue, exchange, "request_assigned", {}, function(err3, oka) {
166
+ winston.info("Queue bind: "+_ok.queue+ " err: "+err3+ " key: request_assigned");
167
+ winston.info("Data queue", oka)
168
+ });
169
+
163
170
  ch.bindQueue(_ok.queue, exchange, "request_update", {}, function(err3, oka) {
164
171
  winston.info("Queue bind: "+_ok.queue+ " err: "+err3+ " key: request_update");
165
172
  winston.info("Data queue", oka)
@@ -189,11 +196,66 @@ function startWorker() {
189
196
  winston.info("Data queue", oka)
190
197
  });
191
198
 
199
+ ch.bindQueue(_ok.queue, exchange, "project_user_invite", {}, function(err3, oka) {
200
+ winston.info("Queue bind: "+_ok.queue+ " err: "+err3+ " key: project_user_invite");
201
+ winston.info("Data queue", oka)
202
+ });
203
+
204
+ ch.bindQueue(_ok.queue, exchange, "project_user_invite_pending", {}, function(err3, oka) {
205
+ winston.info("Queue bind: "+_ok.queue+ " err: "+err3+ " key: project_user_invite_pending");
206
+ winston.info("Data queue", oka)
207
+ });
208
+
209
+ ch.bindQueue(_ok.queue, exchange, "project_user_delete", {}, function(err3, oka) {
210
+ winston.info("Queue bind: "+_ok.queue+ " err: "+err3+ " key: project_user_delete");
211
+ winston.info("Data queue", oka)
212
+ });
213
+
192
214
  ch.bindQueue(_ok.queue, exchange, "faqbot_update", {}, function(err3, oka) {
193
215
  winston.info("Queue bind: "+_ok.queue+ " err: "+err3+ " key: faqbot_update");
194
216
  winston.info("Data queue", oka)
195
217
  });
196
218
 
219
+ ch.bindQueue(_ok.queue, exchange, "faqbot_created", {}, function(err3, oka) {
220
+ winston.info("Queue bind: "+_ok.queue+ " err: "+err3+ " key: faqbot_created");
221
+ winston.info("Data queue", oka)
222
+ });
223
+
224
+ ch.bindQueue(_ok.queue, exchange, "faqbot_deleted", {}, function(err3, oka) {
225
+ winston.info("Queue bind: "+_ok.queue+ " err: "+err3+ " key: faqbot_deleted");
226
+ winston.info("Data queue", oka)
227
+ });
228
+
229
+ ch.bindQueue(_ok.queue, exchange, "faqbot_publish", {}, function(err3, oka) {
230
+ winston.info("Queue bind: "+_ok.queue+ " err: "+err3+ " key: faqbot_publish");
231
+ winston.info("Data queue", oka)
232
+ });
233
+
234
+ ch.bindQueue(_ok.queue, exchange, "kb_namespace_create", {}, function(err3, oka) {
235
+ winston.info("Queue bind: "+_ok.queue+ " err: "+err3+ " key: kb_namespace_create");
236
+ winston.info("Data queue", oka)
237
+ });
238
+
239
+ ch.bindQueue(_ok.queue, exchange, "kb_namespace_delete", {}, function(err3, oka) {
240
+ winston.info("Queue bind: "+_ok.queue+ " err: "+err3+ " key: kb_namespace_delete");
241
+ winston.info("Data queue", oka)
242
+ });
243
+
244
+ ch.bindQueue(_ok.queue, exchange, "kb_contents_add", {}, function(err3, oka) {
245
+ winston.info("Queue bind: "+_ok.queue+ " err: "+err3+ " key: kb_contents_add");
246
+ winston.info("Data queue", oka)
247
+ });
248
+
249
+ ch.bindQueue(_ok.queue, exchange, "kb_contents_delete", {}, function(err3, oka) {
250
+ winston.info("Queue bind: "+_ok.queue+ " err: "+err3+ " key: kb_contents_delete");
251
+ winston.info("Data queue", oka)
252
+ });
253
+
254
+ ch.bindQueue(_ok.queue, exchange, "kb_content_delete", {}, function(err3, oka) {
255
+ winston.info("Queue bind: "+_ok.queue+ " err: "+err3+ " key: kb_content_delete");
256
+ winston.info("Data queue", oka)
257
+ });
258
+
197
259
  ch.bindQueue(_ok.queue, exchange, "lead_create", {}, function(err3, oka) {
198
260
  winston.info("Queue bind: "+_ok.queue+ " err: "+err3+ " key: lead_create");
199
261
  winston.info("Data queue", oka)
@@ -278,6 +340,11 @@ function work(msg, cb) {
278
340
  // requestEvent.emit('request.update.queue', msg.content);
279
341
  requestEvent.emit('request.participants.update.queue', JSON.parse(message_string));
280
342
  }
343
+
344
+ if (topic === 'request_assigned') {
345
+ winston.debug("reconnect here topic:" + topic);
346
+ requestEvent.emit('request.assigned.queue', JSON.parse(message_string));
347
+ }
281
348
 
282
349
  if (topic === 'request_close') {
283
350
  winston.debug("reconnect here topic:" + topic);
@@ -307,12 +374,59 @@ function work(msg, cb) {
307
374
  authEvent.emit('project_user.update.queue', JSON.parse(message_string));
308
375
  }
309
376
 
377
+ if (topic === 'project_user_invite') {
378
+ winston.debug("reconnect here topic:" + topic);
379
+ authEvent.emit('project_user.invite.queue', JSON.parse(message_string));
380
+ }
381
+
382
+ if (topic === 'project_user_invite_pending') {
383
+ winston.debug("reconnect here topic:" + topic);
384
+ authEvent.emit('project_user.invite.pending.queue', JSON.parse(message_string));
385
+ }
386
+
387
+ if (topic === 'project_user_delete') {
388
+ winston.debug("reconnect here topic:" + topic);
389
+ authEvent.emit('project_user.delete.queue', JSON.parse(message_string));
390
+ }
391
+
310
392
  if (topic === 'faqbot_update') {
311
393
  winston.debug("reconnect here topic faqbot_update:" + topic);
312
394
  // requestEvent.emit('request.update.queue', msg.content);
313
395
  botEvent.emit('faqbot.update.queue', JSON.parse(message_string));
314
396
  }
315
397
 
398
+ if (topic === 'faqbot_created') {
399
+ botEvent.emit('faqbot.created.queue', JSON.parse(message_string));
400
+ }
401
+
402
+ if (topic === 'faqbot_deleted') {
403
+ botEvent.emit('faqbot.deleted.queue', JSON.parse(message_string));
404
+ }
405
+
406
+ if (topic === 'faqbot_publish') {
407
+ botEvent.emit('faqbot.publish.queue', JSON.parse(message_string));
408
+ }
409
+
410
+ if (topic === 'kb_namespace_create') {
411
+ kbEvent.emit('kb.namespace.create.queue', JSON.parse(message_string));
412
+ }
413
+
414
+ if (topic === 'kb_namespace_delete') {
415
+ kbEvent.emit('kb.namespace.delete.queue', JSON.parse(message_string));
416
+ }
417
+
418
+ if (topic === 'kb_contents_add') {
419
+ kbEvent.emit('kb.contents.add.queue', JSON.parse(message_string));
420
+ }
421
+
422
+ if (topic === 'kb_contents_delete') {
423
+ kbEvent.emit('kb.contents.delete.queue', JSON.parse(message_string));
424
+ }
425
+
426
+ if (topic === 'kb_content_delete') {
427
+ kbEvent.emit('kb.content.delete.queue', JSON.parse(message_string));
428
+ }
429
+
316
430
  if (topic === 'lead_create') {
317
431
  winston.debug("reconnect here topic lead_create:" + topic);
318
432
  // requestEvent.emit('request.update.queue', msg.content);
@@ -357,6 +471,99 @@ function closeOnErr(err) {
357
471
  // publish(exchange, "request_update", Buffer.from("work2 work work: "+d));
358
472
  // }, 1000);
359
473
 
474
+ function serializeReqUser(req) {
475
+ if (!req || !req.user) {
476
+ return { user: null };
477
+ }
478
+ return {
479
+ user: {
480
+ id: req.user.id,
481
+ fullName: req.user.fullName
482
+ }
483
+ };
484
+ }
485
+
486
+ function serializeProjectUserInvitePayload(data) {
487
+ let user = undefined;
488
+ let body = undefined;
489
+ if (data.req) {
490
+ if (data.req.user) {
491
+ const u = data.req.user;
492
+ user = {
493
+ id: u.id || u._id,
494
+ _id: u._id,
495
+ firstname: u.firstname,
496
+ lastname: u.lastname,
497
+ fullName: projectUserUpdateContextUtil.userDisplayName(u)
498
+ };
499
+ }
500
+ if (data.req.body) {
501
+ body = data.req.body;
502
+ }
503
+ }
504
+ return {
505
+ req: {
506
+ user: user,
507
+ body: body,
508
+ projectid: data.req && data.req.projectid
509
+ },
510
+ savedProject_userPopulated: data.savedProject_userPopulated,
511
+ updatedProject_userPopulated: data.updatedProject_userPopulated,
512
+ updatedPuserPopulated: data.updatedPuserPopulated,
513
+ savedPendingInvitation: data.savedPendingInvitation
514
+ };
515
+ }
516
+
517
+ function serializeProjectUserDeletePayload(data) {
518
+ let user = undefined;
519
+ if (data.req && data.req.user) {
520
+ const u = data.req.user;
521
+ user = {
522
+ id: u.id || u._id,
523
+ _id: u._id,
524
+ firstname: u.firstname,
525
+ lastname: u.lastname,
526
+ fullName: projectUserUpdateContextUtil.userDisplayName(u)
527
+ };
528
+ }
529
+ return {
530
+ req: {
531
+ user: user,
532
+ projectid: data.req && data.req.projectid
533
+ },
534
+ project_userPopulated: data.project_userPopulated,
535
+ deleteType: data.deleteType
536
+ };
537
+ }
538
+
539
+ function serializeFaqbotActivityPayload(data) {
540
+ return {
541
+ chatbot: data.chatbot,
542
+ req: serializeReqUser(data.req),
543
+ id_project: data.id_project,
544
+ publishedBotId: data.publishedBotId,
545
+ release_note: data.release_note
546
+ };
547
+ }
548
+
549
+ function serializeKbActivityPayload(data) {
550
+ return {
551
+ req: serializeReqUser(data.req),
552
+ project_id: data.project_id,
553
+ namespace_id: data.namespace_id,
554
+ namespace_name: data.namespace_name,
555
+ savedNamespace: data.savedNamespace,
556
+ contentAddType: data.contentAddType,
557
+ count: data.count,
558
+ type: data.type,
559
+ source: data.source,
560
+ deletedCount: data.deletedCount,
561
+ deleteMode: data.deleteMode,
562
+ kb_id: data.kb_id,
563
+ kb: data.kb
564
+ };
565
+ }
566
+
360
567
 
361
568
  function listen() {
362
569
 
@@ -398,6 +605,13 @@ function listen() {
398
605
  });
399
606
  });
400
607
 
608
+ requestEvent.on('request.assigned', function(data) {
609
+ setImmediate(() => {
610
+ publish(exchange, "request_assigned", Buffer.from(JSON.stringify(data)));
611
+ winston.debug("reconnect request.assigned published")
612
+ });
613
+ });
614
+
401
615
  requestEvent.on('request.update.preflight', function(request) {
402
616
  setImmediate(() => {
403
617
  // winston.info("reconnect request.update.preflight")
@@ -446,18 +660,52 @@ function listen() {
446
660
  let body = undefined;
447
661
  if (data.req ) {
448
662
  if (data.req.user) { //i think is null from chat21webhook
449
- user = data.req.user;
663
+ const u = data.req.user;
664
+ user = {
665
+ id: u.id || u._id,
666
+ _id: u._id,
667
+ firstname: u.firstname,
668
+ lastname: u.lastname,
669
+ fullName: projectUserUpdateContextUtil.userDisplayName(u)
670
+ };
450
671
  }
451
672
  if (data.req.body) {
452
673
  body = data.req.body;
453
674
  }
454
675
  }
455
- var dat = {updatedProject_userPopulated: data.updatedProject_userPopulated, req: {user: user, body: body}}; //remove request
676
+ var dat = {
677
+ updatedProject_userPopulated: data.updatedProject_userPopulated,
678
+ req: { user: user, body: body, params: data.req && data.req.params },
679
+ previousUserAvailable: data.previousUserAvailable,
680
+ previousProfileStatus: data.previousProfileStatus,
681
+ updateContext: data.updateContext
682
+ };
456
683
  winston.debug("dat",dat);
457
684
  publish(exchange, "project_user_update", Buffer.from(JSON.stringify(dat)));
458
685
  });
459
686
  });
460
687
 
688
+ authEvent.on('project_user.invite', function(data) {
689
+ setImmediate(() => {
690
+ publish(exchange, "project_user_invite", Buffer.from(JSON.stringify(serializeProjectUserInvitePayload(data))));
691
+ winston.debug("reconnect project_user.invite published");
692
+ });
693
+ });
694
+
695
+ authEvent.on('project_user.invite.pending', function(data) {
696
+ setImmediate(() => {
697
+ publish(exchange, "project_user_invite_pending", Buffer.from(JSON.stringify(serializeProjectUserInvitePayload(data))));
698
+ winston.debug("reconnect project_user.invite.pending published");
699
+ });
700
+ });
701
+
702
+ authEvent.on('project_user.delete', function(data) {
703
+ setImmediate(() => {
704
+ publish(exchange, "project_user_delete", Buffer.from(JSON.stringify(serializeProjectUserDeletePayload(data))));
705
+ winston.debug("reconnect project_user.delete published");
706
+ });
707
+ });
708
+
461
709
 
462
710
  botEvent.on('faqbot.update', function(bot) {
463
711
  setImmediate(() => {
@@ -467,6 +715,62 @@ function listen() {
467
715
  });
468
716
  });
469
717
 
718
+ botEvent.on('faqbot.created', function(data) {
719
+ setImmediate(() => {
720
+ publish(exchange, "faqbot_created", Buffer.from(JSON.stringify(serializeFaqbotActivityPayload(data))));
721
+ winston.debug("reconnect faqbot.created published");
722
+ });
723
+ });
724
+
725
+ botEvent.on('faqbot.deleted', function(data) {
726
+ setImmediate(() => {
727
+ publish(exchange, "faqbot_deleted", Buffer.from(JSON.stringify(serializeFaqbotActivityPayload(data))));
728
+ winston.debug("reconnect faqbot.deleted published");
729
+ });
730
+ });
731
+
732
+ botEvent.on('faqbot.publish', function(data) {
733
+ setImmediate(() => {
734
+ publish(exchange, "faqbot_publish", Buffer.from(JSON.stringify(serializeFaqbotActivityPayload(data))));
735
+ winston.debug("reconnect faqbot.publish published");
736
+ });
737
+ });
738
+
739
+ kbEvent.on('kb.namespace.create', function(data) {
740
+ setImmediate(() => {
741
+ publish(exchange, "kb_namespace_create", Buffer.from(JSON.stringify(serializeKbActivityPayload(data))));
742
+ winston.debug("reconnect kb.namespace.create published");
743
+ });
744
+ });
745
+
746
+ kbEvent.on('kb.namespace.delete', function(data) {
747
+ setImmediate(() => {
748
+ publish(exchange, "kb_namespace_delete", Buffer.from(JSON.stringify(serializeKbActivityPayload(data))));
749
+ winston.debug("reconnect kb.namespace.delete published");
750
+ });
751
+ });
752
+
753
+ kbEvent.on('kb.contents.add', function(data) {
754
+ setImmediate(() => {
755
+ publish(exchange, "kb_contents_add", Buffer.from(JSON.stringify(serializeKbActivityPayload(data))));
756
+ winston.debug("reconnect kb.contents.add published");
757
+ });
758
+ });
759
+
760
+ kbEvent.on('kb.contents.delete', function(data) {
761
+ setImmediate(() => {
762
+ publish(exchange, "kb_contents_delete", Buffer.from(JSON.stringify(serializeKbActivityPayload(data))));
763
+ winston.debug("reconnect kb.contents.delete published");
764
+ });
765
+ });
766
+
767
+ kbEvent.on('kb.content.delete', function(data) {
768
+ setImmediate(() => {
769
+ publish(exchange, "kb_content_delete", Buffer.from(JSON.stringify(serializeKbActivityPayload(data))));
770
+ winston.debug("reconnect kb.content.delete published");
771
+ });
772
+ });
773
+
470
774
 
471
775
  leadEvent.on('lead.create', function(lead) {
472
776
  setImmediate(() => {
@@ -504,6 +808,7 @@ if (process.env.QUEUE_ENABLED === "true") {
504
808
  messageEvent.queueEnabled = true;
505
809
  authEvent.queueEnabled = true;
506
810
  botEvent.queueEnabled = true;
811
+ kbEvent.queueEnabled = true;
507
812
  leadEvent.queueEnabled = true;
508
813
  listen();
509
814
  start();
@@ -9,6 +9,7 @@ var LeadConstants = require("../../models/leadConstants");
9
9
  var winston = require('../../config/winston');
10
10
  var i8nUtil = require("../../utils/i8nUtil");
11
11
  var BotFromParticipant = require("../../utils/botFromParticipant");
12
+ var assignmentContextUtil = require('../../utils/assignmentContextUtil');
12
13
  const RequestConstants = require('../../models/requestConstants');
13
14
 
14
15
  class ConciergeBot {
@@ -81,7 +82,12 @@ devi mandare un messaggio welcome tu altrimenti il bot inserito successivamente
81
82
  winston.debug("rerouting");
82
83
  // reroute(request_id, id_project, nobot)
83
84
 
84
- requestService.reroute(message.request.request_id, message.request.id_project, false ).then(function() {
85
+ requestService.reroute(
86
+ message.request.request_id,
87
+ message.request.id_project,
88
+ false,
89
+ assignmentContextUtil.buildInternalOptions('rules', 'auto')
90
+ ).then(function() {
85
91
  winston.debug("reroute successful from event message.create");
86
92
  }).catch((err) => {
87
93
  winston.error("ConciergeBot error reroute: " + err);
@@ -13,6 +13,7 @@ var Engine = require('@tiledesk/tiledesk-json-rules-engine').Engine;
13
13
 
14
14
  var messageService = require('../../services/messageService');
15
15
  var requestService = require('../../services/requestService');
16
+ var assignmentContextUtil = require('../../utils/assignmentContextUtil');
16
17
  var MessageConstants = require("../../models/messageConstants");
17
18
  var leadService = require('../../services/leadService');
18
19
  var LeadConstants = require('../../models/leadConstants');
@@ -477,7 +478,14 @@ class RulesTrigger {
477
478
  winston.debug('runAction action id_project: ' + id_project);
478
479
 
479
480
  // route(request_id, departmentid, id_project, nobot) {
480
- requestService.route(request_id, departmentid, id_project).catch((err) => {
481
+ requestService.route(
482
+ request_id,
483
+ departmentid,
484
+ id_project,
485
+ undefined,
486
+ undefined,
487
+ assignmentContextUtil.buildInternalOptions('rules', 'auto')
488
+ ).catch((err) => {
481
489
  winston.error("Error runAction route: ", err);
482
490
  });
483
491
 
@@ -515,7 +523,12 @@ class RulesTrigger {
515
523
  winston.debug('runAction action id_project: ' + id_project);
516
524
 
517
525
  // reroute(request_id, id_project, nobot) {
518
- requestService.reroute(request_id, id_project).catch((err) => {
526
+ requestService.reroute(
527
+ request_id,
528
+ id_project,
529
+ undefined,
530
+ assignmentContextUtil.buildInternalOptions('rules', 'auto')
531
+ ).catch((err) => {
519
532
  winston.error("Error runAction on reroute", err);
520
533
  });
521
534
 
@@ -678,7 +691,12 @@ class RulesTrigger {
678
691
  winston.debug('runAction action id_project: ' + id_project);
679
692
 
680
693
  // addParticipantByRequestId(request_id, id_project, member) {
681
- requestService.addParticipantByRequestId(request_id, id_project, member).catch((err) => {
694
+ requestService.addParticipantByRequestId(
695
+ request_id,
696
+ id_project,
697
+ member,
698
+ assignmentContextUtil.buildInternalOptions('rules', 'manual_reassign')
699
+ ).catch((err) => {
682
700
  winston.error("(RulesTrigger) addParticipantByRequestId error", err);
683
701
  });
684
702
 
@@ -733,7 +751,12 @@ class RulesTrigger {
733
751
 
734
752
 
735
753
  // reroute(request_id, id_project, nobot) {
736
- requestService.reroute(request_id, id_project).then(function(request) {
754
+ requestService.reroute(
755
+ request_id,
756
+ id_project,
757
+ undefined,
758
+ assignmentContextUtil.buildInternalOptions('rules', 'auto')
759
+ ).then(function(request) {
737
760
 
738
761
  winston.verbose('request.department.bot.launch action reroute request_id: ' + request_id);
739
762
 
@@ -794,7 +817,12 @@ class RulesTrigger {
794
817
  var id_project = eventTrigger.event.id_project;
795
818
  winston.debug('runAction action id_project: ' + id_project);
796
819
 
797
- requestService.addParticipantByRequestId(request_id, id_project, member).then(function(request) {
820
+ requestService.addParticipantByRequestId(
821
+ request_id,
822
+ id_project,
823
+ member,
824
+ assignmentContextUtil.buildInternalOptions('rules', 'manual_reassign')
825
+ ).then(function(request) {
798
826
 
799
827
  winston.verbose('request.bot.launch action request_id: ' + request_id);
800
828