@tiledesk/tiledesk-server 2.4.40 → 2.4.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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.40",
4
+ "version": "2.4.42",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
@@ -44,8 +44,8 @@
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",
48
- "@tiledesk/tiledesk-whatsapp-connector": "^0.1.50",
47
+ "@tiledesk/tiledesk-tybot-connector": "^0.1.91",
48
+ "@tiledesk/tiledesk-whatsapp-connector": "^0.1.51",
49
49
  "amqplib": "^0.5.5",
50
50
  "app-root-path": "^3.0.0",
51
51
  "bcrypt-nodejs": "0.0.3",
package/routes/faq.js CHANGED
@@ -28,7 +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
- console.log("--> csv: ", csv)
31
+ winston.debug("--> csv: ", csv)
32
32
  // winston.debug(' -> CSV STRING ', csv);
33
33
 
34
34
  // res.json({ success: true, msg: 'Importing CSV...' });
@@ -52,7 +52,7 @@ router.post('/uploadcsv', upload.single('uploadFile'), function (req, res, next)
52
52
  .on("data", function (data) {
53
53
  winston.debug('PARSED CSV ', data);
54
54
 
55
- console.log('--> PARSED CSV ', data);
55
+ winston.debug('--> PARSED CSV ', data);
56
56
 
57
57
  var question = data[0]
58
58
  //var answer = data[1]
@@ -107,7 +107,7 @@ router.post('/uploadcsv', upload.single('uploadFile'), function (req, res, next)
107
107
  updatedBy: req.user.id
108
108
  });
109
109
 
110
- console.log("--> newFaq: ", JSON.stringify(newFaq, null, 2));
110
+ winston.debug("--> newFaq: ", JSON.stringify(newFaq, null, 2));
111
111
 
112
112
  newFaq.save(function (err, savedFaq) {
113
113
  if (err) {
@@ -199,7 +199,7 @@ router.post('/', function (req, res) {
199
199
 
200
200
  router.patch('/:faqid/attributes', function (req, res) {
201
201
  let data = req.body;
202
- console.log("data: ", data);
202
+ winston.debug("data: ", data);
203
203
 
204
204
  Faq.findById(req.params.faqid, function (err, updatedFaq) {
205
205
  if (err) {
@@ -212,7 +212,7 @@ router.patch('/:faqid/attributes', function (req, res) {
212
212
  }
213
213
 
214
214
  if (!updatedFaq.attributes) {
215
- console.log("empty attributes");
215
+ winston.debug("empty attributes");
216
216
  winston.debug("empty attributes");
217
217
  updatedFaq.attributes = {};
218
218
  }
@@ -225,8 +225,8 @@ router.patch('/:faqid/attributes', function (req, res) {
225
225
  updatedFaq.attributes[key] = val;
226
226
  })
227
227
 
228
- console.log("updatedFaq: ", updatedFaq);
229
- console.log("updatedFaq attributes: ", updatedFaq.attributes);
228
+ winston.debug("updatedFaq: ", updatedFaq);
229
+ winston.debug("updatedFaq attributes: ", updatedFaq.attributes);
230
230
 
231
231
  winston.debug("updatedBot attributes", updatedFaq.attributes)
232
232
 
@@ -239,7 +239,7 @@ router.patch('/:faqid/attributes', function (req, res) {
239
239
  return res.status(500).send({ success: false, msg: 'Error saving object.' });
240
240
  }
241
241
 
242
- console.log("saved faq attributes", savedFaq.toObject());
242
+ winston.debug("saved faq attributes", savedFaq.toObject());
243
243
 
244
244
  winston.verbose("saved faq attributes", savedFaq.toObject());
245
245
  faqBotEvent.emit('faq.update', savedFaq);
package/routes/faq_kb.js CHANGED
@@ -363,7 +363,6 @@ router.put('/:faq_kbid/language/:language', (req, res) => {
363
363
  botEvent.emit('faqbot.update', updatedFaq_kb);
364
364
  return res.status(500).send({ success: false, msg: 'Error updating multiple object.' });
365
365
  }
366
- console.log("updateMany intents result: ", result)
367
366
  return res.status(200).send(updatedFaq_kb)
368
367
  })
369
368
 
@@ -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