@tiledesk/tiledesk-server 2.4.77 → 2.4.79-rc1

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,19 @@
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
+
18
+ # 2.4.77
19
+ - update tybot-connector to 0.2.26
20
+
8
21
  # 2.4.76
9
22
  - update tybot-connector to 0.2.25
10
23
  - update redirectToDesktop email for new onboarding
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
@@ -1,5 +1,5 @@
1
1
  git pull
2
- npm version patch
2
+ #npm version patch
3
3
  version=`node -e 'console.log(require("./package.json").version)'`
4
4
  echo "version $version"
5
5
 
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.77",
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-messenger-connector": "^0.1.13",
45
46
  "@tiledesk/tiledesk-rasa-connector": "^1.0.10",
46
- "@tiledesk/tiledesk-tybot-connector": "^0.2.26",
47
- "@tiledesk/tiledesk-whatsapp-connector": "^0.1.52",
48
- "@tiledesk/tiledesk-messenger-connector": "^0.1.12",
49
- "@tiledesk/tiledesk-telegram-connector": "^0.1.9",
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
- check('email').isEmail(),
43
- check('firstname').notEmpty(),
44
- check('lastname').notEmpty()
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(function (err, project_user) {
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: req.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:req.user, req:req, token: req.headers["authorization"]});
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: req.headers["authorization"], user: req.user });
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: req.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.info("project_user", project_user);
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, requester: project_user,
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 'stars with':
35
+ case 'starts with':
36
36
  //console.log('Operator >=');
37
37
  this.convertStarsWithOperatorFilter(condition, filter);
38
38
  break;