@tiledesk/tiledesk-server 2.3.126 β 2.3.128
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 +120 -1
- package/middleware/passport.js +133 -6
- package/models/profile.js +9 -0
- package/package.json +2 -2
- package/routes/auth.js +50 -0
- package/routes/email.js +270 -0
- package/services/emailService.js +114 -30
package/CHANGELOG.md
CHANGED
@@ -5,7 +5,126 @@
|
|
5
5
|
π IN PRODUCTION π
|
6
6
|
(https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77)
|
7
7
|
|
8
|
-
|
8
|
+
|
9
|
+
|
10
|
+
# 2.3.127
|
11
|
+
- Added Google OAuth Strategy
|
12
|
+
- tiledesk/tiledesk-tybot-connector": "^0.1.76
|
13
|
+
|
14
|
+
|
15
|
+
# 2.3.126
|
16
|
+
- removed secret from faq_kb cache before caching
|
17
|
+
- removed description and attributes from chabot subscription notifier to reduce the payload size
|
18
|
+
|
19
|
+
# 2.3.125
|
20
|
+
- @tiledesk/tiledesk-tybot-connector@0.1.74
|
21
|
+
|
22
|
+
# 2.3.124
|
23
|
+
- tiledesk/tiledesk-messenger-connector 0.1.8
|
24
|
+
|
25
|
+
# 2.3.123
|
26
|
+
- tiledesk/tiledesk-messenger-connector 0.1.7
|
27
|
+
|
28
|
+
# 2.3.122
|
29
|
+
- new stripe
|
30
|
+
- Updated dependency @tiledesk/tiledesk-tybot-connector to 0.1.73
|
31
|
+
|
32
|
+
# 2.3.121
|
33
|
+
- trial period to 14 days
|
34
|
+
- tiledesk-ent/tiledesk-server-payments: 1.1.9 with new stripe plan
|
35
|
+
- Updated dependency @tiledesk/tiledesk-tybot-connector to 0.1.72
|
36
|
+
|
37
|
+
# 2.3.120
|
38
|
+
- ocf fix
|
39
|
+
|
40
|
+
# 2.3.119
|
41
|
+
- Updated dependency @tiledesk/tiledesk-tybot-connector to 0.1.71
|
42
|
+
|
43
|
+
# 2.3.118
|
44
|
+
- tiledesk/tiledesk-messenger-connector 0.1.3
|
45
|
+
|
46
|
+
# 2.3.117
|
47
|
+
- Updated dependency @tiledesk/tiledesk-tybot-connector to 0.1.70
|
48
|
+
|
49
|
+
# 2.3.116
|
50
|
+
- tiledesk/tiledesk-dialogflow-connector": "^1.8.4",
|
51
|
+
|
52
|
+
# 2.3.115
|
53
|
+
- github action fix
|
54
|
+
|
55
|
+
# 2.3.113
|
56
|
+
- tiledesk-ent/tiledesk-server-payments: 1.1.7 with new stripe plan
|
57
|
+
- Updated dependency @tiledesk/tiledesk-tybot-connector to 0.1.68
|
58
|
+
- tiledesk-whatsapp-connector 0.1.41
|
59
|
+
|
60
|
+
# 2.3.112
|
61
|
+
- fb messenger fix
|
62
|
+
|
63
|
+
# 2.3.111
|
64
|
+
- Updated dependency @tiledesk/tiledesk-tybot-connector to 0.1.67
|
65
|
+
- facebook messenger plugin added
|
66
|
+
|
67
|
+
# 2.3.110
|
68
|
+
- websocket fix ATTENTION change value by reference
|
69
|
+
- Bugfix: Cannot read property 'toString' of undefined at /usr/src/app/services/requestService.js:404
|
70
|
+
- Updated tiledesk/tiledesk-whatsapp-connector 0.1.40
|
71
|
+
- Implmented request /agent endpoint (also support request with empty deparment generated by direct agent/bot assignment with participants field)
|
72
|
+
- fixed bug: fields webhook_enabled and webhook_url was ignored on βpublishβ
|
73
|
+
|
74
|
+
# 2.3.109
|
75
|
+
- Added support gif mimetype for image endpoint
|
76
|
+
|
77
|
+
# 2.3.108
|
78
|
+
- BugFix Chat21 event emitter listener changes request attributes values by reference
|
79
|
+
- Restored populate for message endpoint
|
80
|
+
- Test attributes send message
|
81
|
+
|
82
|
+
# 2.3.107
|
83
|
+
- bugfix execPopulate message endpoint wrong attributes
|
84
|
+
- Dependency updated tiledesk-whatsapp-connector 0.1.39
|
85
|
+
|
86
|
+
|
87
|
+
# 2.3.106
|
88
|
+
@tiledesk/tiledesk-tybot-connector 0.1.63
|
89
|
+
{{dateFormat request.createdAt \"DD/MM/YYYY HH:mm:ss\"}}
|
90
|
+
# 2.3.105
|
91
|
+
- tiledesk/tiledesk-apps: 1.0.14
|
92
|
+
|
93
|
+
# 2.3.104
|
94
|
+
- apps module auth fix
|
95
|
+
|
96
|
+
# 2.3.103
|
97
|
+
- Fix image not found bug
|
98
|
+
|
99
|
+
# 2.3.102
|
100
|
+
- Fix image not found bug
|
101
|
+
|
102
|
+
# 2.3.101
|
103
|
+
- created property entity and endpoint
|
104
|
+
- JSON_BODY_LIMIT env variable fix
|
105
|
+
|
106
|
+
# 2.3.100
|
107
|
+
- added filter by tags for lead endpoint
|
108
|
+
|
109
|
+
# 2.3.99
|
110
|
+
- tags field changed to flat object
|
111
|
+
|
112
|
+
# 2.3.98
|
113
|
+
- Ocf fix
|
114
|
+
|
115
|
+
# 2.3.97
|
116
|
+
- Updated dependency @tiledesk/tiledesk-tybot-connector to 0.1.62
|
117
|
+
|
118
|
+
# 2.3.96
|
119
|
+
- image endpoint set content type and length headers
|
120
|
+
|
121
|
+
# 2.3.95
|
122
|
+
- Bugfix when a conversation has a first_text with \agent
|
123
|
+
|
124
|
+
# 2.3.94
|
125
|
+
- log fix
|
126
|
+
|
127
|
+
# 2.3.93
|
9
128
|
- subscriptionNotifier secret fix
|
10
129
|
|
11
130
|
# 2.3.92
|
package/middleware/passport.js
CHANGED
@@ -4,6 +4,7 @@ var ExtractJwt = passportJWT.ExtractJwt;
|
|
4
4
|
|
5
5
|
var passportHttp = require("passport-http");
|
6
6
|
var BasicStrategy = passportHttp.BasicStrategy;
|
7
|
+
var GoogleStrategy = require('passport-google-oidc');
|
7
8
|
|
8
9
|
var winston = require('../config/winston');
|
9
10
|
// var AnonymousStrategy = require('passport-anonymous').Strategy;
|
@@ -14,12 +15,19 @@ var config = require('../config/database'); // get db config file
|
|
14
15
|
var Faq_kb = require("../models/faq_kb");
|
15
16
|
var Project = require('../models/project');
|
16
17
|
var Subscription = require('../models/subscription');
|
18
|
+
|
19
|
+
var Auth = require('../models/auth');
|
20
|
+
var userService = require('../services/userService');
|
21
|
+
|
17
22
|
var UserUtil = require('../utils/userUtil');
|
18
23
|
var jwt = require('jsonwebtoken');
|
19
24
|
const url = require('url');
|
20
25
|
var cacheUtil = require('../utils/cacheUtil');
|
21
26
|
var cacheEnabler = require("../services/cacheEnabler");
|
22
27
|
|
28
|
+
var uniqid = require('uniqid');
|
29
|
+
|
30
|
+
|
23
31
|
const MaskData = require("maskdata");
|
24
32
|
|
25
33
|
const maskOptions = {
|
@@ -57,7 +65,11 @@ if (pKey) {
|
|
57
65
|
var maskedconfigSecret = MaskData.maskPhone(configSecret, maskOptions);
|
58
66
|
winston.info('Authentication Global Secret : ' + maskedconfigSecret);
|
59
67
|
|
60
|
-
|
68
|
+
var enableGoogleSignin = false;
|
69
|
+
if (process.env.GOOGLE_SIGNIN_ENABLED=="true" || process.env.GOOGLE_SIGNIN_ENABLED == true) {
|
70
|
+
enableGoogleSignin = true;
|
71
|
+
}
|
72
|
+
winston.info('Authentication Google Signin enabled : ' + enableGoogleSignin);
|
61
73
|
|
62
74
|
|
63
75
|
var jwthistory = undefined;
|
@@ -431,11 +443,126 @@ module.exports = function(passport) {
|
|
431
443
|
// if (!user) { return done(null, false); }
|
432
444
|
// if (!user.verifyPassword(password)) { return done(null, false); }
|
433
445
|
});
|
434
|
-
}
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
446
|
+
}));
|
447
|
+
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
|
452
|
+
if (enableGoogleSignin==true) {
|
453
|
+
let googleClientId = process.env.GOOGLE_CLIENT_ID;
|
454
|
+
let googleClientSecret = process.env.GOOGLE_CLIENT_SECRET;
|
455
|
+
let googleCallbackURL = process.env.GOOGLE_CALLBACK_URL || "http://localhost:3000/auth/google/callback";
|
456
|
+
|
457
|
+
winston.info("Enabling Google Signin strategy with ClientId: " + googleClientId + " callbackURL: " + googleCallbackURL + " clientSecret: " + googleClientSecret );
|
458
|
+
|
459
|
+
passport.use(new GoogleStrategy({
|
460
|
+
clientID: googleClientId,
|
461
|
+
clientSecret: googleClientSecret,
|
462
|
+
callbackURL: googleCallbackURL // 'https://www.example.com/oauth2/redirect/google'
|
463
|
+
},
|
464
|
+
function(issuer, profile, cb) {
|
465
|
+
|
466
|
+
winston.info("issuer: "+issuer)
|
467
|
+
winston.info("profile", profile)
|
468
|
+
// winston.info("cb", cb)
|
469
|
+
|
470
|
+
var email = profile.emails[0].value;
|
471
|
+
winston.info("email: "+email)
|
472
|
+
|
473
|
+
var query = {providerId : issuer, subject: profile.id};
|
474
|
+
winston.debug("query", query)
|
475
|
+
|
476
|
+
Auth.findOne(query, function(err, cred){
|
477
|
+
winston.debug("cred", cred, err)
|
478
|
+
|
479
|
+
// db.get('SELECT * FROM federated_credentials WHERE provider = ? AND subject = ?', [
|
480
|
+
// issuer,
|
481
|
+
// profile.id
|
482
|
+
// ], function(err, cred) {
|
483
|
+
|
484
|
+
winston.debug("11")
|
485
|
+
|
486
|
+
|
487
|
+
if (err) { return cb(err); }
|
488
|
+
|
489
|
+
winston.debug("12")
|
490
|
+
|
491
|
+
if (!cred) {
|
492
|
+
winston.debug("13")
|
493
|
+
// The Google account has not logged in to this app before. Create a
|
494
|
+
// new user record and link it to the Google account.
|
495
|
+
|
496
|
+
// db.run('INSERT INTO users (name) VALUES (?)', [
|
497
|
+
// profile.displayName
|
498
|
+
// ], function(err) {
|
499
|
+
|
500
|
+
var password = uniqid()
|
501
|
+
|
502
|
+
|
503
|
+
|
504
|
+
userService.signup(email, password, undefined, profile.displayName, true)
|
505
|
+
.then(function (savedUser) {
|
506
|
+
|
507
|
+
|
508
|
+
// if (err) { return cb(err); }
|
509
|
+
|
510
|
+
winston.debug("savedUser", savedUser)
|
511
|
+
|
512
|
+
var auth = new Auth({
|
513
|
+
providerId: issuer,
|
514
|
+
subject: profile.id,
|
515
|
+
});
|
516
|
+
auth.save(function (err, authSaved) {
|
517
|
+
|
518
|
+
// db.run('INSERT INTO federated_credentials (user_id, provider, subject) VALUES (?, ?, ?)', [
|
519
|
+
// id,
|
520
|
+
// issuer,
|
521
|
+
// profile.id
|
522
|
+
// ], function(err) {
|
523
|
+
|
524
|
+
|
525
|
+
if (err) { return cb(err); }
|
526
|
+
|
527
|
+
winston.debug("authSaved", authSaved)
|
528
|
+
|
529
|
+
// var user = {
|
530
|
+
// id: id.toString(),
|
531
|
+
// name: profile.displayName
|
532
|
+
// };
|
533
|
+
// var user = {
|
534
|
+
// id: "1232321321321321",
|
535
|
+
// name: "Google andrea"
|
536
|
+
// };
|
537
|
+
return cb(null, savedUser);
|
538
|
+
});
|
539
|
+
}).catch(function(err) {
|
540
|
+
winston.error("Error signup google ", err);
|
541
|
+
return cb(err);
|
542
|
+
});
|
543
|
+
} else {
|
544
|
+
|
545
|
+
winston.debug("else")
|
546
|
+
// The Google account has previously logged in to the app. Get the
|
547
|
+
// user record linked to the Google account and log the user in.
|
548
|
+
|
549
|
+
User.findOne({
|
550
|
+
email: email, status: 100
|
551
|
+
}, 'email firstname lastname password emailverified id', function (err, user) {
|
552
|
+
|
553
|
+
winston.debug("user",user, err);
|
554
|
+
// db.get('SELECT * FROM users WHERE id = ?', [ cred.user_id ], function(err, user) {
|
555
|
+
if (err) { return cb(err); }
|
556
|
+
if (!user) { return cb(null, false); }
|
557
|
+
return cb(null, user);
|
558
|
+
});
|
559
|
+
}
|
560
|
+
});
|
561
|
+
}
|
562
|
+
));
|
563
|
+
|
564
|
+
}
|
565
|
+
|
439
566
|
|
440
567
|
|
441
568
|
// var OidcStrategy = require('passport-openidconnect').Strategy;
|
package/models/profile.js
CHANGED
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.3.
|
4
|
+
"version": "2.3.128",
|
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.8",
|
46
46
|
"@tiledesk/tiledesk-rasa-connector": "^1.0.10",
|
47
|
-
"@tiledesk/tiledesk-tybot-connector": "^0.1.
|
47
|
+
"@tiledesk/tiledesk-tybot-connector": "^0.1.76",
|
48
48
|
"@tiledesk/tiledesk-whatsapp-connector": "^0.1.43",
|
49
49
|
"amqplib": "^0.5.5",
|
50
50
|
"app-root-path": "^3.0.0",
|
package/routes/auth.js
CHANGED
@@ -451,6 +451,56 @@ function (req, res) {
|
|
451
451
|
});
|
452
452
|
});
|
453
453
|
|
454
|
+
|
455
|
+
|
456
|
+
// Redirect the user to the Google signin page</em>
|
457
|
+
router.get("/google", passport.authenticate("google", { scope: ["email", "profile"] }));
|
458
|
+
|
459
|
+
// Retrieve user data using the access token received</em>
|
460
|
+
router.get("/google/callback", passport.authenticate("google", { session: false }), (req, res) => {
|
461
|
+
// res.redirect("/auth/profile/");
|
462
|
+
|
463
|
+
var user = req.user;
|
464
|
+
winston.debug("user", user);
|
465
|
+
|
466
|
+
var userJson = user.toObject();
|
467
|
+
|
468
|
+
var signOptions = {
|
469
|
+
issuer: 'https://tiledesk.com',
|
470
|
+
subject: 'user',
|
471
|
+
audience: 'https://tiledesk.com',
|
472
|
+
jwtid: uuidv4()
|
473
|
+
|
474
|
+
};
|
475
|
+
|
476
|
+
var alg = process.env.GLOBAL_SECRET_ALGORITHM;
|
477
|
+
if (alg) {
|
478
|
+
signOptions.algorithm = alg;
|
479
|
+
}
|
480
|
+
|
481
|
+
|
482
|
+
var token = jwt.sign(userJson, configSecret, signOptions); //priv_jwt pp_jwt
|
483
|
+
|
484
|
+
|
485
|
+
// return the information including token as JSON
|
486
|
+
// res.json(returnObject);
|
487
|
+
|
488
|
+
var url = process.env.EMAIL_BASEURL+"?token=JWT "+token;
|
489
|
+
winston.debug("url: "+ url);
|
490
|
+
|
491
|
+
res.redirect(url);
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
|
496
|
+
}
|
497
|
+
);
|
498
|
+
// profile route after successful sign in</em>
|
499
|
+
// router.get("/profile", (req, res) => {
|
500
|
+
// console.log(req);
|
501
|
+
// res.send("Welcome");
|
502
|
+
// });
|
503
|
+
|
454
504
|
// VERIFY EMAIL
|
455
505
|
router.put('/verifyemail/:userid', function (req, res) {
|
456
506
|
|
package/routes/email.js
CHANGED
@@ -32,6 +32,276 @@ router.post('/test/send',
|
|
32
32
|
|
33
33
|
});
|
34
34
|
|
35
|
+
|
36
|
+
if (process.env.ENABLE_TEST_EMAIL_ENDPOINT==true || process.env.ENABLE_TEST_EMAIL_ENDPOINT=="true") {
|
37
|
+
|
38
|
+
|
39
|
+
router.post('/test/sendNewAssignedRequestNotification',
|
40
|
+
async (req, res) => {
|
41
|
+
|
42
|
+
let to = req.body.to;
|
43
|
+
winston.debug("to",to);
|
44
|
+
|
45
|
+
let configEmail = req.body.config;
|
46
|
+
winston.debug("configEmail", configEmail);
|
47
|
+
|
48
|
+
let request = {
|
49
|
+
"_id" : "6316fe117c04320341200e8a",
|
50
|
+
"status" : 50,
|
51
|
+
"preflight" : true,
|
52
|
+
"hasBot" : false,
|
53
|
+
"participants" : [],
|
54
|
+
"priority" : "medium",
|
55
|
+
"request_id" : "support-group-123",
|
56
|
+
"first_text" : "first_text"
|
57
|
+
}
|
58
|
+
|
59
|
+
emailService.sendNewAssignedRequestNotification(to, request, req.project);
|
60
|
+
|
61
|
+
res.json({"status":"delivering"});
|
62
|
+
|
63
|
+
});
|
64
|
+
|
65
|
+
|
66
|
+
router.post('/test/sendNewAssignedAgentMessageEmailNotification',
|
67
|
+
async (req, res) => {
|
68
|
+
|
69
|
+
let to = req.body.to;
|
70
|
+
winston.debug("to",to);
|
71
|
+
|
72
|
+
let configEmail = req.body.config;
|
73
|
+
winston.debug("configEmail", configEmail);
|
74
|
+
|
75
|
+
let request = {
|
76
|
+
"_id" : "6316fe117c04320341200e8a",
|
77
|
+
"status" : 50,
|
78
|
+
"preflight" : true,
|
79
|
+
"hasBot" : false,
|
80
|
+
"participants" : [],
|
81
|
+
"priority" : "medium",
|
82
|
+
"request_id" : "support-group-123",
|
83
|
+
"first_text" : "first_text"
|
84
|
+
}
|
85
|
+
let message = {
|
86
|
+
"text": "text",
|
87
|
+
"request": request
|
88
|
+
}
|
89
|
+
//(to, request, project, message)
|
90
|
+
emailService.sendNewAssignedAgentMessageEmailNotification(to, request, req.project, message);
|
91
|
+
|
92
|
+
res.json({"status":"delivering"});
|
93
|
+
|
94
|
+
});
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
router.post('/test/sendNewPooledRequestNotification',
|
101
|
+
async (req, res) => {
|
102
|
+
|
103
|
+
let to = req.body.to;
|
104
|
+
winston.debug("to",to);
|
105
|
+
|
106
|
+
let configEmail = req.body.config;
|
107
|
+
winston.debug("configEmail", configEmail);
|
108
|
+
|
109
|
+
let request = {
|
110
|
+
"_id" : "6316fe117c04320341200e8a",
|
111
|
+
"status" : 50,
|
112
|
+
"preflight" : true,
|
113
|
+
"hasBot" : false,
|
114
|
+
"participants" : [],
|
115
|
+
"priority" : "medium",
|
116
|
+
"request_id" : "support-group-123",
|
117
|
+
"first_text" : "first_text"
|
118
|
+
}
|
119
|
+
|
120
|
+
emailService.sendNewPooledRequestNotification(to, request, req.project);
|
121
|
+
|
122
|
+
res.json({"status":"delivering"});
|
123
|
+
|
124
|
+
});
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
router.post('/test/sendNewPooledMessageEmailNotification',
|
131
|
+
async (req, res) => {
|
132
|
+
|
133
|
+
let to = req.body.to;
|
134
|
+
winston.debug("to",to);
|
135
|
+
|
136
|
+
let configEmail = req.body.config;
|
137
|
+
winston.debug("configEmail", configEmail);
|
138
|
+
|
139
|
+
let request = {
|
140
|
+
"_id" : "6316fe117c04320341200e8a",
|
141
|
+
"status" : 50,
|
142
|
+
"preflight" : true,
|
143
|
+
"hasBot" : false,
|
144
|
+
"participants" : [],
|
145
|
+
"priority" : "medium",
|
146
|
+
"request_id" : "support-group-123",
|
147
|
+
"first_text" : "first_text"
|
148
|
+
}
|
149
|
+
let message = {
|
150
|
+
"text": "text",
|
151
|
+
"request": request
|
152
|
+
}
|
153
|
+
|
154
|
+
emailService.sendNewPooledMessageEmailNotification(to, request, req.project, message);
|
155
|
+
|
156
|
+
res.json({"status":"delivering"});
|
157
|
+
|
158
|
+
});
|
159
|
+
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
router.post('/test/sendNewMessageNotification',
|
165
|
+
async (req, res) => {
|
166
|
+
|
167
|
+
let to = req.body.to;
|
168
|
+
winston.debug("to",to);
|
169
|
+
|
170
|
+
let configEmail = req.body.config;
|
171
|
+
winston.debug("configEmail", configEmail);
|
172
|
+
|
173
|
+
let request = {
|
174
|
+
"_id" : "6316fe117c04320341200e8a",
|
175
|
+
"status" : 50,
|
176
|
+
"preflight" : true,
|
177
|
+
"hasBot" : false,
|
178
|
+
"participants" : [],
|
179
|
+
"priority" : "medium",
|
180
|
+
"request_id" : "support-group-123",
|
181
|
+
"first_text" : "first_text"
|
182
|
+
}
|
183
|
+
let message = {
|
184
|
+
"text": "text",
|
185
|
+
"request": request
|
186
|
+
}
|
187
|
+
|
188
|
+
// sendNewMessageNotification(to, message, project, tokenQueryString, sourcePage)
|
189
|
+
emailService.sendNewMessageNotification(to, message, req.project, "tokenQueryString", "sourcePage");
|
190
|
+
|
191
|
+
res.json({"status":"delivering"});
|
192
|
+
|
193
|
+
});
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
router.post('/test/sendEmailChannelNotification',
|
198
|
+
async (req, res) => {
|
199
|
+
|
200
|
+
let to = req.body.to;
|
201
|
+
winston.debug("to",to);
|
202
|
+
|
203
|
+
let configEmail = req.body.config;
|
204
|
+
winston.debug("configEmail", configEmail);
|
205
|
+
|
206
|
+
let request = {
|
207
|
+
"_id" : "6316fe117c04320341200e8a",
|
208
|
+
"status" : 50,
|
209
|
+
"preflight" : true,
|
210
|
+
"hasBot" : false,
|
211
|
+
"participants" : [],
|
212
|
+
"priority" : "medium",
|
213
|
+
"request_id" : "support-group-123",
|
214
|
+
"first_text" : "first_text"
|
215
|
+
}
|
216
|
+
let message = {
|
217
|
+
"text": "text",
|
218
|
+
"request": request
|
219
|
+
}
|
220
|
+
|
221
|
+
// (to, message, project, tokenQueryString, sourcePage)
|
222
|
+
emailService.sendEmailChannelNotification(to, message, req.project, "tokenQueryString", "sourcePage");
|
223
|
+
|
224
|
+
res.json({"status":"delivering"});
|
225
|
+
|
226
|
+
});
|
227
|
+
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
router.post('/test/sendFollowerNotification',
|
232
|
+
async (req, res) => {
|
233
|
+
|
234
|
+
let to = req.body.to;
|
235
|
+
winston.debug("to",to);
|
236
|
+
|
237
|
+
let configEmail = req.body.config;
|
238
|
+
winston.debug("configEmail", configEmail);
|
239
|
+
|
240
|
+
let request = {
|
241
|
+
"_id" : "6316fe117c04320341200e8a",
|
242
|
+
"status" : 50,
|
243
|
+
"preflight" : true,
|
244
|
+
"hasBot" : false,
|
245
|
+
"participants" : [],
|
246
|
+
"priority" : "medium",
|
247
|
+
"request_id" : "support-group-123",
|
248
|
+
"first_text" : "first_text"
|
249
|
+
}
|
250
|
+
let message = {
|
251
|
+
"text": "text",
|
252
|
+
"request": request
|
253
|
+
}
|
254
|
+
|
255
|
+
emailService.sendFollowerNotification(to, message, req.project);
|
256
|
+
|
257
|
+
res.json({"status":"delivering"});
|
258
|
+
|
259
|
+
});
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
router.post('/test/sendRequestTranscript',
|
264
|
+
async (req, res) => {
|
265
|
+
|
266
|
+
let to = req.body.to;
|
267
|
+
winston.debug("to",to);
|
268
|
+
|
269
|
+
let configEmail = req.body.config;
|
270
|
+
winston.debug("configEmail", configEmail);
|
271
|
+
|
272
|
+
let request = {
|
273
|
+
"_id" : "6316fe117c04320341200e8a",
|
274
|
+
"status" : 50,
|
275
|
+
"preflight" : true,
|
276
|
+
"hasBot" : false,
|
277
|
+
"participants" : [],
|
278
|
+
"priority" : "medium",
|
279
|
+
"request_id" : "support-group-123",
|
280
|
+
"first_text" : "first_text",
|
281
|
+
createdAt: new Date()
|
282
|
+
|
283
|
+
}
|
284
|
+
let messages = [{
|
285
|
+
"text": "text",
|
286
|
+
"request": request,
|
287
|
+
createdAt: new Date()
|
288
|
+
}]
|
289
|
+
|
290
|
+
// sendRequestTranscript(to, messages, request, project)
|
291
|
+
|
292
|
+
|
293
|
+
emailService.sendRequestTranscript(to, messages, request, req.project);
|
294
|
+
|
295
|
+
res.json({"status":"delivering"});
|
296
|
+
|
297
|
+
});
|
298
|
+
|
299
|
+
|
300
|
+
}
|
301
|
+
|
302
|
+
|
303
|
+
|
304
|
+
|
35
305
|
//TODO add cc
|
36
306
|
router.post('/send',
|
37
307
|
async (req, res) => {
|
package/services/emailService.js
CHANGED
@@ -436,12 +436,15 @@ class EmailService {
|
|
436
436
|
// cambiare in [Nicky:Dashboard Support] Assigned Chat
|
437
437
|
// serve per aggiornare native... fai aggiornamento
|
438
438
|
|
439
|
-
let
|
439
|
+
let subjectDef = `[Tiledesk ${project ? project.name : '-'}] New Assigned Chat`;
|
440
440
|
|
441
441
|
if (request.subject) {
|
442
|
-
|
442
|
+
subjectDef = `[Tiledesk ${project ? project.name : '-'}] ${request.subject}`;
|
443
443
|
}
|
444
444
|
|
445
|
+
let subject = that.formatText("assignedRequestSubject", subjectDef, request, project.settings);
|
446
|
+
|
447
|
+
|
445
448
|
// if (request.ticket_id) {
|
446
449
|
// subject = `[Ticket #${request.ticket_id}] New Assigned Chat`;
|
447
450
|
// }
|
@@ -583,19 +586,21 @@ class EmailService {
|
|
583
586
|
}
|
584
587
|
|
585
588
|
|
586
|
-
let
|
589
|
+
let subjectDef = `[Tiledesk ${project ? project.name : '-'}] New message`;
|
587
590
|
|
588
591
|
if (request.subject) {
|
589
|
-
|
592
|
+
subjectDef = `[Tiledesk ${project ? project.name : '-'}] ${request.subject}`;
|
590
593
|
}
|
591
594
|
if (request.ticket_id) {
|
592
|
-
|
595
|
+
subjectDef = `[Ticket #${request.ticket_id}] New message`;
|
593
596
|
}
|
594
597
|
|
595
598
|
if (request.ticket_id && request.subject) {
|
596
|
-
|
599
|
+
subjectDef = `[Ticket #${request.ticket_id}] ${request.subject}`;
|
597
600
|
}
|
598
601
|
|
602
|
+
let subject = that.formatText("assignedEmailMessageSubject", subjectDef, request, project.settings);
|
603
|
+
|
599
604
|
|
600
605
|
|
601
606
|
that.send({
|
@@ -727,11 +732,15 @@ class EmailService {
|
|
727
732
|
}
|
728
733
|
}
|
729
734
|
|
730
|
-
let
|
735
|
+
let subjectDef = `[Tiledesk ${project ? project.name : '-'}] New Pooled Chat`;
|
731
736
|
|
732
737
|
if (request.subject) {
|
733
|
-
|
738
|
+
subjectDef = `[Tiledesk ${project ? project.name : '-'}] ${request.subject}`;
|
734
739
|
}
|
740
|
+
|
741
|
+
let subject = that.formatText("pooledRequestSubject", subjectDef, request, project.settings);
|
742
|
+
|
743
|
+
|
735
744
|
// if (request.ticket_id) {
|
736
745
|
// subject = `[Ticket #${request.ticket_id}] New Pooled Chat`;
|
737
746
|
// }
|
@@ -868,19 +877,21 @@ class EmailService {
|
|
868
877
|
}
|
869
878
|
|
870
879
|
|
871
|
-
let
|
880
|
+
let subjectDef = `[Tiledesk ${project ? project.name : '-'}] New Message`;
|
872
881
|
|
873
882
|
if (request.subject) {
|
874
|
-
|
883
|
+
subjectDef = `[Tiledesk ${project ? project.name : '-'}] ${request.subject}`;
|
875
884
|
}
|
876
885
|
if (request.ticket_id) {
|
877
|
-
|
886
|
+
subjectDef = `[Ticket #${request.ticket_id}] New Message`;
|
878
887
|
}
|
879
888
|
|
880
889
|
if (request.ticket_id && request.subject) {
|
881
|
-
|
890
|
+
subjectDef = `[Ticket #${request.ticket_id}] ${request.subject}`;
|
882
891
|
}
|
883
892
|
|
893
|
+
let subject = that.formatText("pooledEmailMessageSubject", subjectDef, request, project.settings);
|
894
|
+
|
884
895
|
|
885
896
|
that.send({
|
886
897
|
messageId: messageId,
|
@@ -1012,6 +1023,8 @@ class EmailService {
|
|
1012
1023
|
}
|
1013
1024
|
|
1014
1025
|
|
1026
|
+
let subject = that.formatText("newMessageSubject", `[Tiledesk ${project ? project.name : '-'}] New Offline Message`, message, project.settings);
|
1027
|
+
|
1015
1028
|
that.send({
|
1016
1029
|
messageId: messageId,
|
1017
1030
|
// sender: message.senderFullname, //must be an email
|
@@ -1020,7 +1033,7 @@ class EmailService {
|
|
1020
1033
|
replyTo: replyTo,
|
1021
1034
|
inReplyTo: inReplyTo,
|
1022
1035
|
references: references,
|
1023
|
-
subject
|
1036
|
+
subject:subject, //TODO (anche per il cloud) aggiungere variabile env per cambiare i subjects
|
1024
1037
|
html:html,
|
1025
1038
|
config:configEmail,
|
1026
1039
|
headers: headers
|
@@ -1166,17 +1179,18 @@ class EmailService {
|
|
1166
1179
|
}
|
1167
1180
|
}
|
1168
1181
|
|
1169
|
-
|
1182
|
+
//gmail uses subject
|
1183
|
+
let subject = that.formatText("ticketSubject", `R: ${message.request ? message.request.subject : '-'}`, message, project.settings);
|
1170
1184
|
|
1171
1185
|
//ocf
|
1172
1186
|
//prod //pre
|
1173
|
-
if (project._id =="6406e34727b57500120b1bd6" || project._id == "642c609f179910002cc56b3e") {
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
}
|
1187
|
+
// if (project._id =="6406e34727b57500120b1bd6" || project._id == "642c609f179910002cc56b3e") {
|
1188
|
+
// subject = "Richiesta di supporto #" + message.request.ticket_id;
|
1189
|
+
// if (message.request.subject) {
|
1190
|
+
// subject = subject + " - " + message.request.subject;
|
1191
|
+
// }
|
1192
|
+
// // console.log("subject",subject);
|
1193
|
+
// }
|
1180
1194
|
|
1181
1195
|
// if (message.request && message.request.lead && message.request.lead.email) {
|
1182
1196
|
// winston.info("message.request.lead.email: " + message.request.lead.email);
|
@@ -1349,6 +1363,8 @@ class EmailService {
|
|
1349
1363
|
}
|
1350
1364
|
|
1351
1365
|
|
1366
|
+
let subject = that.formatText("newMessageFollowerSubject", `${message.request ? message.request.ticket_id : '-'}`, message, project.settings);
|
1367
|
+
|
1352
1368
|
|
1353
1369
|
|
1354
1370
|
that.send({
|
@@ -1361,7 +1377,7 @@ class EmailService {
|
|
1361
1377
|
inReplyTo: inReplyTo,
|
1362
1378
|
references: references,
|
1363
1379
|
// subject:`${message.request ? message.request.subject : '-'}`,
|
1364
|
-
subject
|
1380
|
+
subject: subject, //gmail uses subject
|
1365
1381
|
text:html,
|
1366
1382
|
html:html,
|
1367
1383
|
config:configEmail,
|
@@ -1814,15 +1830,17 @@ async sendRequestTranscript(to, messages, request, project) {
|
|
1814
1830
|
|
1815
1831
|
//custom ocf here
|
1816
1832
|
// console.log("ocf",project._id);
|
1817
|
-
let subject = '[Tiledesk] Transcript';
|
1833
|
+
let subject = that.formatText("sendTranscriptSubject", '[Tiledesk] Transcript', request, project.settings);
|
1834
|
+
|
1818
1835
|
//prod //pre
|
1819
|
-
if (project._id =="6406e34727b57500120b1bd6" || project._id == "642c609f179910002cc56b3e") {
|
1820
|
-
|
1821
|
-
|
1822
|
-
|
1823
|
-
|
1824
|
-
|
1825
|
-
|
1836
|
+
// if (project._id =="6406e34727b57500120b1bd6" || project._id == "642c609f179910002cc56b3e") {
|
1837
|
+
// subject = "Segnalazione #" + request.ticket_id;
|
1838
|
+
// // subject = "Richiesta di supporto #" + request.ticket_id;
|
1839
|
+
// if (request.subject) {
|
1840
|
+
// subject = subject + " - " + request.subject;
|
1841
|
+
// }
|
1842
|
+
// // console.log("subject",subject);
|
1843
|
+
// }
|
1826
1844
|
// hcustomization.emailTranscript(to, subject, html, configEmail)
|
1827
1845
|
|
1828
1846
|
that.send({from:from, to:to, subject: subject, html:html, config: configEmail});
|
@@ -1830,6 +1848,72 @@ async sendRequestTranscript(to, messages, request, project) {
|
|
1830
1848
|
|
1831
1849
|
}
|
1832
1850
|
|
1851
|
+
formatText(templateName, defaultText, payload, settings) {
|
1852
|
+
|
1853
|
+
let text = defaultText;
|
1854
|
+
winston.verbose("formatText defaultText: "+ defaultText);
|
1855
|
+
|
1856
|
+
let template = this.getTemplate(templateName, settings);
|
1857
|
+
|
1858
|
+
winston.verbose("formatText template: "+ template);
|
1859
|
+
|
1860
|
+
if (template) {
|
1861
|
+
text = template;
|
1862
|
+
}
|
1863
|
+
|
1864
|
+
var baseScope = JSON.parse(JSON.stringify(this));
|
1865
|
+
delete baseScope.pass;
|
1866
|
+
|
1867
|
+
winston.verbose("formatText text: "+ text);
|
1868
|
+
|
1869
|
+
var templateHand = handlebars.compile(text);
|
1870
|
+
|
1871
|
+
var replacements = {
|
1872
|
+
payload: payload,
|
1873
|
+
baseScope: baseScope,
|
1874
|
+
test: "test"
|
1875
|
+
};
|
1876
|
+
|
1877
|
+
var textTemplate = templateHand(replacements);
|
1878
|
+
winston.verbose("formatText textTemplate: "+ textTemplate);
|
1879
|
+
|
1880
|
+
return textTemplate;
|
1881
|
+
|
1882
|
+
}
|
1883
|
+
|
1884
|
+
getTemplate(templateName, settings) {
|
1885
|
+
|
1886
|
+
var that = this;
|
1887
|
+
winston.verbose('getTemplate formatSubject: ' + JSON.stringify(settings));
|
1888
|
+
|
1889
|
+
|
1890
|
+
winston.verbose('getTemplate settings.email.templates: ',settings.email.templates);
|
1891
|
+
if (settings && settings.email && settings.email.templates) {
|
1892
|
+
|
1893
|
+
var templates = settings.email.templates;
|
1894
|
+
winston.verbose('getTemplate templates: ',templates);
|
1895
|
+
|
1896
|
+
var templateDbName = templateName.replace(".subject", "");
|
1897
|
+
winston.verbose('getTemplate templateDbName: '+templateDbName);
|
1898
|
+
|
1899
|
+
|
1900
|
+
var template = templates[templateDbName];
|
1901
|
+
winston.verbose('getTemplate template: '+template);
|
1902
|
+
|
1903
|
+
if (template) {
|
1904
|
+
// that.callback(template);
|
1905
|
+
// return new Promise(function (resolve, reject) {
|
1906
|
+
// return resolve(template);
|
1907
|
+
return template;
|
1908
|
+
// });
|
1909
|
+
}else {
|
1910
|
+
return undefined;
|
1911
|
+
}
|
1912
|
+
} else {
|
1913
|
+
return undefined;
|
1914
|
+
}
|
1915
|
+
|
1916
|
+
}
|
1833
1917
|
|
1834
1918
|
|
1835
1919
|
|