@tiledesk/tiledesk-server 2.10.52 → 2.10.54
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +7 -0
- package/app.js +0 -5
- package/jobs.js +0 -5
- package/models/kb_setting.js +8 -0
- package/package.json +2 -3
- package/routes/kb.js +14 -16
- package/routes/kbsettings.js +4 -4
- package/routes/openai.js +2 -2
- package/routes/webhook.js +134 -1
- package/services/QuoteManager.js +37 -10
- package/services/aiReindexService.js +151 -0
- package/services/{openaiService.js → aiService.js} +3 -3
- package/services/requestService.js +449 -435
- package/test/kbRoute.js +74 -2
- package/utils/jobs-worker-queue-manager/queueManagerClassV2.js +15 -21
@@ -277,8 +277,6 @@ class RequestService {
|
|
277
277
|
return that.routeInternal(request, departmentid, id_project, nobot).then( async function (routedRequest) {
|
278
278
|
|
279
279
|
winston.debug("after routeInternal", routedRequest);
|
280
|
-
// winston.info("requestBeforeRoute.participants " +requestBeforeRoute.request_id , requestBeforeRoute.participants);
|
281
|
-
// console.log("routedRequest.participants " +routedRequest.request_id , routedRequest.participants);
|
282
280
|
winston.debug("requestBeforeRoute.status:" + requestBeforeRoute.status);
|
283
281
|
winston.debug("routedRequest.status:" + routedRequest.status);
|
284
282
|
|
@@ -650,8 +648,12 @@ class RequestService {
|
|
650
648
|
isTestConversation = true;
|
651
649
|
}
|
652
650
|
else if (channel && (channel.name === 'voice-vxml')) {
|
653
|
-
winston.verbose("is a voice conversation --> skip quote availability check")
|
654
651
|
isVoiceConversation = true;
|
652
|
+
let available = await qm.checkQuote(project, request, 'voice_duration');
|
653
|
+
if (available === false) {
|
654
|
+
winston.info("Voice duration limits reached for project " + project._id);
|
655
|
+
return reject("Voice duration limits reached for project " + project._id);
|
656
|
+
}
|
655
657
|
}
|
656
658
|
else {
|
657
659
|
isStandardConversation = true;
|
@@ -775,562 +777,562 @@ class RequestService {
|
|
775
777
|
}
|
776
778
|
|
777
779
|
// DEPRECATED
|
778
|
-
async _create(request) {
|
780
|
+
// async _create(request) {
|
779
781
|
|
780
|
-
|
782
|
+
// var startDate = new Date();
|
781
783
|
|
782
|
-
|
783
|
-
|
784
|
-
|
784
|
+
// if (!request.createdAt) {
|
785
|
+
// request.createdAt = new Date();
|
786
|
+
// }
|
785
787
|
|
786
788
|
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
789
|
+
// var request_id = request.request_id;
|
790
|
+
// var project_user_id = request.project_user_id;
|
791
|
+
// var lead_id = request.lead_id;
|
792
|
+
// var id_project = request.id_project;
|
791
793
|
|
792
|
-
|
794
|
+
// var first_text = request.first_text;
|
793
795
|
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
796
|
+
// //removed for ticket
|
797
|
+
// // // lascia che sia nico a fare il replace...certo tu devi fare il test che tutto sia ok quindi dopo demo
|
798
|
+
// // var first_text;
|
799
|
+
// // if (request.first_text) { //first_text can be empty for type image
|
800
|
+
// // first_text = request.first_text.replace(/[\n\r]+/g, ' '); //replace new line with space
|
801
|
+
// // }
|
800
802
|
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
803
|
+
// var departmentid = request.departmentid;
|
804
|
+
// var sourcePage = request.sourcePage;
|
805
|
+
// var language = request.language;
|
806
|
+
// var userAgent = request.userAgent;
|
807
|
+
// var status = request.status;
|
808
|
+
// var createdBy = request.createdBy;
|
809
|
+
// var attributes = request.attributes;
|
810
|
+
// var subject = request.subject;
|
811
|
+
// var preflight = request.preflight;
|
812
|
+
// var channel = request.channel;
|
813
|
+
// var location = request.location;
|
814
|
+
// var participants = request.participants || [];
|
813
815
|
|
814
|
-
|
815
|
-
|
816
|
-
|
816
|
+
// var tags = request.tags;
|
817
|
+
// var notes = request.notes;
|
818
|
+
// var priority = request.priority;
|
817
819
|
|
818
|
-
|
820
|
+
// var auto_close = request.auto_close;
|
819
821
|
|
820
|
-
|
821
|
-
|
822
|
+
// var followers = request.followers;
|
823
|
+
// let createdAt = request.createdAt;
|
822
824
|
|
823
825
|
|
824
|
-
|
825
|
-
|
826
|
-
|
826
|
+
// if (!departmentid) {
|
827
|
+
// departmentid = 'default';
|
828
|
+
// }
|
827
829
|
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
830
|
+
// if (!createdBy) {
|
831
|
+
// if (project_user_id) {
|
832
|
+
// createdBy = project_user_id;
|
833
|
+
// } else {
|
834
|
+
// createdBy = "system";
|
835
|
+
// }
|
834
836
|
|
835
|
-
|
837
|
+
// }
|
836
838
|
|
837
|
-
|
838
|
-
|
839
|
+
// let isTestConversation = false;
|
840
|
+
// let isVoiceConversation = false;
|
839
841
|
|
840
|
-
|
842
|
+
// var that = this;
|
841
843
|
|
842
|
-
|
844
|
+
// return new Promise(async (resolve, reject) => {
|
843
845
|
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
846
|
+
// let q = Project.findOne({ _id: request.id_project, status: 100 });
|
847
|
+
// if (cacheEnabler.project) {
|
848
|
+
// q.cache(cacheUtil.longTTL, "projects:id:" + request.id_project) //project_cache
|
849
|
+
// winston.debug('project cache enabled for /project detail');
|
850
|
+
// }
|
851
|
+
// q.exec(async function (err, p) {
|
852
|
+
// if (err) {
|
853
|
+
// winston.error('Error getting project ', err);
|
854
|
+
// }
|
855
|
+
// if (!p) {
|
856
|
+
// winston.warn('Project not found ');
|
857
|
+
// }
|
856
858
|
|
857
859
|
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
860
|
+
// let payload = {
|
861
|
+
// project: p,
|
862
|
+
// request: request
|
863
|
+
// }
|
862
864
|
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
865
|
+
// if (attributes && attributes.sourcePage && (attributes.sourcePage.indexOf("td_draft=true") > -1)) {
|
866
|
+
// winston.verbose("is a test conversation --> skip quote availability check")
|
867
|
+
// isTestConversation = true;
|
868
|
+
// }
|
869
|
+
// else if (channel && (channel.name === 'voice-vxml')) {
|
870
|
+
// winston.verbose("is a voice conversation --> skip quote availability check")
|
871
|
+
// isVoiceConversation = true;
|
872
|
+
// }
|
873
|
+
// else {
|
874
|
+
// // console.log("! check quota moved")
|
875
|
+
// // let available = await qm.checkQuote(p, request, 'requests');
|
876
|
+
// // if (available === false) {
|
877
|
+
// // winston.info("Requests limits reached for project " + p._id)
|
878
|
+
// // return false;
|
879
|
+
// // }
|
880
|
+
// }
|
879
881
|
|
880
882
|
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
winston.debug("context", context);
|
892
|
-
|
893
|
-
var participantsAgents = [];
|
894
|
-
var participantsBots = [];
|
895
|
-
var hasBot = false;
|
896
|
-
|
897
|
-
var dep_id = undefined;
|
898
|
-
|
899
|
-
var assigned_at = undefined;
|
900
|
-
|
901
|
-
var agents = [];
|
883
|
+
// var context = {
|
884
|
+
// request: {
|
885
|
+
// request_id: request_id, project_user_id: project_user_id, lead_id: lead_id, id_project: id_project,
|
886
|
+
// first_text: first_text, departmentid: departmentid, sourcePage: sourcePage, language: language, userAgent: userAgent, status: status,
|
887
|
+
// createdBy: createdBy, attributes: attributes, subject: subject, preflight: preflight, channel: channel, location: location,
|
888
|
+
// participants: participants, tags: tags, notes: notes,
|
889
|
+
// priority: priority, auto_close: auto_close, followers: followers
|
890
|
+
// }
|
891
|
+
// };
|
902
892
|
|
903
|
-
|
893
|
+
// winston.debug("context", context);
|
904
894
|
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
// console.log("************* after get operator: "+new Date().toISOString());
|
895
|
+
// var participantsAgents = [];
|
896
|
+
// var participantsBots = [];
|
897
|
+
// var hasBot = false;
|
909
898
|
|
910
|
-
|
911
|
-
} catch (err) {
|
912
|
-
return reject(err);
|
913
|
-
}
|
899
|
+
// var dep_id = undefined;
|
914
900
|
|
901
|
+
// var assigned_at = undefined;
|
915
902
|
|
903
|
+
// var agents = [];
|
916
904
|
|
917
|
-
|
918
|
-
|
919
|
-
if (status == 50) {
|
920
|
-
// skip assignment
|
921
|
-
if (participants.length == 0) {
|
922
|
-
dep_id = result.department._id;
|
923
|
-
}
|
924
|
-
} else {
|
905
|
+
// var snapshot = {};
|
925
906
|
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
// for preflight it is important to save agents in req for trigger. try to optimize it
|
931
|
-
dep_id = result.department._id;
|
907
|
+
// try {
|
908
|
+
// // getOperators(departmentid, projectid, nobot, disableWebHookCall, context) {
|
909
|
+
// var result = await departmentService.getOperators(departmentid, id_project, false, undefined, context);
|
910
|
+
// // console.log("************* after get operator: "+new Date().toISOString());
|
932
911
|
|
933
|
-
|
912
|
+
// winston.debug("getOperators", result);
|
913
|
+
// } catch (err) {
|
914
|
+
// return reject(err);
|
915
|
+
// }
|
934
916
|
|
935
|
-
if (participants.length > 0) {
|
936
917
|
|
937
|
-
status = RequestConstants.ASSIGNED;
|
938
918
|
|
939
|
-
|
940
|
-
* QUOTAS - START!!!
|
941
|
-
*/
|
942
|
-
if (!isTestConversation && !isVoiceConversation) {
|
943
|
-
requestEvent.emit('request.create.quote', payload);
|
944
|
-
}
|
945
|
-
/**
|
946
|
-
* QUOTAS - END!!!
|
947
|
-
*/
|
919
|
+
// agents = result.agents;
|
948
920
|
|
921
|
+
// if (status == 50) {
|
922
|
+
// // skip assignment
|
923
|
+
// if (participants.length == 0) {
|
924
|
+
// dep_id = result.department._id;
|
925
|
+
// }
|
926
|
+
// } else {
|
949
927
|
|
928
|
+
// if (participants.length == 0) {
|
929
|
+
// if (result.operators && result.operators.length > 0) {
|
930
|
+
// participants.push(result.operators[0].id_user.toString());
|
931
|
+
// }
|
932
|
+
// // for preflight it is important to save agents in req for trigger. try to optimize it
|
933
|
+
// dep_id = result.department._id;
|
950
934
|
|
951
|
-
|
952
|
-
if (participants[0].startsWith("bot_")) {
|
953
|
-
|
954
|
-
hasBot = true;
|
955
|
-
winston.debug("hasBot:" + hasBot);
|
956
|
-
|
957
|
-
// botprefix
|
958
|
-
var assigned_operator_idStringBot = participants[0].replace("bot_", "");
|
959
|
-
winston.debug("assigned_operator_idStringBot:" + assigned_operator_idStringBot);
|
960
|
-
|
961
|
-
participantsBots.push(assigned_operator_idStringBot);
|
962
|
-
|
963
|
-
} else {
|
935
|
+
// }
|
964
936
|
|
965
|
-
|
937
|
+
// if (participants.length > 0) {
|
966
938
|
|
967
|
-
|
939
|
+
// status = RequestConstants.ASSIGNED;
|
968
940
|
|
969
|
-
|
941
|
+
// /**
|
942
|
+
// * QUOTAS - START!!!
|
943
|
+
// */
|
944
|
+
// if (!isTestConversation && !isVoiceConversation) {
|
945
|
+
// requestEvent.emit('request.create.quote', payload);
|
946
|
+
// }
|
947
|
+
// /**
|
948
|
+
// * QUOTAS - END!!!
|
949
|
+
// */
|
970
950
|
|
971
|
-
} else {
|
972
951
|
|
973
|
-
status = RequestConstants.UNASSIGNED;
|
974
952
|
|
975
|
-
|
953
|
+
// // botprefix
|
954
|
+
// if (participants[0].startsWith("bot_")) {
|
976
955
|
|
977
|
-
|
956
|
+
// hasBot = true;
|
957
|
+
// winston.debug("hasBot:" + hasBot);
|
978
958
|
|
959
|
+
// // botprefix
|
960
|
+
// var assigned_operator_idStringBot = participants[0].replace("bot_", "");
|
961
|
+
// winston.debug("assigned_operator_idStringBot:" + assigned_operator_idStringBot);
|
979
962
|
|
963
|
+
// participantsBots.push(assigned_operator_idStringBot);
|
980
964
|
|
965
|
+
// } else {
|
981
966
|
|
982
|
-
|
983
|
-
snapshot.department = result.department;
|
984
|
-
}
|
967
|
+
// participantsAgents.push(participants[0]);
|
985
968
|
|
986
|
-
|
987
|
-
snapshot.agents = agents;
|
988
|
-
snapshot.availableAgentsCount = that.getAvailableAgentsCount(agents);
|
969
|
+
// }
|
989
970
|
|
990
|
-
|
991
|
-
snapshot.requester = request.requester;
|
992
|
-
}
|
993
|
-
if (request.lead) {
|
994
|
-
snapshot.lead = request.lead;
|
995
|
-
}
|
971
|
+
// assigned_at = Date.now();
|
996
972
|
|
997
|
-
|
998
|
-
// winston.debug("req status", status);
|
973
|
+
// } else {
|
999
974
|
|
1000
|
-
|
1001
|
-
request_id: request_id,
|
1002
|
-
requester: project_user_id,
|
1003
|
-
lead: lead_id,
|
1004
|
-
first_text: first_text,
|
1005
|
-
subject: subject,
|
1006
|
-
status: status,
|
1007
|
-
participants: participants,
|
1008
|
-
participantsAgents: participantsAgents,
|
1009
|
-
participantsBots: participantsBots,
|
1010
|
-
hasBot: hasBot,
|
1011
|
-
department: dep_id,
|
1012
|
-
// agents: agents,
|
975
|
+
// status = RequestConstants.UNASSIGNED;
|
1013
976
|
|
1014
|
-
|
1015
|
-
sourcePage: sourcePage,
|
1016
|
-
language: language,
|
1017
|
-
userAgent: userAgent,
|
1018
|
-
assigned_at: assigned_at,
|
977
|
+
// }
|
1019
978
|
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
979
|
+
// }
|
980
|
+
|
981
|
+
|
982
|
+
|
983
|
+
|
984
|
+
// if (dep_id) {
|
985
|
+
// snapshot.department = result.department;
|
986
|
+
// }
|
987
|
+
|
988
|
+
// // console.log("result.agents",result.agents);
|
989
|
+
// snapshot.agents = agents;
|
990
|
+
// snapshot.availableAgentsCount = that.getAvailableAgentsCount(agents);
|
991
|
+
|
992
|
+
// if (request.requester) { //.toObject()????
|
993
|
+
// snapshot.requester = request.requester;
|
994
|
+
// }
|
995
|
+
// if (request.lead) {
|
996
|
+
// snapshot.lead = request.lead;
|
997
|
+
// }
|
998
|
+
|
999
|
+
// // winston.debug("assigned_operator_id", assigned_operator_id);
|
1000
|
+
// // winston.debug("req status", status);
|
1001
|
+
|
1002
|
+
// var newRequest = new Request({
|
1003
|
+
// request_id: request_id,
|
1004
|
+
// requester: project_user_id,
|
1005
|
+
// lead: lead_id,
|
1006
|
+
// first_text: first_text,
|
1007
|
+
// subject: subject,
|
1008
|
+
// status: status,
|
1009
|
+
// participants: participants,
|
1010
|
+
// participantsAgents: participantsAgents,
|
1011
|
+
// participantsBots: participantsBots,
|
1012
|
+
// hasBot: hasBot,
|
1013
|
+
// department: dep_id,
|
1014
|
+
// // agents: agents,
|
1015
|
+
|
1016
|
+
// //others
|
1017
|
+
// sourcePage: sourcePage,
|
1018
|
+
// language: language,
|
1019
|
+
// userAgent: userAgent,
|
1020
|
+
// assigned_at: assigned_at,
|
1021
|
+
|
1022
|
+
// attributes: attributes,
|
1023
|
+
// //standard
|
1024
|
+
// id_project: id_project,
|
1025
|
+
// createdBy: createdBy,
|
1026
|
+
// updatedBy: createdBy,
|
1027
|
+
// preflight: preflight,
|
1028
|
+
// channel: channel,
|
1029
|
+
// location: location,
|
1030
|
+
// snapshot: snapshot,
|
1031
|
+
// tags: tags,
|
1032
|
+
// notes: notes,
|
1033
|
+
// priority: priority,
|
1034
|
+
// auto_close: auto_close,
|
1035
|
+
// followers: followers,
|
1036
|
+
// createdAt: createdAt
|
1037
|
+
// });
|
1036
1038
|
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1039
|
+
// if (isTestConversation) {
|
1040
|
+
// newRequest.draft = true;
|
1041
|
+
// }
|
1040
1042
|
|
1041
|
-
|
1043
|
+
// winston.debug('newRequest.', newRequest);
|
1042
1044
|
|
1043
1045
|
|
1044
|
-
|
1045
|
-
|
1046
|
+
// //cacheinvalidation
|
1047
|
+
// return newRequest.save( async function (err, savedRequest) {
|
1046
1048
|
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1049
|
+
// if (err) {
|
1050
|
+
// winston.error('RequestService error for method createWithIdAndRequester for newRequest' + JSON.stringify(newRequest), err);
|
1051
|
+
// return reject(err);
|
1052
|
+
// }
|
1051
1053
|
|
1052
1054
|
|
1053
|
-
|
1055
|
+
// winston.debug("Request created", savedRequest.toObject());
|
1054
1056
|
|
1055
|
-
|
1056
|
-
|
1057
|
+
// var endDate = new Date();
|
1058
|
+
// winston.verbose("Performance Request created in millis: " + endDate - startDate);
|
1057
1059
|
|
1058
|
-
|
1060
|
+
// requestEvent.emit('request.create.simple', savedRequest);
|
1059
1061
|
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1062
|
+
// if (!isTestConversation && !isVoiceConversation) {
|
1063
|
+
// // requestEvent.emit('request.create.quote', payload);;
|
1064
|
+
// }
|
1063
1065
|
|
1064
|
-
|
1066
|
+
// return resolve(savedRequest);
|
1065
1067
|
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1068
|
+
// });
|
1069
|
+
// // }).catch(function(err){
|
1070
|
+
// // return reject(err);
|
1071
|
+
// // });
|
1070
1072
|
|
1071
|
-
|
1072
|
-
|
1073
|
+
// })
|
1074
|
+
// });
|
1073
1075
|
|
1074
|
-
}
|
1076
|
+
// }
|
1075
1077
|
|
1076
1078
|
// DEPRECATED
|
1077
|
-
async __create(request) {
|
1079
|
+
// async __create(request) {
|
1078
1080
|
|
1079
|
-
|
1081
|
+
// var startDate = new Date();
|
1080
1082
|
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1083
|
+
// if (!request.createdAt) {
|
1084
|
+
// request.createdAt = new Date();
|
1085
|
+
// }
|
1084
1086
|
|
1085
1087
|
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
var first_text = request.first_text;
|
1092
|
-
|
1093
|
-
//removed for ticket
|
1094
|
-
// // lascia che sia nico a fare il replace...certo tu devi fare il test che tutto sia ok quindi dopo demo
|
1095
|
-
// var first_text;
|
1096
|
-
// if (request.first_text) { //first_text can be empty for type image
|
1097
|
-
// first_text = request.first_text.replace(/[\n\r]+/g, ' '); //replace new line with space
|
1098
|
-
// }
|
1099
|
-
|
1100
|
-
var departmentid = request.departmentid;
|
1101
|
-
var sourcePage = request.sourcePage;
|
1102
|
-
var language = request.language;
|
1103
|
-
var userAgent = request.userAgent;
|
1104
|
-
var status = request.status;
|
1105
|
-
var createdBy = request.createdBy;
|
1106
|
-
var attributes = request.attributes;
|
1107
|
-
var subject = request.subject;
|
1108
|
-
var preflight = request.preflight;
|
1109
|
-
var channel = request.channel;
|
1110
|
-
var location = request.location;
|
1111
|
-
var participants = request.participants || [];
|
1112
|
-
|
1113
|
-
var tags = request.tags;
|
1114
|
-
var notes = request.notes;
|
1115
|
-
var priority = request.priority;
|
1116
|
-
|
1117
|
-
var auto_close = request.auto_close;
|
1118
|
-
|
1119
|
-
var followers = request.followers;
|
1120
|
-
let createdAt = request.createdAt;
|
1121
|
-
|
1122
|
-
if (!departmentid) {
|
1123
|
-
departmentid = 'default';
|
1124
|
-
}
|
1125
|
-
|
1126
|
-
if (!createdBy) {
|
1127
|
-
if (project_user_id) {
|
1128
|
-
createdBy = project_user_id;
|
1129
|
-
} else {
|
1130
|
-
createdBy = "system";
|
1131
|
-
}
|
1088
|
+
// var request_id = request.request_id;
|
1089
|
+
// var project_user_id = request.project_user_id;
|
1090
|
+
// var lead_id = request.lead_id;
|
1091
|
+
// var id_project = request.id_project;
|
1132
1092
|
|
1133
|
-
|
1093
|
+
// var first_text = request.first_text;
|
1134
1094
|
|
1135
|
-
|
1095
|
+
// //removed for ticket
|
1096
|
+
// // // lascia che sia nico a fare il replace...certo tu devi fare il test che tutto sia ok quindi dopo demo
|
1097
|
+
// // var first_text;
|
1098
|
+
// // if (request.first_text) { //first_text can be empty for type image
|
1099
|
+
// // first_text = request.first_text.replace(/[\n\r]+/g, ' '); //replace new line with space
|
1100
|
+
// // }
|
1136
1101
|
|
1137
|
-
|
1102
|
+
// var departmentid = request.departmentid;
|
1103
|
+
// var sourcePage = request.sourcePage;
|
1104
|
+
// var language = request.language;
|
1105
|
+
// var userAgent = request.userAgent;
|
1106
|
+
// var status = request.status;
|
1107
|
+
// var createdBy = request.createdBy;
|
1108
|
+
// var attributes = request.attributes;
|
1109
|
+
// var subject = request.subject;
|
1110
|
+
// var preflight = request.preflight;
|
1111
|
+
// var channel = request.channel;
|
1112
|
+
// var location = request.location;
|
1113
|
+
// var participants = request.participants || [];
|
1138
1114
|
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
first_text: first_text, departmentid: departmentid, sourcePage: sourcePage, language: language, userAgent: userAgent, status: status,
|
1143
|
-
createdBy: createdBy, attributes: attributes, subject: subject, preflight: preflight, channel: channel, location: location,
|
1144
|
-
participants: participants, tags: tags, notes: notes,
|
1145
|
-
priority: priority, auto_close: auto_close, followers: followers
|
1146
|
-
}
|
1147
|
-
};
|
1115
|
+
// var tags = request.tags;
|
1116
|
+
// var notes = request.notes;
|
1117
|
+
// var priority = request.priority;
|
1148
1118
|
|
1149
|
-
|
1119
|
+
// var auto_close = request.auto_close;
|
1150
1120
|
|
1151
|
-
|
1152
|
-
|
1153
|
-
var hasBot = false;
|
1121
|
+
// var followers = request.followers;
|
1122
|
+
// let createdAt = request.createdAt;
|
1154
1123
|
|
1155
|
-
|
1124
|
+
// if (!departmentid) {
|
1125
|
+
// departmentid = 'default';
|
1126
|
+
// }
|
1156
1127
|
|
1157
|
-
|
1128
|
+
// if (!createdBy) {
|
1129
|
+
// if (project_user_id) {
|
1130
|
+
// createdBy = project_user_id;
|
1131
|
+
// } else {
|
1132
|
+
// createdBy = "system";
|
1133
|
+
// }
|
1158
1134
|
|
1159
|
-
|
1135
|
+
// }
|
1160
1136
|
|
1161
|
-
|
1137
|
+
// var that = this;
|
1162
1138
|
|
1163
|
-
|
1164
|
-
// getOperators(departmentid, projectid, nobot, disableWebHookCall, context) {
|
1165
|
-
var result = await departmentService.getOperators(departmentid, id_project, false, undefined, context);
|
1166
|
-
// console.log("************* after get operator: "+new Date().toISOString());
|
1139
|
+
// return new Promise(async (resolve, reject) => {
|
1167
1140
|
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1141
|
+
// var context = {
|
1142
|
+
// request: {
|
1143
|
+
// request_id: request_id, project_user_id: project_user_id, lead_id: lead_id, id_project: id_project,
|
1144
|
+
// first_text: first_text, departmentid: departmentid, sourcePage: sourcePage, language: language, userAgent: userAgent, status: status,
|
1145
|
+
// createdBy: createdBy, attributes: attributes, subject: subject, preflight: preflight, channel: channel, location: location,
|
1146
|
+
// participants: participants, tags: tags, notes: notes,
|
1147
|
+
// priority: priority, auto_close: auto_close, followers: followers
|
1148
|
+
// }
|
1149
|
+
// };
|
1172
1150
|
|
1151
|
+
// winston.debug("context", context);
|
1173
1152
|
|
1153
|
+
// var participantsAgents = [];
|
1154
|
+
// var participantsBots = [];
|
1155
|
+
// var hasBot = false;
|
1174
1156
|
|
1175
|
-
|
1157
|
+
// var dep_id = undefined;
|
1176
1158
|
|
1177
|
-
|
1178
|
-
// skip assignment
|
1179
|
-
if (participants.length == 0) {
|
1180
|
-
dep_id = result.department._id;
|
1181
|
-
}
|
1182
|
-
} else {
|
1159
|
+
// var assigned_at = undefined;
|
1183
1160
|
|
1184
|
-
|
1185
|
-
if (result.operators && result.operators.length > 0) {
|
1186
|
-
participants.push(result.operators[0].id_user.toString());
|
1187
|
-
}
|
1188
|
-
// for preflight it is important to save agents in req for trigger. try to optimize it
|
1189
|
-
dep_id = result.department._id;
|
1161
|
+
// var agents = [];
|
1190
1162
|
|
1191
|
-
|
1163
|
+
// var snapshot = {};
|
1192
1164
|
|
1193
|
-
|
1165
|
+
// try {
|
1166
|
+
// // getOperators(departmentid, projectid, nobot, disableWebHookCall, context) {
|
1167
|
+
// var result = await departmentService.getOperators(departmentid, id_project, false, undefined, context);
|
1168
|
+
// // console.log("************* after get operator: "+new Date().toISOString());
|
1194
1169
|
|
1195
|
-
|
1170
|
+
// winston.debug("getOperators", result);
|
1171
|
+
// } catch (err) {
|
1172
|
+
// return reject(err);
|
1173
|
+
// }
|
1196
1174
|
|
1197
|
-
// botprefix
|
1198
|
-
if (participants[0].startsWith("bot_")) {
|
1199
1175
|
|
1200
|
-
hasBot = true;
|
1201
|
-
winston.debug("hasBot:" + hasBot);
|
1202
1176
|
|
1203
|
-
|
1204
|
-
var assigned_operator_idStringBot = participants[0].replace("bot_", "");
|
1205
|
-
winston.debug("assigned_operator_idStringBot:" + assigned_operator_idStringBot);
|
1177
|
+
// agents = result.agents;
|
1206
1178
|
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
}
|
1214
|
-
|
1215
|
-
assigned_at = Date.now();
|
1179
|
+
// if (status == 50) {
|
1180
|
+
// // skip assignment
|
1181
|
+
// if (participants.length == 0) {
|
1182
|
+
// dep_id = result.department._id;
|
1183
|
+
// }
|
1184
|
+
// } else {
|
1216
1185
|
|
1217
|
-
|
1186
|
+
// if (participants.length == 0) {
|
1187
|
+
// if (result.operators && result.operators.length > 0) {
|
1188
|
+
// participants.push(result.operators[0].id_user.toString());
|
1189
|
+
// }
|
1190
|
+
// // for preflight it is important to save agents in req for trigger. try to optimize it
|
1191
|
+
// dep_id = result.department._id;
|
1218
1192
|
|
1219
|
-
|
1193
|
+
// }
|
1220
1194
|
|
1221
|
-
|
1195
|
+
// if (participants.length > 0) {
|
1222
1196
|
|
1223
|
-
|
1197
|
+
// status = RequestConstants.ASSIGNED;
|
1224
1198
|
|
1199
|
+
// // botprefix
|
1200
|
+
// if (participants[0].startsWith("bot_")) {
|
1225
1201
|
|
1202
|
+
// hasBot = true;
|
1203
|
+
// winston.debug("hasBot:" + hasBot);
|
1226
1204
|
|
1205
|
+
// // botprefix
|
1206
|
+
// var assigned_operator_idStringBot = participants[0].replace("bot_", "");
|
1207
|
+
// winston.debug("assigned_operator_idStringBot:" + assigned_operator_idStringBot);
|
1227
1208
|
|
1228
|
-
|
1229
|
-
snapshot.department = result.department;
|
1230
|
-
}
|
1231
|
-
|
1232
|
-
// console.log("result.agents",result.agents);
|
1233
|
-
snapshot.agents = agents;
|
1234
|
-
snapshot.availableAgentsCount = that.getAvailableAgentsCount(agents);
|
1209
|
+
// participantsBots.push(assigned_operator_idStringBot);
|
1235
1210
|
|
1236
|
-
|
1237
|
-
snapshot.requester = request.requester;
|
1238
|
-
}
|
1239
|
-
if (request.lead) {
|
1240
|
-
snapshot.lead = request.lead;
|
1241
|
-
}
|
1211
|
+
// } else {
|
1242
1212
|
|
1243
|
-
|
1244
|
-
// winston.debug("req status", status);
|
1213
|
+
// participantsAgents.push(participants[0]);
|
1245
1214
|
|
1246
|
-
|
1247
|
-
request_id: request_id,
|
1248
|
-
requester: project_user_id,
|
1249
|
-
lead: lead_id,
|
1250
|
-
first_text: first_text,
|
1251
|
-
subject: subject,
|
1252
|
-
status: status,
|
1253
|
-
participants: participants,
|
1254
|
-
participantsAgents: participantsAgents,
|
1255
|
-
participantsBots: participantsBots,
|
1256
|
-
hasBot: hasBot,
|
1257
|
-
department: dep_id,
|
1258
|
-
// agents: agents,
|
1259
|
-
|
1260
|
-
//others
|
1261
|
-
sourcePage: sourcePage,
|
1262
|
-
language: language,
|
1263
|
-
userAgent: userAgent,
|
1264
|
-
assigned_at: assigned_at,
|
1215
|
+
// }
|
1265
1216
|
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1217
|
+
// assigned_at = Date.now();
|
1218
|
+
|
1219
|
+
// } else {
|
1220
|
+
|
1221
|
+
// status = RequestConstants.UNASSIGNED;
|
1222
|
+
|
1223
|
+
// }
|
1224
|
+
|
1225
|
+
// }
|
1226
|
+
|
1227
|
+
|
1228
|
+
|
1229
|
+
|
1230
|
+
// if (dep_id) {
|
1231
|
+
// snapshot.department = result.department;
|
1232
|
+
// }
|
1233
|
+
|
1234
|
+
// // console.log("result.agents",result.agents);
|
1235
|
+
// snapshot.agents = agents;
|
1236
|
+
// snapshot.availableAgentsCount = that.getAvailableAgentsCount(agents);
|
1237
|
+
|
1238
|
+
// if (request.requester) { //.toObject()????
|
1239
|
+
// snapshot.requester = request.requester;
|
1240
|
+
// }
|
1241
|
+
// if (request.lead) {
|
1242
|
+
// snapshot.lead = request.lead;
|
1243
|
+
// }
|
1244
|
+
|
1245
|
+
// // winston.debug("assigned_operator_id", assigned_operator_id);
|
1246
|
+
// // winston.debug("req status", status);
|
1247
|
+
|
1248
|
+
// var newRequest = new Request({
|
1249
|
+
// request_id: request_id,
|
1250
|
+
// requester: project_user_id,
|
1251
|
+
// lead: lead_id,
|
1252
|
+
// first_text: first_text,
|
1253
|
+
// subject: subject,
|
1254
|
+
// status: status,
|
1255
|
+
// participants: participants,
|
1256
|
+
// participantsAgents: participantsAgents,
|
1257
|
+
// participantsBots: participantsBots,
|
1258
|
+
// hasBot: hasBot,
|
1259
|
+
// department: dep_id,
|
1260
|
+
// // agents: agents,
|
1261
|
+
|
1262
|
+
// //others
|
1263
|
+
// sourcePage: sourcePage,
|
1264
|
+
// language: language,
|
1265
|
+
// userAgent: userAgent,
|
1266
|
+
// assigned_at: assigned_at,
|
1267
|
+
|
1268
|
+
// attributes: attributes,
|
1269
|
+
// //standard
|
1270
|
+
// id_project: id_project,
|
1271
|
+
// createdBy: createdBy,
|
1272
|
+
// updatedBy: createdBy,
|
1273
|
+
// preflight: preflight,
|
1274
|
+
// channel: channel,
|
1275
|
+
// location: location,
|
1276
|
+
// snapshot: snapshot,
|
1277
|
+
// tags: tags,
|
1278
|
+
// notes: notes,
|
1279
|
+
// priority: priority,
|
1280
|
+
// auto_close: auto_close,
|
1281
|
+
// followers: followers,
|
1282
|
+
// createdAt: createdAt
|
1283
|
+
// });
|
1282
1284
|
|
1283
|
-
|
1285
|
+
// winston.debug('newRequest.', newRequest);
|
1284
1286
|
|
1285
1287
|
|
1286
|
-
|
1287
|
-
|
1288
|
+
// //cacheinvalidation
|
1289
|
+
// return newRequest.save(function (err, savedRequest) {
|
1288
1290
|
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1291
|
+
// if (err) {
|
1292
|
+
// winston.error('RequestService error for method createWithIdAndRequester for newRequest' + JSON.stringify(newRequest), err);
|
1293
|
+
// return reject(err);
|
1294
|
+
// }
|
1293
1295
|
|
1294
1296
|
|
1295
|
-
|
1297
|
+
// winston.debug("Request created", savedRequest.toObject());
|
1296
1298
|
|
1297
|
-
|
1298
|
-
|
1299
|
+
// var endDate = new Date();
|
1300
|
+
// winston.verbose("Performance Request created in millis: " + endDate - startDate);
|
1299
1301
|
|
1300
|
-
|
1302
|
+
// requestEvent.emit('request.create.simple', savedRequest);
|
1301
1303
|
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1304
|
+
// let q = Project.findOne({ _id: request.id_project, status: 100 });
|
1305
|
+
// if (cacheEnabler.project) {
|
1306
|
+
// q.cache(cacheUtil.longTTL, "projects:id:" + request.id_project) //project_cache
|
1307
|
+
// winston.debug('project cache enabled for /project detail');
|
1308
|
+
// }
|
1309
|
+
// q.exec(async function (err, p) {
|
1310
|
+
// if (err) {
|
1311
|
+
// winston.error('Error getting project ', err);
|
1312
|
+
// }
|
1313
|
+
// if (!p) {
|
1314
|
+
// winston.warn('Project not found ');
|
1315
|
+
// }
|
1316
|
+
// //TODO REMOVE settings from project
|
1317
|
+
// let payload = {
|
1318
|
+
// project: p,
|
1319
|
+
// request: request
|
1320
|
+
// }
|
1319
1321
|
|
1320
|
-
|
1322
|
+
// requestEvent.emit('request.create.quote', payload);;
|
1321
1323
|
|
1322
|
-
|
1324
|
+
// });
|
1323
1325
|
|
1324
|
-
|
1326
|
+
// return resolve(savedRequest);
|
1325
1327
|
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1328
|
+
// });
|
1329
|
+
// // }).catch(function(err){
|
1330
|
+
// // return reject(err);
|
1331
|
+
// // });
|
1330
1332
|
|
1331
1333
|
|
1332
|
-
|
1333
|
-
}
|
1334
|
+
// });
|
1335
|
+
// }
|
1334
1336
|
|
1335
1337
|
|
1336
1338
|
|
@@ -1612,12 +1614,24 @@ class RequestService {
|
|
1612
1614
|
.populate('participatingBots')
|
1613
1615
|
.populate('participatingAgents')
|
1614
1616
|
.populate({ path: 'requester', populate: { path: 'id_user' } })
|
1615
|
-
.exec(function (err, updatedRequest) {
|
1617
|
+
.exec( async function (err, updatedRequest) {
|
1616
1618
|
if (err) {
|
1617
1619
|
winston.error(err);
|
1618
1620
|
return reject(err);
|
1619
1621
|
}
|
1620
1622
|
|
1623
|
+
let project = await projectService.getCachedProject(id_project).catch((err) => {
|
1624
|
+
winston.warn("Error getting cached project. Skip conversation quota check.")
|
1625
|
+
winston.warn("Getting cached project error: ", err)
|
1626
|
+
})
|
1627
|
+
|
1628
|
+
let payload = {
|
1629
|
+
project: project,
|
1630
|
+
request: updatedRequest
|
1631
|
+
}
|
1632
|
+
if (updatedRequest.channel.name === 'voice-vxml') {
|
1633
|
+
requestEvent.emit('request.close.quote', payload);
|
1634
|
+
}
|
1621
1635
|
// winston.debug("updatedRequest", updatedRequest);
|
1622
1636
|
return resolve(updatedRequest);
|
1623
1637
|
});
|