@tiledesk/tiledesk-server 2.3.17 → 2.3.19
Sign up to get free protection for your applications and to get access to all the features.
- package/channels/chat21/chat21Handler.js +18 -3
- package/channels/chat21/package-lock.json +663 -706
- package/channels/chat21/package.json +2 -2
- package/models/project_user.js +4 -0
- package/models/request.js +12 -1
- package/package.json +3 -5
- package/pubmodules/activities/activityArchiver.js +1 -1
- package/pubmodules/activities/routes/activity.js +1 -1
- package/pubmodules/canned/cannedResponse.js +4 -0
- package/pubmodules/canned/cannedResponseRoute.js +11 -5
- package/pubmodules/emailNotification/requestNotification.js +25 -2
- package/pubmodules/events/eventRoute.js +37 -7
- package/pubmodules/pubModulesManager.js +57 -5
- package/pubmodules/queue/index.js +4 -0
- package/pubmodules/queue/reconnect.js +247 -0
- package/pubmodules/queue/reconnectFanout.js +250 -0
- package/pubmodules/routing-queue/index.js +3 -0
- package/pubmodules/routing-queue/listener.js +328 -0
- package/pubmodules/trigger/start.js +5 -1
- package/routes/auth.js +7 -2
- package/routes/project_user.js +9 -0
- package/routes/request.js +18 -0
- package/services/geoService.js +30 -4
- package/services/modulesManager.js +34 -33
- package/template/email/pooledRequest.html +1 -1
- package/test/cannedRoute.js +166 -0
- package/websocket/webSocketServer.js +23 -5
package/services/geoService.js
CHANGED
@@ -8,6 +8,13 @@ var geoip = require('geoip-lite');
|
|
8
8
|
|
9
9
|
class GeoService {
|
10
10
|
|
11
|
+
constructor() {
|
12
|
+
this.enabled = true;
|
13
|
+
if (process.env.GEO_SERVICE_ENABLED=="false" || process.env.GEO_SERVICE_ENABLED==false) {
|
14
|
+
this.enabled = false;
|
15
|
+
}
|
16
|
+
winston.debug("GeoService this.enabled: "+ this.enabled);
|
17
|
+
}
|
11
18
|
|
12
19
|
|
13
20
|
// https://medium.com/@rossbulat/node-js-client-ip-location-with-geoip-lite-fallback-c25833c94a76
|
@@ -16,7 +23,12 @@ class GeoService {
|
|
16
23
|
|
17
24
|
listen() {
|
18
25
|
|
19
|
-
|
26
|
+
if (this.enabled==true) {
|
27
|
+
winston.info("GeoService listener started");
|
28
|
+
} else {
|
29
|
+
return winston.info("GeoService listener disabled");
|
30
|
+
}
|
31
|
+
|
20
32
|
|
21
33
|
|
22
34
|
|
@@ -36,9 +48,19 @@ class GeoService {
|
|
36
48
|
// area: 200 }
|
37
49
|
|
38
50
|
|
39
|
-
requestEvent.on('request.create', function(request) {
|
40
51
|
|
41
|
-
|
52
|
+
var requestCreateKey = 'request.create';
|
53
|
+
// if (requestEvent.queueEnabled) {
|
54
|
+
// requestCreateKey = 'request.create.queue';
|
55
|
+
// }
|
56
|
+
// winston.debug('GeoService requestCreateKey: ' + requestCreateKey);
|
57
|
+
|
58
|
+
|
59
|
+
requestEvent.on(requestCreateKey, function(request) {
|
60
|
+
|
61
|
+
setImmediate(() => {
|
62
|
+
|
63
|
+
winston.debug("request", request);
|
42
64
|
|
43
65
|
var ip = (request.location && request.location.ipAddress) || (request.attributes && request.attributes.ipAddress);
|
44
66
|
winston.debug("ip" + ip);
|
@@ -114,11 +136,15 @@ class GeoService {
|
|
114
136
|
}
|
115
137
|
return winston.verbose("Saved location metadata for request with id " + request._id);
|
116
138
|
});
|
139
|
+
|
140
|
+
//TODO AGGIORNA ANCHE LEAD e req.snapshot.lead?
|
141
|
+
// leggi ip da request e nn da attributes
|
117
142
|
|
118
143
|
}
|
119
144
|
}
|
120
145
|
});
|
121
|
-
|
146
|
+
});
|
147
|
+
}
|
122
148
|
|
123
149
|
|
124
150
|
}
|
@@ -24,6 +24,7 @@ var licenseKey = process.env.LICENSE_KEY;
|
|
24
24
|
if (licenseKey) {
|
25
25
|
var maskedLicenseKey = MaskData.maskPhone(licenseKey, maskOptions);
|
26
26
|
winston.info("LicenseKey: " + maskedLicenseKey);
|
27
|
+
// winston.info("LicenseKey: " + licenseKey);
|
27
28
|
}
|
28
29
|
|
29
30
|
class ModulesManager {
|
@@ -38,8 +39,8 @@ class ModulesManager {
|
|
38
39
|
this.dialogflowListener = undefined;
|
39
40
|
this.requestHistoryArchiver = undefined;
|
40
41
|
this.requestHistoryRoute = undefined;
|
41
|
-
this.routingQueue = undefined;
|
42
|
-
this.queue = undefined;
|
42
|
+
// this.routingQueue = undefined;
|
43
|
+
// this.queue = undefined;
|
43
44
|
this.cache = undefined;
|
44
45
|
this.visitorCounterRoute = undefined;
|
45
46
|
this.visitorCounterMiddleware = undefined;
|
@@ -216,34 +217,34 @@ class ModulesManager {
|
|
216
217
|
}
|
217
218
|
|
218
219
|
|
219
|
-
try {
|
220
|
-
|
221
|
-
|
222
|
-
|
220
|
+
// try {
|
221
|
+
// this.routingQueue = require('@tiledesk-ent/tiledesk-server-routing-queue').listener;
|
222
|
+
// // this.routingQueue.listen();
|
223
|
+
// winston.debug("this.routingQueue:"+ this.routingQueue);
|
223
224
|
|
224
|
-
|
225
|
-
} catch(err) {
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
}
|
225
|
+
// winston.info("ModulesManager routing queue initialized");
|
226
|
+
// } catch(err) {
|
227
|
+
// if (err.code == 'MODULE_NOT_FOUND') {
|
228
|
+
// winston.info("ModulesManager init routing queue module not found");
|
229
|
+
// }else {
|
230
|
+
// winston.error("ModulesManager error initializing init routing queue module", err);
|
231
|
+
// }
|
232
|
+
// }
|
232
233
|
|
233
234
|
|
234
235
|
|
235
|
-
try {
|
236
|
-
|
237
|
-
|
236
|
+
// try {
|
237
|
+
// this.queue = require('@tiledesk-ent/tiledesk-server-queue');
|
238
|
+
// winston.debug("this.queue:"+ this.queue);
|
238
239
|
|
239
|
-
|
240
|
-
} catch(err) {
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
}
|
240
|
+
// winston.info("ModulesManager queue initialized");
|
241
|
+
// } catch(err) {
|
242
|
+
// if (err.code == 'MODULE_NOT_FOUND') {
|
243
|
+
// winston.info("ModulesManager init queue module not found");
|
244
|
+
// }else {
|
245
|
+
// winston.error("ModulesManager error initializing init queue module", err);
|
246
|
+
// }
|
247
|
+
// }
|
247
248
|
|
248
249
|
|
249
250
|
try {
|
@@ -329,14 +330,14 @@ class ModulesManager {
|
|
329
330
|
winston.info("ModulesManager error starting requestHistoryArchiver module", err);
|
330
331
|
}
|
331
332
|
}
|
332
|
-
if (this.routingQueue) {
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
}
|
333
|
+
// if (this.routingQueue) {
|
334
|
+
// try {
|
335
|
+
// this.routingQueue.listen();
|
336
|
+
// winston.info("ModulesManager routingQueue started");
|
337
|
+
// } catch(err) {
|
338
|
+
// winston.info("ModulesManager error starting routingQueue module", err);
|
339
|
+
// }
|
340
|
+
// }
|
340
341
|
if (this.dialogflowListener) {
|
341
342
|
try {
|
342
343
|
this.dialogflowListener.listen();
|
@@ -82,7 +82,7 @@
|
|
82
82
|
|
83
83
|
<div style="text-align:center">
|
84
84
|
<a href="http://www.tiledesk.com" style="color:#2daae1;font-weight:bold;text-decoration:none;word-break:break-word" target="_blank">
|
85
|
-
<img src="https://tiledesk.com/wp-content/uploads/2022/07/tiledesk_v2.png" style="width:
|
85
|
+
<img src="https://tiledesk.com/wp-content/uploads/2022/07/tiledesk_v2.png" style="max-width:200px;outline:none;text-decoration:none;border:none;height:auto;margin-left:0px;" class="CToWUd">
|
86
86
|
</a>
|
87
87
|
</div>
|
88
88
|
</tr>
|
@@ -0,0 +1,166 @@
|
|
1
|
+
//During the test the env variable is set to test
|
2
|
+
process.env.NODE_ENV = 'test';
|
3
|
+
|
4
|
+
//Require the dev-dependencies
|
5
|
+
let chai = require('chai');
|
6
|
+
let expect = require('chai').expect;
|
7
|
+
|
8
|
+
let chaiHttp = require('chai-http');
|
9
|
+
let server = require('../app');
|
10
|
+
const projectService = require('../services/projectService');
|
11
|
+
const userService = require('../services/userService');
|
12
|
+
var RoleConstants = require("../models/roleConstants");
|
13
|
+
const Project_user = require('../models/project_user');
|
14
|
+
let should = chai.should();
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
chai.use(chaiHttp);
|
19
|
+
|
20
|
+
describe('CannedRoute', () => {
|
21
|
+
|
22
|
+
it('new canned by owner/admin', (done) => {
|
23
|
+
var email = "test-signup-" + Date.now() + "@email.com";
|
24
|
+
var pwd = "pwd";
|
25
|
+
|
26
|
+
userService.signup(email, pwd, "Test Firstname", "Test Lastname").then(savedUser => {
|
27
|
+
projectService.create("test1", savedUser._id).then(savedProject => {
|
28
|
+
|
29
|
+
chai.request(server)
|
30
|
+
.post('/' + savedProject._id + '/canned/')
|
31
|
+
.auth(email, pwd)
|
32
|
+
.set('content-type', 'application/json')
|
33
|
+
.send({ "title": "Test Title", "text": "Test Text" })
|
34
|
+
.end((err, res) => {
|
35
|
+
console.log("res.body", res.body);
|
36
|
+
res.should.have.status(200);
|
37
|
+
res.body.should.be.a('object');
|
38
|
+
res.body.should.have.property('title').eql("Test Title");
|
39
|
+
res.body.should.have.property('text').eql("Test Text");
|
40
|
+
res.body.should.have.property('createdBy').eql(savedUser._id.toString());
|
41
|
+
res.body.should.have.property('shared').eql(true);
|
42
|
+
|
43
|
+
done();
|
44
|
+
})
|
45
|
+
})
|
46
|
+
})
|
47
|
+
})
|
48
|
+
|
49
|
+
it('new canned by agent', (done) => {
|
50
|
+
var email = "test-signup-" + Date.now() + "@email.com";
|
51
|
+
var pwd = "pwd";
|
52
|
+
|
53
|
+
userService.signup(email, pwd, "Test Firstname", "Test Lastname").then(savedUser => {
|
54
|
+
projectService.create("test1", savedUser._id).then(savedProject => {
|
55
|
+
|
56
|
+
console.log("RoleConstants.AGENT: ", RoleConstants.AGENT);
|
57
|
+
Project_user.findOneAndUpdate({id_project: savedProject._id, id_user: savedUser._id }, { role: RoleConstants.AGENT }, function(err, savedProject_user){
|
58
|
+
chai.request(server)
|
59
|
+
.post('/' + savedProject._id + '/canned/')
|
60
|
+
.auth(email, pwd)
|
61
|
+
.set('content-type', 'application/json')
|
62
|
+
.send({ title: "Test Title", text: "Test Text" })
|
63
|
+
.end((err, res) => {
|
64
|
+
console.log("res.body", res.body);
|
65
|
+
res.body.should.be.a('object');
|
66
|
+
res.body.should.have.property('title').eql("Test Title");
|
67
|
+
res.body.should.have.property('text').eql("Test Text");
|
68
|
+
res.body.should.have.property('createdBy').eql(savedUser._id.toString());
|
69
|
+
res.body.should.have.property('shared').eql(false);
|
70
|
+
|
71
|
+
done();
|
72
|
+
})
|
73
|
+
})
|
74
|
+
})
|
75
|
+
})
|
76
|
+
})
|
77
|
+
|
78
|
+
it('get canned', (done) => {
|
79
|
+
|
80
|
+
var email_owner = "owner-signup-" + Date.now() + "@email.com";
|
81
|
+
var email_agent = "agent-signup-" + Date.now() + "@email.com";
|
82
|
+
var pwd = "pwd";
|
83
|
+
|
84
|
+
userService.signup(email_owner, pwd, "Owner Firstname", "Owner Lastname").then(savedOwner => {
|
85
|
+
userService.signup(email_agent, pwd, "Agent Firstname", "Agent Lastname").then(savedAgent => {
|
86
|
+
projectService.create("test1", savedOwner._id).then(savedProject => {
|
87
|
+
|
88
|
+
// invite Agent on savedProject (?)
|
89
|
+
chai.request(server)
|
90
|
+
.post('/' + savedProject._id + "/project_users/invite")
|
91
|
+
.auth(email_owner, pwd)
|
92
|
+
.set('content-type', 'application/json')
|
93
|
+
.send({ email: email_agent, role: "agent", userAvailable: false })
|
94
|
+
.end((err, res) => {
|
95
|
+
console.log("res.boy", res.body)
|
96
|
+
res.should.have.status(200);
|
97
|
+
|
98
|
+
|
99
|
+
chai.request(server)
|
100
|
+
.post('/' + savedProject._id + "/canned/")
|
101
|
+
.auth(email_owner, pwd)
|
102
|
+
.set('content-type', 'application/json')
|
103
|
+
.send({ title: "Test1 Title", text: "Test1 Text" })
|
104
|
+
.end((err, res) => {
|
105
|
+
|
106
|
+
console.log("res.body", res.body);
|
107
|
+
res.should.have.status(200);
|
108
|
+
res.body.should.be.a('object');
|
109
|
+
|
110
|
+
chai.request(server)
|
111
|
+
.post('/' + savedProject._id + "/canned/")
|
112
|
+
.auth(email_agent, pwd)
|
113
|
+
.set('content-type', 'application/json')
|
114
|
+
.send({ title: "Test2 Title", text: "Test2 Text" })
|
115
|
+
.end((err, res) => {
|
116
|
+
|
117
|
+
console.log("res.body", res.body);
|
118
|
+
res.should.have.status(200);
|
119
|
+
res.body.should.be.a('object');
|
120
|
+
|
121
|
+
chai.request(server)
|
122
|
+
.get('/' + savedProject._id + "/canned/")
|
123
|
+
.auth(email_owner, pwd)
|
124
|
+
.set('content-type', 'application-json')
|
125
|
+
.send()
|
126
|
+
.end((err, res) => {
|
127
|
+
|
128
|
+
console.log("res.body", res.body);
|
129
|
+
res.should.have.status(200);
|
130
|
+
//res.body.should.be.a('array');
|
131
|
+
|
132
|
+
expect(res.body).to.be.an('array')
|
133
|
+
expect(res.body.length).to.equal(1);
|
134
|
+
|
135
|
+
chai.request(server)
|
136
|
+
.get('/' + savedProject._id + "/canned/")
|
137
|
+
.auth(email_agent, pwd)
|
138
|
+
.set('content-type', 'application-json')
|
139
|
+
.send()
|
140
|
+
.end((err, res) => {
|
141
|
+
|
142
|
+
console.log("res.body", res.body);
|
143
|
+
console.log("\n --> body.length", res.body.length);
|
144
|
+
res.should.have.status(200);
|
145
|
+
//res.body.should.be.a('array');
|
146
|
+
|
147
|
+
expect(res.body).to.be.an('array')
|
148
|
+
expect(res.body.length).to.equal(2);
|
149
|
+
|
150
|
+
done();
|
151
|
+
|
152
|
+
})
|
153
|
+
|
154
|
+
|
155
|
+
})
|
156
|
+
|
157
|
+
|
158
|
+
})
|
159
|
+
|
160
|
+
})
|
161
|
+
})
|
162
|
+
})
|
163
|
+
})
|
164
|
+
})
|
165
|
+
}).timeout(5000);
|
166
|
+
})
|
@@ -169,8 +169,18 @@ class WebSocketServer {
|
|
169
169
|
|
170
170
|
winston.debug(' req.user._id: '+ req.user);
|
171
171
|
|
172
|
+
if (!topic) {
|
173
|
+
winston.error('WebSocket - Error getting topic. Topic can t be null');
|
174
|
+
return reject('WebSocket - Error getting topic. Topic can t be null');
|
175
|
+
}
|
172
176
|
var urlSub = topic.split('/');
|
173
177
|
|
178
|
+
if (!urlSub || (urlSub && urlSub.length==0)) {
|
179
|
+
winston.error('WebSocket - Error getting topic. Topic is not properly configured');
|
180
|
+
return reject('WebSocket - Error getting topic. Topic is not properly configured');
|
181
|
+
}
|
182
|
+
// Error getting Project Cast to ObjectId failed for value "N7VJlLZ1" (type string) at path "_id" for model "project" {"kind":"ObjectId","path":"_id","reason":{},"stack":"CastError: Cast to ObjectId failed for value \"N7VJlLZ1\" (type string) at path \"_id\" for model \"project\"\n at model.Query.exec (/usr/src/app/node_modules/mongoose/lib/query.js:4498:21)\n at /usr/src/app/websocket/webSocketServer.js:180:14\n at new Promise (<anonymous>)\n at Object.onSubscribeCallback [as onSubscribe] (/usr/src/app/websocket/webSocketServer.js:167:14)\n at PubSub.handleReceivedClientMessage (/usr/src/app/websocket/pubsub.js:358:57)\n at runMicrotasks (<anonymous>)\n at processTicksAndRejections (internal/process/task_queues.js:97:5)","stringValue":"\"N7VJlLZ1\"","value":"N7VJlLZ1","valueType":"string"}
|
183
|
+
|
174
184
|
var projectId = urlSub[1];
|
175
185
|
winston.debug('projectId: '+projectId);
|
176
186
|
|
@@ -590,11 +600,12 @@ class WebSocketServer {
|
|
590
600
|
winston.debug('messageCreateKey: ' + messageCreateKey);
|
591
601
|
|
592
602
|
messageEvent.on(messageCreateKey, function (message) {
|
603
|
+
setImmediate(async () => {
|
593
604
|
winston.debug('messageEvent websocket server: '+messageCreateKey, message);
|
594
605
|
if (message.request) {
|
595
606
|
pubSubServer.handlePublishMessage ('/'+message.id_project+'/requests/'+message.request.request_id+'/messages', message, undefined, true, "CREATE");
|
596
607
|
}
|
597
|
-
|
608
|
+
});
|
598
609
|
});
|
599
610
|
|
600
611
|
// var reconnect = require('./reconnect');
|
@@ -604,7 +615,8 @@ class WebSocketServer {
|
|
604
615
|
}
|
605
616
|
winston.debug('requestCreateKey: ' + requestCreateKey);
|
606
617
|
requestEvent.on(requestCreateKey, async function (request) {
|
607
|
-
|
618
|
+
setImmediate(async () => {
|
619
|
+
|
608
620
|
winston.debug('requestEvent websocket server: '+requestCreateKey, request);
|
609
621
|
// TODO scarta riquesta se agente (req.user._id) non sta ne in participants ne in agents
|
610
622
|
|
@@ -643,7 +655,7 @@ class WebSocketServer {
|
|
643
655
|
pubSubServer.handlePublishMessage ('/'+request.id_project+'/requests', request, undefined, true, "CREATE");
|
644
656
|
pubSubServer.handlePublishMessage ('/'+request.id_project+'/requests/'+request.request_id, request, undefined, true, "CREATE");
|
645
657
|
}
|
646
|
-
|
658
|
+
});
|
647
659
|
});
|
648
660
|
|
649
661
|
var requestUpdateKey = 'request.update';
|
@@ -653,6 +665,8 @@ class WebSocketServer {
|
|
653
665
|
|
654
666
|
winston.debug('requestUpdateKey: ' + requestUpdateKey);
|
655
667
|
requestEvent.on(requestUpdateKey, async function(request) {
|
668
|
+
setImmediate(async () => {
|
669
|
+
|
656
670
|
// TODO setImmediate(() => {
|
657
671
|
winston.debug('requestEvent websocket server: '+requestUpdateKey, request);
|
658
672
|
if (request.preflight===false && request.status > requestConstants.TEMP) {
|
@@ -694,7 +708,7 @@ class WebSocketServer {
|
|
694
708
|
pubSubServer.handlePublishMessage ('/'+request.id_project+'/requests', requestJSON, undefined, true, "UPDATE");
|
695
709
|
pubSubServer.handlePublishMessage ('/'+request.id_project+'/requests/'+request.request_id, requestJSON, undefined, true, "UPDATE");
|
696
710
|
}
|
697
|
-
|
711
|
+
});
|
698
712
|
});
|
699
713
|
|
700
714
|
|
@@ -709,6 +723,8 @@ class WebSocketServer {
|
|
709
723
|
}
|
710
724
|
winston.debug('projectuserUpdateKey: ' + projectuserUpdateKey);
|
711
725
|
authEvent.on(projectuserUpdateKey,function(data) {
|
726
|
+
setImmediate(async () => {
|
727
|
+
|
712
728
|
var pu = data.updatedProject_userPopulated;
|
713
729
|
winston.debug('ws pu', pu);
|
714
730
|
|
@@ -724,7 +740,7 @@ class WebSocketServer {
|
|
724
740
|
}
|
725
741
|
winston.debug('userId:'+ userId);
|
726
742
|
pubSubServer.handlePublishMessage ('/'+pu.id_project+'/project_users/users/'+userId, pu, undefined, true, "UPDATE");
|
727
|
-
|
743
|
+
});
|
728
744
|
});
|
729
745
|
|
730
746
|
|
@@ -735,6 +751,7 @@ class WebSocketServer {
|
|
735
751
|
}
|
736
752
|
winston.debug('eventEmitKey: ' + eventEmitKey);
|
737
753
|
eventEvent.on(eventEmitKey,function(event) {
|
754
|
+
setImmediate(async () => {
|
738
755
|
winston.debug('event', event);
|
739
756
|
if (event.project_user === undefined) {
|
740
757
|
//with "faqbot.answer_not_found" project_user is undefined but it's ok
|
@@ -743,6 +760,7 @@ class WebSocketServer {
|
|
743
760
|
}
|
744
761
|
pubSubServer.handlePublishMessage ('/'+event.id_project+'/events/'+event.project_user._id, event, undefined, true, "CREATE");
|
745
762
|
});
|
763
|
+
});
|
746
764
|
|
747
765
|
|
748
766
|
// https://github.com/websockets/ws/blob/master/examples/express-session-parse/index.js
|