@tiledesk/tiledesk-server 2.4.78 → 2.4.79-rc1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +10 -0
- package/app.js +5 -0
- package/deploy.sh +1 -1
- package/jobs.js +3 -1
- package/jobsManager.js +11 -0
- package/middleware/recaptcha.js +32 -0
- package/package.json +6 -4
- package/pubmodules/whatsapp/listener.js +8 -0
- package/routes/auth.js +86 -10
- package/routes/message.js +3 -2
- package/utils/segment2mongoConverter.js +1 -1
package/CHANGELOG.md
CHANGED
@@ -5,6 +5,16 @@
|
|
5
5
|
🚀 IN PRODUCTION 🚀
|
6
6
|
(https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77)
|
7
7
|
|
8
|
+
# 2.4.79
|
9
|
+
- update whatsapp-connector to 0.1.55
|
10
|
+
- update whatsapp-jobworker to 0.0.4
|
11
|
+
- added support for whatsapp broadcast queue
|
12
|
+
|
13
|
+
# 2.4.78
|
14
|
+
- update whatsapp-connector to 0.1.53
|
15
|
+
- update messenger-connector to 0.1.13
|
16
|
+
- update telegram-connector to 0.1.10
|
17
|
+
|
8
18
|
# 2.4.77
|
9
19
|
- update tybot-connector to 0.2.26
|
10
20
|
|
package/app.js
CHANGED
@@ -181,6 +181,11 @@ pubModulesManager.init({express:express, mongoose:mongoose, passport:passport, d
|
|
181
181
|
|
182
182
|
jobsManager.listen(); //listen after pubmodules to enabled queued *.queueEnabled events
|
183
183
|
|
184
|
+
let whatsappQueue = require('@tiledesk/tiledesk-whatsapp-jobworker');
|
185
|
+
winston.info("whatsappQueue");
|
186
|
+
jobsManager.listenWhatsappQueue(whatsappQueue);
|
187
|
+
|
188
|
+
|
184
189
|
var channelManager = require('./channels/channelManager');
|
185
190
|
channelManager.listen();
|
186
191
|
|
package/deploy.sh
CHANGED
package/jobs.js
CHANGED
@@ -97,7 +97,9 @@ async function main()
|
|
97
97
|
winston.debug("routingQueueQueued");
|
98
98
|
jobsManager.listenRoutingQueue(routingQueueQueued);
|
99
99
|
|
100
|
-
|
100
|
+
let whatsappQueue = require('@tiledesk/tiledesk-whatsapp-jobworker');
|
101
|
+
winston.info("whatsappQueue");
|
102
|
+
jobsManager.listenWhatsappQueue(whatsappQueue);
|
101
103
|
|
102
104
|
let scheduler = require('./pubmodules/scheduler');
|
103
105
|
jobsManager.listenScheduler(scheduler);
|
package/jobsManager.js
CHANGED
@@ -11,6 +11,7 @@ class JobsManager {
|
|
11
11
|
|
12
12
|
this.emailNotificatio = undefined;
|
13
13
|
this.activityArchiver = undefined;
|
14
|
+
this.whatsappWorker = undefined;
|
14
15
|
|
15
16
|
this.jobWorkerEnabled = jobWorkerEnabled;
|
16
17
|
// this.jobWorkerEnabled = false;
|
@@ -71,6 +72,16 @@ class JobsManager {
|
|
71
72
|
this.activityArchiver = activityArchiver;
|
72
73
|
this.activityArchiver.listen();
|
73
74
|
}
|
75
|
+
|
76
|
+
listenWhatsappQueue(whatsappQueue) {
|
77
|
+
console.log("JobsManager listenWhatsappQueue started");
|
78
|
+
console.log("whatsappQueue is: ", whatsappQueue)
|
79
|
+
if ( this.jobWorkerEnabled == true) {
|
80
|
+
return winston.info("JobsManager jobWorkerEnabled is enabled. Skipping listener for Whatsapp Queue");
|
81
|
+
}
|
82
|
+
// this.whatsappWorker = whatsappQueue;
|
83
|
+
// this.whatsappQueue.listen(); // oppure codice
|
84
|
+
}
|
74
85
|
}
|
75
86
|
|
76
87
|
|
@@ -0,0 +1,32 @@
|
|
1
|
+
var winston = require('../config/winston');
|
2
|
+
|
3
|
+
var Recaptcha = require('express-recaptcha').RecaptchaV3
|
4
|
+
var recaptcha = new Recaptcha('6Lf1khcpAAAAABMNHJfnJm43vVTxFzXM7ADqDAp5', '6Lf1khcpAAAAAG6t7LuOfl9vThGPFOOJIiAoMIhs')
|
5
|
+
|
6
|
+
const RECAPTCHA_ENABLED = false;
|
7
|
+
|
8
|
+
if (process.env.RECAPTCHA_ENABLED === true || process.env.RECAPTCHA_ENABLED ==="true") {
|
9
|
+
RECAPTCHA_ENABLED = true;
|
10
|
+
}
|
11
|
+
|
12
|
+
module.exports =
|
13
|
+
function(req,res,next){
|
14
|
+
if (RECAPTCHA_ENABLED==false) {
|
15
|
+
return next();
|
16
|
+
}
|
17
|
+
|
18
|
+
recaptcha.verify(req, function (error, data) {
|
19
|
+
if (!error) {
|
20
|
+
winston.debug("Signup recaptcha ok");
|
21
|
+
next();
|
22
|
+
// success code
|
23
|
+
} else {
|
24
|
+
winston.error("Signup recaptcha ko");
|
25
|
+
// next({status:"Signup recaptcha ko"});
|
26
|
+
res.status(403).send({success: false, msg: 'Recaptcha error.'});
|
27
|
+
|
28
|
+
// error code
|
29
|
+
}
|
30
|
+
})
|
31
|
+
|
32
|
+
}
|
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.4.
|
4
|
+
"version": "2.4.79-rc1",
|
5
5
|
"scripts": {
|
6
6
|
"start": "node ./bin/www",
|
7
7
|
"pretest": "mongodb-runner start",
|
@@ -42,11 +42,12 @@
|
|
42
42
|
"@tiledesk/tiledesk-dialogflow-connector": "^1.8.4",
|
43
43
|
"@tiledesk/tiledesk-json-rules-engine": "^4.0.3",
|
44
44
|
"@tiledesk/tiledesk-kaleyra-proxy": "^0.1.7",
|
45
|
-
"@tiledesk/tiledesk-rasa-connector": "^1.0.10",
|
46
|
-
"@tiledesk/tiledesk-tybot-connector": "^0.2.26",
|
47
|
-
"@tiledesk/tiledesk-whatsapp-connector": "^0.1.53",
|
48
45
|
"@tiledesk/tiledesk-messenger-connector": "^0.1.13",
|
46
|
+
"@tiledesk/tiledesk-rasa-connector": "^1.0.10",
|
49
47
|
"@tiledesk/tiledesk-telegram-connector": "^0.1.10",
|
48
|
+
"@tiledesk/tiledesk-tybot-connector": "^0.2.30",
|
49
|
+
"@tiledesk/tiledesk-whatsapp-connector": "^0.1.55",
|
50
|
+
"@tiledesk/tiledesk-whatsapp-jobworker": "^0.0.4",
|
50
51
|
"amqplib": "^0.5.5",
|
51
52
|
"app-root-path": "^3.0.0",
|
52
53
|
"bcrypt-nodejs": "0.0.3",
|
@@ -62,6 +63,7 @@
|
|
62
63
|
"eventemitter2": "^6.4.4",
|
63
64
|
"express": "^4.17.3",
|
64
65
|
"express-ipfilter": "^1.2.0",
|
66
|
+
"express-recaptcha": "^5.1.0",
|
65
67
|
"express-session": "^1.17.3",
|
66
68
|
"express-validator": "^6.14.2",
|
67
69
|
"fast-csv": "^4.3.6",
|
@@ -27,6 +27,12 @@ class Listener {
|
|
27
27
|
|
28
28
|
let baseFileUrl = process.env.BASE_FILE_URL || apiUrl || "http://localhost:3000"
|
29
29
|
|
30
|
+
let job_topic = process.env.JOB_TOPIC_EXCHANGE;
|
31
|
+
winston.debug("Whatsapp job topic " + job_topic);
|
32
|
+
|
33
|
+
let amqp_manager_url = process.env.AMQP_MANAGER_URL;
|
34
|
+
winston.debug("amqp_manager_url " + amqp_manager_url);
|
35
|
+
|
30
36
|
let log = process.env.WHATSAPP_LOG || false
|
31
37
|
winston.debug("Whatsapp log: "+ log);
|
32
38
|
|
@@ -40,6 +46,8 @@ class Listener {
|
|
40
46
|
REDIS_HOST: host,
|
41
47
|
REDIS_PORT: port,
|
42
48
|
REDIS_PASSWORD: password,
|
49
|
+
AMQP_MANAGER_URL: amqp_manager_url,
|
50
|
+
JOB_TOPIC_EXCHANGE: job_topic,
|
43
51
|
log: log
|
44
52
|
}, (err) => {
|
45
53
|
if (!err) {
|
package/routes/auth.js
CHANGED
@@ -33,18 +33,33 @@ if (pKey) {
|
|
33
33
|
configSecret = pKey.replace(/\\n/g, '\n');
|
34
34
|
}
|
35
35
|
|
36
|
+
var recaptcha = require('../middleware/recaptcha');
|
37
|
+
|
38
|
+
|
39
|
+
|
36
40
|
// const fs = require('fs');
|
37
41
|
// var configSecret = fs.readFileSync('private.key');
|
38
42
|
|
39
43
|
|
40
44
|
router.post('/signup',
|
41
|
-
[
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
45
|
+
[
|
46
|
+
check('email').isEmail(),
|
47
|
+
check('firstname').notEmpty(),
|
48
|
+
check('lastname').notEmpty(),
|
49
|
+
recaptcha
|
50
|
+
|
51
|
+
]
|
52
|
+
// recaptcha.middleware.verify
|
53
|
+
|
46
54
|
, function (req, res) {
|
47
55
|
|
56
|
+
// if (!req.recaptcha.error) {
|
57
|
+
// winston.error("Signup recaptcha ok");
|
58
|
+
// } else {
|
59
|
+
// // error code
|
60
|
+
// winston.error("Signup recaptcha ko");
|
61
|
+
// }
|
62
|
+
|
48
63
|
const errors = validationResult(req);
|
49
64
|
if (!errors.isEmpty()) {
|
50
65
|
winston.error("Signup validation error", errors);
|
@@ -210,6 +225,7 @@ router.post('/signinWithCustomToken', [
|
|
210
225
|
|
211
226
|
var id_project;
|
212
227
|
|
228
|
+
let userToReturn = req.user;
|
213
229
|
|
214
230
|
var role = RoleConstants.USER;
|
215
231
|
|
@@ -264,12 +280,41 @@ router.post('/signinWithCustomToken', [
|
|
264
280
|
|
265
281
|
|
266
282
|
Project_user.findOne({ id_project: id_project, uuid_user: req.user._id, role: role}).
|
267
|
-
exec(
|
283
|
+
exec(async (err, project_user) => {
|
268
284
|
if (err) {
|
269
285
|
winston.error(err);
|
270
286
|
return res.json({ success: true, token: req.headers["authorization"], user: req.user });
|
271
287
|
}
|
272
288
|
if (!project_user) {
|
289
|
+
|
290
|
+
let createNewUser = false;
|
291
|
+
winston.debug('role: '+ role)
|
292
|
+
|
293
|
+
|
294
|
+
if (role === RoleConstants.OWNER || role === RoleConstants.ADMIN || role === RoleConstants.AGENT) {
|
295
|
+
createNewUser = true;
|
296
|
+
|
297
|
+
var newUser;
|
298
|
+
try {
|
299
|
+
newUser = await userService.signup(req.user.email, uuidv4(), req.user.firstname, req.user.lastname, false);
|
300
|
+
} catch(e) {
|
301
|
+
winston.debug('error signup already exists??: ')
|
302
|
+
|
303
|
+
if (e.code = "E11000") {
|
304
|
+
newUser = await User.findOne({email: req.user.email , status: 100}).exec();
|
305
|
+
winston.debug('signup found')
|
306
|
+
|
307
|
+
}
|
308
|
+
}
|
309
|
+
|
310
|
+
if (!newUser) {
|
311
|
+
return res.status(401).send({ success: false, msg: 'User not found.' });
|
312
|
+
}
|
313
|
+
|
314
|
+
winston.debug('userToReturn forced to newUser.', newUser)
|
315
|
+
userToReturn=newUser;
|
316
|
+
}
|
317
|
+
|
273
318
|
var newProject_user = new Project_user({
|
274
319
|
|
275
320
|
id_project: id_project,
|
@@ -281,29 +326,60 @@ router.post('/signinWithCustomToken', [
|
|
281
326
|
updatedBy: req.user._id
|
282
327
|
});
|
283
328
|
|
329
|
+
// testtare qiestp cpm dpcker dev partemdp da ui
|
330
|
+
if (createNewUser===true) {
|
331
|
+
newProject_user.id_user = newUser._id;
|
332
|
+
// delete newProject_user.uuid_user;
|
333
|
+
winston.debug('newProject_user.', newProject_user)
|
334
|
+
}
|
335
|
+
|
284
336
|
return newProject_user.save(function (err, savedProject_user) {
|
285
337
|
if (err) {
|
286
338
|
winston.error('Error saving object.', err)
|
287
339
|
// return res.status(500).send({ success: false, msg: 'Error saving object.' });
|
288
|
-
return res.json({ success: true, token: req.headers["authorization"], user:
|
340
|
+
return res.json({ success: true, token: req.headers["authorization"], user: userToReturn});
|
289
341
|
}
|
290
342
|
|
291
343
|
|
292
344
|
authEvent.emit("projectuser.create", savedProject_user);
|
293
345
|
|
294
|
-
authEvent.emit("user.signin", {user:
|
346
|
+
authEvent.emit("user.signin", {user:userToReturn, req:req, token: req.headers["authorization"]});
|
295
347
|
|
296
348
|
winston.debug('project user created ', savedProject_user.toObject());
|
297
349
|
|
350
|
+
|
351
|
+
let returnToken = req.headers["authorization"];
|
352
|
+
if (createNewUser===true) {
|
353
|
+
|
354
|
+
|
355
|
+
|
356
|
+
var signOptions = {
|
357
|
+
issuer: 'https://tiledesk.com',
|
358
|
+
subject: 'user',
|
359
|
+
audience: 'https://tiledesk.com',
|
360
|
+
jwtid: uuidv4()
|
361
|
+
};
|
362
|
+
|
363
|
+
var alg = process.env.GLOBAL_SECRET_ALGORITHM;
|
364
|
+
if (alg) {
|
365
|
+
signOptions.algorithm = alg;
|
366
|
+
}
|
367
|
+
|
368
|
+
//remove password //test it
|
369
|
+
let userJson = userToReturn.toObject();
|
370
|
+
delete userJson.password;
|
371
|
+
|
372
|
+
returnToken = jwt.sign(userJson, configSecret, signOptions); //priv_jwt pp_jwt
|
298
373
|
|
374
|
+
}
|
299
375
|
|
300
|
-
return res.json({ success: true, token:
|
376
|
+
return res.json({ success: true, token: 'JWT ' + returnToken, user: userToReturn });
|
301
377
|
});
|
302
378
|
} else {
|
303
379
|
winston.debug('project user already exists ');
|
304
380
|
|
305
381
|
if (project_user.status==="active") {
|
306
|
-
return res.json({ success: true, token: req.headers["authorization"], user:
|
382
|
+
return res.json({ success: true, token: req.headers["authorization"], user: userToReturn });
|
307
383
|
} else {
|
308
384
|
winston.warn('Authentication failed. Project_user not active.');
|
309
385
|
return res.status(401).send({ success: false, msg: 'Authentication failed. Project_user not active.' });
|
package/routes/message.js
CHANGED
@@ -122,7 +122,7 @@ async (req, res) => {
|
|
122
122
|
winston.debug("queryProjectUser", queryProjectUser);
|
123
123
|
|
124
124
|
project_user = await Project_user.findOne(queryProjectUser).populate({path:'id_user', select:{'firstname':1, 'lastname':1, 'email':1}})
|
125
|
-
winston.
|
125
|
+
winston.debug("project_user", project_user);
|
126
126
|
|
127
127
|
if (!project_user) {
|
128
128
|
return res.status(403).send({success: false, msg: 'Unauthorized. Project_user not found with user id : '+ sender });
|
@@ -177,7 +177,8 @@ async (req, res) => {
|
|
177
177
|
channel: req.body.channel,
|
178
178
|
location: req.body.location,
|
179
179
|
participants: req.body.participants,
|
180
|
-
lead: createdLead,
|
180
|
+
lead: createdLead,
|
181
|
+
requester: project_user,
|
181
182
|
priority: req.body.priority,
|
182
183
|
followers: req.body.followers,
|
183
184
|
};
|
@@ -32,7 +32,7 @@ class Segment2MongoConverter {
|
|
32
32
|
//console.log('Operator >=');
|
33
33
|
this.convertGreaterThanOrEqualOperatorFilter(condition, filter);
|
34
34
|
break;
|
35
|
-
case '
|
35
|
+
case 'starts with':
|
36
36
|
//console.log('Operator >=');
|
37
37
|
this.convertStarsWithOperatorFilter(condition, filter);
|
38
38
|
break;
|