@tiledesk/tiledesk-server 2.4.41 → 2.4.43

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -5,9 +5,22 @@
5
5
  🚀 IN PRODUCTION 🚀
6
6
  (https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77)
7
7
 
8
+
9
+ # 2.4.42
10
+ - createIfNotExistsWithLeadId now update the lead email if jwt email changes
11
+
12
+ # 2.4.41
13
+ - Whatsapp updates
14
+
15
+ # 2.4.40
16
+ - botSubscriptionNotifier and botEvent queued disabled
17
+ - added lead.create to the queue
18
+ - queued scheduler (close chat)
19
+ - added chat21 channel, cache, rules
20
+
8
21
  # 2.4.39
9
22
  - Queued botSubscriptionNotifier
10
- - added lead.create to the queue????? testare di nuovo
23
+ - added lead.create to the queue
11
24
  - @tiledesk/tiledesk-tybot-connector: 0.1.89
12
25
  - jobsManager.listen(); //listen after pubmodules to enabled queued *.queueEnabled events
13
26
 
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.41",
4
+ "version": "2.4.43",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
@@ -44,7 +44,7 @@
44
44
  "@tiledesk/tiledesk-kaleyra-proxy": "^0.1.7",
45
45
  "@tiledesk/tiledesk-messenger-connector": "0.1.9",
46
46
  "@tiledesk/tiledesk-rasa-connector": "^1.0.10",
47
- "@tiledesk/tiledesk-tybot-connector": "^0.1.89",
47
+ "@tiledesk/tiledesk-tybot-connector": "^0.1.91",
48
48
  "@tiledesk/tiledesk-whatsapp-connector": "^0.1.51",
49
49
  "amqplib": "^0.5.5",
50
50
  "app-root-path": "^3.0.0",
