@tiledesk/tiledesk-server 2.2.39 → 2.3.3
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +24 -0
- package/LICENSE +14 -657
- package/README.md +17 -3
- package/app.js +14 -2
- package/channels/chat21/chat21WebHook.js +12 -1
- package/event/botEvent.js +1 -1
- package/event/subscriptionEvent.js +11 -0
- package/fonts/Roboto-Italic.ttf +0 -0
- package/fonts/Roboto-Medium.ttf +0 -0
- package/fonts/Roboto-MediumItalic.ttf +0 -0
- package/fonts/Roboto-Regular.ttf +0 -0
- package/middleware/passport.js +4 -1
- package/models/lead.js +2 -0
- package/models/request.js +38 -11
- package/models/subscriptionLog.js +34 -0
- package/models/tagLibrary.js +42 -0
- package/package.json +4 -11
- package/pubmodules/activities/activityArchiver.js +295 -0
- package/pubmodules/activities/index.js +3 -0
- package/pubmodules/activities/models/activity.js +88 -0
- package/pubmodules/activities/routes/activity.js +710 -0
- package/pubmodules/activities/test/activityRoute.js +85 -0
- package/pubmodules/analytics/analytics.js +1719 -0
- package/pubmodules/analytics/index.js +3 -0
- package/pubmodules/canned/cannedResponse.js +51 -0
- package/pubmodules/canned/cannedResponseRoute.js +157 -0
- package/pubmodules/canned/index.js +3 -0
- package/pubmodules/emailNotification/requestNotification.js +184 -26
- package/pubmodules/messageActions/messageActionsInterceptor.js +4 -2
- package/pubmodules/pubModulesManager.js +104 -5
- package/pubmodules/scheduler/tasks/closeAgentUnresponsiveRequestTask.js +3 -1
- package/pubmodules/scheduler/tasks/closeBotUnresponsiveRequestTask.js +3 -1
- package/pubmodules/trigger/default.js +271 -0
- package/pubmodules/trigger/event/actionEventEmitter.js +10 -0
- package/pubmodules/trigger/event/flowEventEmitter.js +10 -0
- package/pubmodules/trigger/event/triggerEventEmitter.js +10 -0
- package/pubmodules/trigger/index.js +3 -0
- package/pubmodules/trigger/models/trigger.js +149 -0
- package/pubmodules/trigger/rulesTrigger.js +1181 -0
- package/pubmodules/trigger/start.js +114 -0
- package/pubmodules/trigger/triggerRoute.js +150 -0
- package/routes/department.js +51 -0
- package/routes/group.js +140 -0
- package/routes/lead.js +24 -1
- package/routes/message.js +6 -3
- package/routes/project.js +52 -0
- package/routes/public-request.js +265 -2
- package/routes/request.js +83 -11
- package/routes/subscription.js +140 -0
- package/routes/tag.js +138 -0
- package/routes/user-request.js +3 -2
- package/routes/widget.js +16 -1
- package/routes/widgetLoader.js +31 -0
- package/services/emailService.js +189 -11
- package/services/faqService.js +1 -1
- package/services/leadService.js +2 -0
- package/services/modulesManager.js +7 -188
- package/services/requestService.js +364 -6
- package/services/subscriptionNotifier.js +485 -0
- package/template/email/assignedEmailMessage.html +1 -1
- package/template/email/assignedRequest.html +1 -1
- package/template/email/newMessage.html +1 -1
- package/template/email/newMessageFollower.html +236 -0
- package/template/email/passwordChanged.html +1 -1
- package/template/email/pooledEmailMessage.html +1 -1
- package/template/email/pooledRequest.html +1 -1
- package/template/email/resetPassword.html +2 -2
- package/template/email/ticket.html +1 -1
- package/test/messageRoute.js +69 -0
- package/test/requestService.js +3 -1
- package/views/messages.jade +2 -2
@@ -21,6 +21,7 @@ class RequestService {
|
|
21
21
|
|
22
22
|
listen() {
|
23
23
|
this.updateSnapshotLead();
|
24
|
+
this.sendMessageUpdateLead();
|
24
25
|
}
|
25
26
|
updateSnapshotLead() {
|
26
27
|
leadEvent.on('lead.update', function(lead) {
|
@@ -58,6 +59,62 @@ class RequestService {
|
|
58
59
|
});
|
59
60
|
});
|
60
61
|
}
|
62
|
+
|
63
|
+
|
64
|
+
sendMessageUpdateLead() {
|
65
|
+
leadEvent.on('lead.fullname.update', function(lead) {
|
66
|
+
// leadEvent.on('lead.update', function(lead) {
|
67
|
+
|
68
|
+
setImmediate(() => {
|
69
|
+
winston.debug("sendMessageUpdateLead on lead.update ", lead);
|
70
|
+
|
71
|
+
Request.find({lead: lead._id, id_project: lead.id_project}, function(err, requests) {
|
72
|
+
|
73
|
+
if (err) {
|
74
|
+
winston.error("Error getting sendMessageUpdateLead request by lead", err);
|
75
|
+
return 0;
|
76
|
+
}
|
77
|
+
if (!requests || (requests && requests.length==0)) {
|
78
|
+
winston.warn("sendMessageUpdateLead No request found for lead id " +lead._id );
|
79
|
+
return 0;
|
80
|
+
}
|
81
|
+
|
82
|
+
// winston.info("sendMessageUpdateLead requests ", requests);
|
83
|
+
|
84
|
+
requests.forEach(function(request) {
|
85
|
+
|
86
|
+
winston.debug("sendMessageUpdateLead request ", request);
|
87
|
+
|
88
|
+
// send(sender, senderFullname, recipient, text, id_project, createdBy, attributes, type, metadata, language)
|
89
|
+
messageService.send(
|
90
|
+
'system',
|
91
|
+
'Bot',
|
92
|
+
// lead.fullname,
|
93
|
+
request.request_id,
|
94
|
+
"Lead updated",
|
95
|
+
request.id_project,
|
96
|
+
'system',
|
97
|
+
{
|
98
|
+
subtype:"info/support",
|
99
|
+
"updateconversation" : false,
|
100
|
+
messagelabel: {key: "LEAD_UPDATED"},
|
101
|
+
updateUserEmail: lead.email,
|
102
|
+
updateUserFullname: lead.fullname
|
103
|
+
},
|
104
|
+
undefined,
|
105
|
+
request.language
|
106
|
+
|
107
|
+
);
|
108
|
+
|
109
|
+
});
|
110
|
+
|
111
|
+
});
|
112
|
+
|
113
|
+
});
|
114
|
+
});
|
115
|
+
}
|
116
|
+
|
117
|
+
|
61
118
|
getAvailableAgentsCount(agents) {
|
62
119
|
|
63
120
|
var project_users_available = agents.filter(function (projectUser) {
|
@@ -142,6 +199,7 @@ class RequestService {
|
|
142
199
|
request.snapshot = {}
|
143
200
|
}
|
144
201
|
|
202
|
+
|
145
203
|
request.snapshot.department = result.department;
|
146
204
|
request.snapshot.agents = result.agents;
|
147
205
|
request.snapshot.availableAgentsCount = that.getAvailableAgentsCount(result.agents);
|
@@ -400,6 +458,10 @@ class RequestService {
|
|
400
458
|
var notes = request.notes;
|
401
459
|
var priority = request.priority;
|
402
460
|
|
461
|
+
var auto_close = request.auto_close;
|
462
|
+
|
463
|
+
var followers = request.followers;
|
464
|
+
|
403
465
|
if (!departmentid) {
|
404
466
|
departmentid ='default';
|
405
467
|
}
|
@@ -421,7 +483,7 @@ class RequestService {
|
|
421
483
|
first_text:first_text, departmentid:departmentid, sourcePage:sourcePage, language:language, userAgent:userAgent, status:status,
|
422
484
|
createdBy:createdBy, attributes:attributes, subject:subject, preflight: preflight, channel: channel, location: location,
|
423
485
|
participants:participants, tags: tags, notes:notes,
|
424
|
-
priority: priority}};
|
486
|
+
priority: priority, auto_close: auto_close, followers: followers}};
|
425
487
|
|
426
488
|
winston.debug("context",context);
|
427
489
|
|
@@ -505,6 +567,7 @@ class RequestService {
|
|
505
567
|
snapshot.department = result.department;
|
506
568
|
}
|
507
569
|
|
570
|
+
// console.log("result.agents",result.agents);
|
508
571
|
snapshot.agents = agents;
|
509
572
|
snapshot.availableAgentsCount = that.getAvailableAgentsCount(agents);
|
510
573
|
|
@@ -549,7 +612,9 @@ class RequestService {
|
|
549
612
|
snapshot: snapshot,
|
550
613
|
tags: tags,
|
551
614
|
notes: notes,
|
552
|
-
priority: priority
|
615
|
+
priority: priority,
|
616
|
+
auto_close: auto_close,
|
617
|
+
followers: followers
|
553
618
|
});
|
554
619
|
|
555
620
|
|
@@ -842,14 +907,14 @@ class RequestService {
|
|
842
907
|
|
843
908
|
}
|
844
909
|
|
845
|
-
setClosedAtByRequestId(request_id, id_project, closed_at) {
|
910
|
+
setClosedAtByRequestId(request_id, id_project, closed_at, closed_by) {
|
846
911
|
|
847
912
|
return new Promise(function (resolve, reject) {
|
848
913
|
// winston.debug("request_id", request_id);
|
849
914
|
// winston.debug("newstatus", newstatus);
|
850
915
|
|
851
916
|
return Request
|
852
|
-
.findOneAndUpdate({request_id: request_id, id_project: id_project}, {closed_at: closed_at}, {new: true, upsert:false})
|
917
|
+
.findOneAndUpdate({request_id: request_id, id_project: id_project}, {closed_at: closed_at, closed_by: closed_by}, {new: true, upsert:false})
|
853
918
|
.populate('lead')
|
854
919
|
.populate('department')
|
855
920
|
.populate('participatingBots')
|
@@ -934,7 +999,7 @@ class RequestService {
|
|
934
999
|
}
|
935
1000
|
|
936
1001
|
|
937
|
-
closeRequestByRequestId(request_id, id_project, skipStatsUpdate, notify) {
|
1002
|
+
closeRequestByRequestId(request_id, id_project, skipStatsUpdate, notify, closed_by) {
|
938
1003
|
|
939
1004
|
var that = this;
|
940
1005
|
return new Promise(function (resolve, reject) {
|
@@ -991,7 +1056,8 @@ class RequestService {
|
|
991
1056
|
return resolve(updatedRequest);
|
992
1057
|
}
|
993
1058
|
|
994
|
-
|
1059
|
+
// setClosedAtByRequestId(request_id, id_project, closed_at, closed_by)
|
1060
|
+
return that.setClosedAtByRequestId(request_id, id_project, new Date().getTime(), closed_by).then(function(updatedRequest) {
|
995
1061
|
|
996
1062
|
winston.verbose("Request closed with id: " + updatedRequest.id);
|
997
1063
|
winston.debug("Request closed ", updatedRequest);
|
@@ -1728,6 +1794,298 @@ class RequestService {
|
|
1728
1794
|
|
1729
1795
|
|
1730
1796
|
|
1797
|
+
|
1798
|
+
|
1799
|
+
|
1800
|
+
|
1801
|
+
addFollowerByRequestId(request_id, id_project, member) {
|
1802
|
+
winston.debug("request_id: " + request_id);
|
1803
|
+
winston.debug("id_project: " + id_project);
|
1804
|
+
winston.debug("addFollowerByRequestId member: " + member);
|
1805
|
+
|
1806
|
+
|
1807
|
+
|
1808
|
+
//TODO control if member is a valid project_user of the project
|
1809
|
+
// validate member is string
|
1810
|
+
return new Promise(function (resolve, reject) {
|
1811
|
+
|
1812
|
+
if (member==undefined) {
|
1813
|
+
var err = "addFollowerByRequestId error, member field is null";
|
1814
|
+
winston.error(err);
|
1815
|
+
return reject(err);
|
1816
|
+
}
|
1817
|
+
|
1818
|
+
return Request
|
1819
|
+
.findOne({request_id: request_id, id_project: id_project})
|
1820
|
+
// qui cache
|
1821
|
+
.exec( function(err, request) {
|
1822
|
+
if (err){
|
1823
|
+
winston.error("Error adding follower ", err);
|
1824
|
+
return reject(err);
|
1825
|
+
}
|
1826
|
+
if (!request) {
|
1827
|
+
winston.error('Request not found for request_id '+ request_id + ' and id_project '+ id_project);
|
1828
|
+
return reject('Request not found for request_id '+ request_id + ' and id_project '+ id_project);
|
1829
|
+
}
|
1830
|
+
|
1831
|
+
winston.debug("assigned_operator here1");
|
1832
|
+
|
1833
|
+
// return Request.findById(id).then(function (request) {
|
1834
|
+
if (request.followers.indexOf(member)==-1){
|
1835
|
+
request.followers.push(member);
|
1836
|
+
|
1837
|
+
request.save(function(err, savedRequest) {
|
1838
|
+
if (err) {
|
1839
|
+
winston.error(err);
|
1840
|
+
return reject(err);
|
1841
|
+
}
|
1842
|
+
|
1843
|
+
winston.debug("saved", savedRequest);
|
1844
|
+
|
1845
|
+
return savedRequest
|
1846
|
+
.populate('lead')
|
1847
|
+
.populate('department')
|
1848
|
+
.populate('participatingBots')
|
1849
|
+
.populate('participatingAgents')
|
1850
|
+
// .populate('followers')
|
1851
|
+
.populate({path:'requester',populate:{path:'id_user'}})
|
1852
|
+
.execPopulate( function(err, requestComplete) {
|
1853
|
+
|
1854
|
+
if (err) {
|
1855
|
+
winston.error("Error getting addFollowerByRequestId", err);
|
1856
|
+
return reject(err);
|
1857
|
+
}
|
1858
|
+
|
1859
|
+
|
1860
|
+
winston.debug("populated", requestComplete);
|
1861
|
+
|
1862
|
+
requestEvent.emit('request.update', requestComplete);
|
1863
|
+
requestEvent.emit("request.update.comment", {comment:"FOLLOWER_ADD",request:requestComplete});//Deprecated
|
1864
|
+
requestEvent.emit("request.updated", {comment:"FOLLOWER_ADD",request:requestComplete, patch: {member:member}});
|
1865
|
+
requestEvent.emit('request.followers.join', {member:member, request: requestComplete});
|
1866
|
+
|
1867
|
+
return resolve(requestComplete);
|
1868
|
+
});
|
1869
|
+
});
|
1870
|
+
// qui assignetat
|
1871
|
+
} else {
|
1872
|
+
winston.debug('Request member '+ member+ ' already added for request_id '+ request_id + ' and id_project '+ id_project);
|
1873
|
+
return request
|
1874
|
+
.populate('lead')
|
1875
|
+
.populate('department')
|
1876
|
+
.populate('participatingBots')
|
1877
|
+
.populate('participatingAgents')
|
1878
|
+
// .populate('followers')
|
1879
|
+
.populate({path:'requester',populate:{path:'id_user'}})
|
1880
|
+
.execPopulate( function(err, requestComplete) {
|
1881
|
+
return resolve(requestComplete);
|
1882
|
+
});
|
1883
|
+
}
|
1884
|
+
|
1885
|
+
});
|
1886
|
+
});
|
1887
|
+
}
|
1888
|
+
|
1889
|
+
|
1890
|
+
|
1891
|
+
|
1892
|
+
|
1893
|
+
setFollowersByRequestId(request_id, id_project, newfollowers) {
|
1894
|
+
|
1895
|
+
//TODO validate participants
|
1896
|
+
// validate if array of string newparticipants
|
1897
|
+
return new Promise(function (resolve, reject) {
|
1898
|
+
|
1899
|
+
var isArray = Array.isArray(newfollowers);
|
1900
|
+
|
1901
|
+
if(isArray==false) {
|
1902
|
+
winston.error('setFollowersByRequestId error newfollowers is not an array for request_id '+ request_id + ' and id_project '+ id_project);
|
1903
|
+
return reject('setFollowersByRequestId error newfollowers is not an array for request_id '+ request_id + ' and id_project '+ id_project);
|
1904
|
+
}
|
1905
|
+
|
1906
|
+
return Request
|
1907
|
+
|
1908
|
+
.findOne({request_id: request_id, id_project: id_project})
|
1909
|
+
// qui cache ok
|
1910
|
+
.exec( function(err, request) {
|
1911
|
+
if (err) {
|
1912
|
+
winston.error("Error setFollowersByRequestId", err);
|
1913
|
+
return reject(err);
|
1914
|
+
}
|
1915
|
+
if (!request) {
|
1916
|
+
winston.error('Request not found for request_id '+ request_id + ' and id_project '+ id_project);
|
1917
|
+
return reject('Request not found for request_id '+ request_id + ' and id_project '+ id_project);
|
1918
|
+
}
|
1919
|
+
var oldfollowers = request.followers;
|
1920
|
+
winston.debug('oldParticipants', oldfollowers);
|
1921
|
+
winston.debug('newparticipants', newfollowers);
|
1922
|
+
|
1923
|
+
if (requestUtil.arraysEqual(oldfollowers, newfollowers)){
|
1924
|
+
//if (oldParticipants === newparticipants) {
|
1925
|
+
winston.verbose('Request members '+ oldfollowers+ ' already equal to ' + newfollowers + ' for request_id '+ request_id + ' and id_project '+ id_project);
|
1926
|
+
return request
|
1927
|
+
.populate('lead')
|
1928
|
+
.populate('department')
|
1929
|
+
.populate('participatingBots')
|
1930
|
+
.populate('participatingAgents')
|
1931
|
+
.populate({path:'requester',populate:{path:'id_user'}})
|
1932
|
+
.execPopulate( function(err, requestComplete) {
|
1933
|
+
return resolve(requestComplete);
|
1934
|
+
});
|
1935
|
+
|
1936
|
+
}
|
1937
|
+
|
1938
|
+
request.followers = newfollowers;
|
1939
|
+
|
1940
|
+
//cacheinvalidation
|
1941
|
+
return request.save(function(err, updatedRequest) {
|
1942
|
+
// dopo save non aggiorna participating
|
1943
|
+
if (err) {
|
1944
|
+
winston.error("Error setFollowersByRequestId", err);
|
1945
|
+
return reject(err);
|
1946
|
+
}
|
1947
|
+
|
1948
|
+
return updatedRequest
|
1949
|
+
.populate('lead')
|
1950
|
+
.populate('department')
|
1951
|
+
.populate('participatingBots')
|
1952
|
+
.populate('participatingAgents')
|
1953
|
+
.populate({path:'requester',populate:{path:'id_user'}})
|
1954
|
+
.execPopulate( function(err, requestComplete) {
|
1955
|
+
|
1956
|
+
|
1957
|
+
if (err) {
|
1958
|
+
winston.error("Error getting setFollowersByRequestId", err);
|
1959
|
+
return reject(err);
|
1960
|
+
}
|
1961
|
+
|
1962
|
+
winston.debug("oldfollowers ", oldfollowers);
|
1963
|
+
|
1964
|
+
requestEvent.emit('request.update', requestComplete);
|
1965
|
+
requestEvent.emit("request.update.comment", {comment:"FOLLOWERS_SET",request:requestComplete});//Deprecated
|
1966
|
+
requestEvent.emit("request.updated", {comment:"FOLLOWERS_SET",request:requestComplete, patch: {}});
|
1967
|
+
|
1968
|
+
// requestEvent.emit('request.followers.update', {beforeRequest:request,
|
1969
|
+
// removedParticipants:removedParticipants,
|
1970
|
+
// addedParticipants:addedParticipants,
|
1971
|
+
// request:requestComplete});
|
1972
|
+
|
1973
|
+
return resolve(requestComplete);
|
1974
|
+
});
|
1975
|
+
});
|
1976
|
+
|
1977
|
+
});
|
1978
|
+
|
1979
|
+
|
1980
|
+
});
|
1981
|
+
}
|
1982
|
+
|
1983
|
+
|
1984
|
+
|
1985
|
+
|
1986
|
+
|
1987
|
+
|
1988
|
+
removeFollowerByRequestId(request_id, id_project, member) {
|
1989
|
+
winston.debug("request_id", request_id);
|
1990
|
+
winston.debug("id_project", id_project);
|
1991
|
+
winston.debug("member", member);
|
1992
|
+
|
1993
|
+
return new Promise(function (resolve, reject) {
|
1994
|
+
|
1995
|
+
|
1996
|
+
|
1997
|
+
if (member==undefined) {
|
1998
|
+
var err = "removeFollowerByRequestId error, member field is null";
|
1999
|
+
winston.error(err);
|
2000
|
+
return reject(err);
|
2001
|
+
}
|
2002
|
+
|
2003
|
+
|
2004
|
+
return Request
|
2005
|
+
.findOne({request_id: request_id, id_project: id_project})
|
2006
|
+
// .populate('participatingAgents') //for abandoned_by_project_users
|
2007
|
+
// qui cache
|
2008
|
+
.exec( async (err, request) => {
|
2009
|
+
|
2010
|
+
if (err){
|
2011
|
+
winston.error("Error removing follower ", err);
|
2012
|
+
return reject(err);
|
2013
|
+
}
|
2014
|
+
|
2015
|
+
if (!request) {
|
2016
|
+
winston.error('Request not found for request_id '+ request_id + ' and id_project '+ id_project);
|
2017
|
+
return reject('Request not found for request_id '+ request_id + ' and id_project '+ id_project);
|
2018
|
+
}
|
2019
|
+
|
2020
|
+
var index = request.followers.indexOf(member);
|
2021
|
+
winston.debug("index", index);
|
2022
|
+
|
2023
|
+
if (index > -1) {
|
2024
|
+
request.followers.splice(index, 1);
|
2025
|
+
// winston.debug(" request.participants", request.participants);
|
2026
|
+
|
2027
|
+
|
2028
|
+
// winston.debug(" request", request);
|
2029
|
+
//cacheinvalidation
|
2030
|
+
return request.save(function(err, savedRequest) {
|
2031
|
+
if (err){
|
2032
|
+
winston.error("Error saving removed follower ", err);
|
2033
|
+
return reject(err);
|
2034
|
+
}
|
2035
|
+
|
2036
|
+
return savedRequest
|
2037
|
+
.populate('lead')
|
2038
|
+
.populate('department')
|
2039
|
+
.populate('participatingBots')
|
2040
|
+
.populate('participatingAgents')
|
2041
|
+
// .populate('followers')
|
2042
|
+
.populate({path:'requester',populate:{path:'id_user'}})
|
2043
|
+
.execPopulate( function(err, requestComplete) {
|
2044
|
+
|
2045
|
+
if (err){
|
2046
|
+
winston.error("Error getting removed follower ", err);
|
2047
|
+
return reject(err);
|
2048
|
+
}
|
2049
|
+
|
2050
|
+
|
2051
|
+
requestEvent.emit('request.update', requestComplete);
|
2052
|
+
requestEvent.emit("request.update.comment", {comment:"FOLLOWER_REMOVE",request:requestComplete});//Deprecated
|
2053
|
+
requestEvent.emit("request.updated", {comment:"FOLLOWER_REMOVE",request:requestComplete, patch: {member:member}});
|
2054
|
+
requestEvent.emit('request.followers.leave', {member:member, request: requestComplete});
|
2055
|
+
|
2056
|
+
|
2057
|
+
return resolve(requestComplete);
|
2058
|
+
|
2059
|
+
});
|
2060
|
+
});
|
2061
|
+
|
2062
|
+
|
2063
|
+
}else {
|
2064
|
+
winston.verbose('Request member '+ member+ ' already not found for request_id '+ request_id + ' and id_project '+ id_project);
|
2065
|
+
|
2066
|
+
return request
|
2067
|
+
.populate('lead')
|
2068
|
+
.populate('department')
|
2069
|
+
.populate('participatingBots')
|
2070
|
+
.populate('participatingAgents')
|
2071
|
+
// .populate('followers')
|
2072
|
+
.populate({path:'requester',populate:{path:'id_user'}})
|
2073
|
+
.execPopulate( function(err, requestComplete) {
|
2074
|
+
return resolve(requestComplete);
|
2075
|
+
});
|
2076
|
+
}
|
2077
|
+
|
2078
|
+
});
|
2079
|
+
});
|
2080
|
+
}
|
2081
|
+
|
2082
|
+
|
2083
|
+
|
2084
|
+
|
2085
|
+
|
2086
|
+
|
2087
|
+
|
2088
|
+
|
1731
2089
|
}
|
1732
2090
|
|
1733
2091
|
|