package/routes/auth.js CHANGED
@@ -458,13 +458,23 @@ function (req, res) {
458
458
 
459
459
  // http://localhost:3000/auth/google?redirect_url=%2F%23%2Fproject%2F6452281f6d68c5f419c1c577%2Fhome
460
460
 
461
+ // http://localhost:3000/auth/google?redirect_url=%23%2Fcreate-project-gs
461
462
 
463
+ // http://localhost:3000/auth/google?forced_redirect_url=https%3A%2F%2Fpanel.tiledesk.com%2Fv3%2Fchat%2F%23conversation-detail%3Ffrom%3Dgoogle
464
+
465
+ // https://tiledesk-server-pre.herokuapp.com/auth/google?redirect_url=%23%2Fcreate-project-gs
466
+
467
+ // https://tiledesk-server-pre.herokuapp.com/auth/google
462
468
 
463
469
  // Redirect the user to the Google signin page</em>
464
470
  // router.get("/google", passport.authenticate("google", { scope: ["email", "profile"] }));
465
471
  router.get("/google", function(req,res,next){
466
472
  winston.info("redirect_url: "+ req.query.redirect_url );
467
473
  req.session.redirect_url = req.query.redirect_url;
474
+
475
+ winston.info("forced_redirect_url: "+ req.query.forced_redirect_url );
476
+ req.session.forced_redirect_url = req.query.forced_redirect_url;
477
+
468
478
  // req._toParam = 'Hello';
469
479
  passport.authenticate(
470
480
  // 'google', { scope : ["email", "profile"], state: base64url(JSON.stringify({blah: 'text'})) } //custom redirect_url req.query.state
@@ -487,7 +497,7 @@ router.get("/google/callback", passport.authenticate("google", { session: false
487
497
  // winston.info("req._toParam: "+ req._toParam);
488
498
  // winston.info("req.query.redirect_url: "+ req.query.redirect_url);
489
499
  // winston.info("req.query.state: "+ req.query.state);
490
- winston.info("req.session.redirect_url: "+ req.session.redirect_url);
500
+ winston.debug("req.session.redirect_url: "+ req.session.redirect_url);
491
501
 
492
502
 
493
503
  var userJson = user.toObject();
@@ -526,6 +536,9 @@ router.get("/google/callback", passport.authenticate("google", { session: false
526
536
 
527
537
  var url = dashboard_base_url+homeurl+"?token=JWT "+token;
528
538
 
539
+ if (req.session.forced_redirect_url) {
540
+ url = req.session.forced_redirect_url+"&token=JWT "+token;
541
+ }
529
542
 
530
543
  winston.info("Google Redirect: "+ url);
531
544
 
package/routes/faq.js CHANGED
@@ -28,6 +28,7 @@ router.post('/uploadcsv', upload.single('uploadFile'), function (req, res, next)
28
28
  winston.debug('delimiter: ' + delimiter);
29
29
 
30
30
  var csv = req.file.buffer.toString('utf8');
31
+ winston.debug("--> csv: ", csv)
31
32
  // winston.debug(' -> CSV STRING ', csv);
32
33
 
33
34
  // res.json({ success: true, msg: 'Importing CSV...' });
@@ -51,6 +52,8 @@ router.post('/uploadcsv', upload.single('uploadFile'), function (req, res, next)
51
52
  .on("data", function (data) {
52
53
  winston.debug('PARSED CSV ', data);
53
54
 
55
+ winston.debug('--> PARSED CSV ', data);
56
+
54
57
  var question = data[0]
55
58
  //var answer = data[1]
56
59
  var intent_id = data[2];
@@ -104,6 +107,8 @@ router.post('/uploadcsv', upload.single('uploadFile'), function (req, res, next)
104
107
  updatedBy: req.user.id
105
108
  });
106
109
 
110
+ winston.debug("--> newFaq: ", JSON.stringify(newFaq, null, 2));
111
+
107
112
  newFaq.save(function (err, savedFaq) {
108
113
  if (err) {
109
114
  winston.error('--- > ERROR uploadcsv', err)
@@ -194,6 +199,7 @@ router.post('/', function (req, res) {
194
199
 
195
200
  router.patch('/:faqid/attributes', function (req, res) {
196
201
  let data = req.body;
202
+ winston.debug("data: ", data);
197
203
 
198
204
  Faq.findById(req.params.faqid, function (err, updatedFaq) {
199
205
  if (err) {
@@ -206,6 +212,7 @@ router.patch('/:faqid/attributes', function (req, res) {
206
212
  }
207
213
 
208
214
  if (!updatedFaq.attributes) {
215
+ winston.debug("empty attributes");
209
216
  winston.debug("empty attributes");
210
217
  updatedFaq.attributes = {};
211
218
  }
@@ -218,6 +225,9 @@ router.patch('/:faqid/attributes', function (req, res) {
218
225
  updatedFaq.attributes[key] = val;
219
226
  })
220
227
 
228
+ winston.debug("updatedFaq: ", updatedFaq);
229
+ winston.debug("updatedFaq attributes: ", updatedFaq.attributes);
230
+
221
231
  winston.debug("updatedBot attributes", updatedFaq.attributes)
222
232
 
223
233
  updatedFaq.markModified('attributes');
@@ -229,6 +239,8 @@ router.patch('/:faqid/attributes', function (req, res) {
229
239
  return res.status(500).send({ success: false, msg: 'Error saving object.' });
230
240
  }
231
241
 
242
+ winston.debug("saved faq attributes", savedFaq.toObject());
243
+
232
244
  winston.verbose("saved faq attributes", savedFaq.toObject());
233
245
  faqBotEvent.emit('faq.update', savedFaq);
234
246
  res.json(savedFaq);
@@ -5,6 +5,7 @@ const uuidv4 = require('uuid/v4');
5
5
  const leadEvent = require('../event/leadEvent');
6
6
  var winston = require('../config/winston');
7
7
  var cacheUtil = require('../utils/cacheUtil');
8
+ var cacheEnabler = require("../services/cacheEnabler");
8
9
 
9
10
 
10
11
  class LeadService {
@@ -67,8 +68,18 @@ class LeadService {
67
68
  if (!lead) {
68
69
  return resolve(that.createWitId(lead_id, fullname, email, id_project, createdBy, attributes, status));
69
70
  }
70
- winston.debug("lead already exists createIfNotExistsWithLeadId");
71
- return resolve(lead);
71
+
72
+ winston.debug("lead.email: " + lead.email);
73
+ winston.debug("email: " + email);
74
+
75
+ if (lead.email == email) {
76
+ winston.debug("lead already exists createIfNotExistsWithLeadId with the same email");
77
+ return resolve(lead);
78
+ } else {
79
+ winston.debug("lead already exists createIfNotExistsWithLeadId but with different email");
80
+ return resolve(that.updateWitId(lead_id, fullname, email, id_project, status));
81
+ }
82
+
72
83
 
73
84
  });
74
85
  });
@@ -101,7 +112,7 @@ class LeadService {
101
112
  }
102
113
 
103
114
  updateWitId(lead_id, fullname, email, id_project, status) {
104
- winston.debug("lead_id: "+ lead_id);
115
+ winston.debug("updateWitId lead_id: "+ lead_id);
105
116
  winston.debug("fullname: "+ fullname);
106
117
  winston.debug("email: "+ email);
107
118
  winston.debug("id_project: "+ id_project);
@@ -1431,11 +1431,183 @@ describe('/SendMessageSigninWithCustomToken', () => {
1431
1431
 
1432
1432
  });
1433
1433
 
1434
+
1435
+
1436
+
1437
+
1438
+
1439
+ // mocha test/messageRoute.js --grep 'sendMessageSigninWithCustomTokenModified'
1440
+
1441
+ it('sendMessageSigninWithCustomTokenModified', (done) => {
1442
+
1443
+
1444
+ var email = "test-sendmessagesigninwithcustomtokenModified-" + Date.now() + "@email.com";
1445
+ var pwd = "pwd";
1446
+
1447
+ userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
1448
+ // create(name, createdBy, settings)
1449
+ projectService.create("test-sendMessageSigninWithCustomTokenModified", savedUser._id).then(function(savedProject) {
1450
+
1451
+ chai.request(server)
1452
+ .post('/'+ savedProject._id + '/keys/generate')
1453
+ .auth(email, pwd)
1454
+ .send()
1455
+ .end((err, res) => {
1456
+ //console.log("res", res);
1457
+ console.log("res.body", res.body);
1458
+ res.should.have.status(200);
1459
+ res.body.should.be.a('object');
1460
+ expect(res.body.jwtSecret).to.not.equal(null);
1461
+
1462
+ // 'E11000 duplicate key error collection: tiledesk-test.users index: email_1 dup key: { email: "email@email.com" }' }
1463
+ var externalUserId = "123";
1464
+ var externalUserObj = {_id: externalUserId, firstname:"andrea", lastname:"leo", email: "email2@email.com"};
1465
+
1466
+ console.log("externalUserObj", externalUserObj);
1467
+
1468
+
1469
+ var signOptions = {
1470
+ subject: 'userexternal',
1471
+ audience: 'https://tiledesk.com/projects/'+savedProject._id ,
1472
+ };
1473
+
1474
+
1475
+ var secret = res.body.jwtSecret;
1476
+ var jwtToken = jwt.sign(externalUserObj, res.body.jwtSecret,signOptions);
1477
+
1478
+ console.log("jwtToken", jwtToken);
1479
+
1480
+
1481
+ chai.request(server)
1482
+ .post('/auth/signinWithCustomToken' )
1483
+ .set('Authorization', 'JWT '+jwtToken)
1484
+ //.send({ id_project: savedProject._id})
1485
+ .send()
1486
+ .end((err, res) => {
1487
+ //console.log("res", res);
1488
+ console.log("res.body", res.body);
1489
+ res.should.have.status(200);
1490
+ res.body.should.be.a('object');
1491
+ expect(res.body.success).to.equal(true);
1492
+ expect(res.body.user.email).to.equal("email2@email.com");
1493
+ expect(res.body.user.firstname).to.equal("andrea");
1494
+
1495
+ expect(res.body.token).to.not.equal(undefined);
1496
+ expect(res.body.token).to.equal('JWT '+jwtToken);
1497
+
1498
+
1499
+ chai.request(server)
1500
+ .post('/'+ savedProject._id + '/requests/sendMessageSigninWithCustomTokenModified/messages')
1501
+ .set('Authorization', 'JWT '+jwtToken)
1502
+ .set('content-type', 'application/json')
1503
+ .send({"text":"text"})
1504
+ .end(function(err, res) {
1505
+ //console.log("res", res);
1506
+ console.log("res.body", res.body);
1507
+ res.should.have.status(200);
1508
+ res.body.should.be.a('object');
1509
+
1510
+ expect(res.body.sender).to.equal(externalUserId);
1511
+ // expect(res.body.sender).to.equal(savedProjectAndPU.project_user._id.toString());
1512
+ // expect(res.body.senderFullname).to.equal("senderFullname");
1513
+ expect(res.body.recipient).to.equal("sendMessageSigninWithCustomTokenModified");
1514
+ expect(res.body.text).to.equal("text");
1515
+ expect(res.body.id_project).to.equal(savedProject._id.toString());
1516
+ expect(res.body.createdBy).to.equal(externalUserId);
1517
+ expect(res.body.status).to.equal(0);
1518
+
1519
+ expect(res.body.request.request_id).to.equal("sendMessageSigninWithCustomTokenModified");
1520
+ expect(res.body.request.first_text).to.equal("text");
1521
+ expect(res.body.request.id_project).to.equal(savedProject._id.toString());
1522
+ expect(res.body.request.createdBy).to.equal(externalUserId);
1523
+
1524
+ // expect(res.body.request.messages_count).to.equal(1);
1525
+
1526
+ expect(res.body.request.status).to.equal(200);
1527
+ expect(res.body.request.snapshot.agents.length).to.equal(1);
1528
+ expect(res.body.request.participants.length).to.equal(1);
1529
+ expect(res.body.request.department).to.not.equal(null);
1530
+ expect(res.body.request.lead).to.not.equal(null);
1531
+ expect(res.body.request.lead.email).to.equal("email2@email.com");
1532
+
1533
+
1534
+ chai.request(server)
1535
+ .get('/'+ savedProject._id + '/requests/sendMessageSigninWithCustomTokenModified')
1536
+ .auth(email, pwd)
1537
+ .set('content-type', 'application/json')
1538
+ .end(function(err, res) {
1539
+ //console.log("res", res);
1540
+ console.log("res.body", res.body);
1541
+ expect(res.body.lead.lead_id).to.equal(externalUserId);
1542
+ expect(res.body.lead.email).to.equal("email2@email.com");
1543
+ expect(res.body.lead.fullname).to.equal("andrea leo");
1544
+ expect(res.body.requester.role).to.equal("user");
1545
+ expect(res.body.requester.uuid_user).to.equal(externalUserId);
1546
+ expect(res.body.requester.id_user).to.equal(undefined);
1547
+
1548
+
1549
+
1550
+
1551
+ externalUserObj.email = "email33@email.com";
1552
+
1553
+ jwtToken = jwt.sign(externalUserObj,secret, signOptions);
1554
+ console.log("jwtToken2", jwtToken);
1555
+
1556
+ chai.request(server)
1557
+ .post('/auth/signinWithCustomToken' )
1558
+ .set('Authorization', 'JWT '+jwtToken)
1559
+ //.send({ id_project: savedProject._id})
1560
+ .send()
1561
+ .end((err, res) => {
1562
+ //console.log("res", res);
1563
+ console.log("res.body", res.body);
1564
+ res.should.have.status(200);
1565
+ res.body.should.be.a('object');
1566
+ expect(res.body.success).to.equal(true);
1567
+ expect(res.body.user.email).to.equal("email33@email.com");
1568
+ expect(res.body.user.firstname).to.equal("andrea");
1569
+
1570
+ chai.request(server)
1571
+ .post('/'+ savedProject._id + '/requests/sendMessageSigninWithCustomTokenModified33/messages')
1572
+ .set('Authorization', 'JWT '+jwtToken)
1573
+ .set('content-type', 'application/json')
1574
+ .send({"text":"text"})
1575
+ .end(function(err, res) {
1576
+ //console.log("res", res);
1577
+ console.log("res.body", res.body);
1578
+ res.should.have.status(200);
1579
+ res.body.should.be.a('object');
1580
+
1581
+ expect(res.body.request.lead.email).to.equal("email33@email.com");
1582
+ done()
1583
+
1584
+
1585
+ });
1586
+
1587
+
1588
+ });
1589
+
1590
+
1591
+ });
1592
+
1593
+ });
1594
+ });
1595
+ });
1596
+ });
1597
+ });
1598
+
1434
1599
  });
1435
1600
 
1436
1601
 
1437
1602
 
1438
1603
 
1604
+ });
1605
+
1606
+
1607
+
1608
+
1609
+
1610
+
1439
1611
 
1440
1612
  // mocha test/messageRoute.js --grep 'sendMessageSigninAnonym'
1441
1613