@tiledesk/tiledesk-server 2.3.6 → 2.3.7-1.2
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/.github/workflows/docker-community-worker-push-latest.yml +23 -0
- package/.github/workflows/docker-image-tag-worker-community-tag-push.yml +22 -0
- package/CHANGELOG.md +361 -3
- package/Dockerfile-jobs +31 -0
- package/app.js +62 -69
- package/channels/chat21/chat21Handler.js +37 -6
- package/channels/chat21/chat21WebHook.js +62 -34
- package/channels/chat21/package-lock.json +663 -706
- package/channels/chat21/package.json +2 -2
- package/config/labels/widget.json +337 -136
- package/deploy.sh +2 -0
- package/event/messageEvent.js +110 -9
- package/jobs.js +80 -0
- package/jobsManager.js +47 -0
- package/middleware/has-role.js +10 -3
- package/middleware/ipFilter.js +220 -0
- package/middleware/passport.js +8 -2
- package/models/department.js +1 -1
- package/models/faq.js +77 -25
- package/models/faq_kb.js +19 -0
- package/models/message.js +10 -8
- package/models/project.js +10 -0
- package/models/project_user.js +10 -0
- package/models/request.js +12 -1
- package/package.json +12 -11
- package/pubmodules/activities/activityArchiver.js +216 -90
- package/pubmodules/activities/routes/activity.js +1 -1
- package/pubmodules/apps/index.js +8 -0
- package/pubmodules/apps/listener.js +27 -0
- package/pubmodules/cache/index.js +2 -0
- package/pubmodules/cache/mongoose-cachegoose-fn.js +630 -0
- package/pubmodules/canned/cannedResponse.js +4 -0
- package/pubmodules/canned/cannedResponseRoute.js +10 -5
- package/pubmodules/dialogflow/index.js +10 -0
- package/pubmodules/dialogflow/listener.js +66 -0
- package/pubmodules/emailNotification/requestNotification.js +58 -28
- package/pubmodules/events/eventRoute.js +49 -24
- package/pubmodules/messageTransformer/messageHandlebarsTransformerInterceptor.js +6 -1
- package/pubmodules/messageTransformer/messageTransformerInterceptor.js +10 -4
- package/pubmodules/pubModulesManager.js +173 -7
- package/pubmodules/queue/index.js +4 -0
- package/pubmodules/queue/reconnect.js +331 -0
- package/pubmodules/queue/reconnectFanout.js +256 -0
- package/pubmodules/rasa/listener.js +5 -5
- package/pubmodules/routing-queue/index.js +3 -0
- package/pubmodules/routing-queue/listener.js +328 -0
- package/pubmodules/rules/conciergeBot.js +2 -2
- package/pubmodules/scheduler/tasks/closeAgentUnresponsiveRequestTask.js +6 -1
- package/pubmodules/scheduler/tasks/closeBotUnresponsiveRequestTask.js +7 -1
- package/pubmodules/tilebot/index.js +11 -0
- package/pubmodules/tilebot/listener.js +85 -0
- package/pubmodules/trigger/rulesTrigger.js +137 -14
- package/pubmodules/trigger/start.js +5 -1
- package/pubmodules/whatsapp/index.js +7 -0
- package/pubmodules/whatsapp/listener.js +32 -0
- package/routes/auth.js +7 -2
- package/routes/campaigns.js +3 -3
- package/routes/department.js +3 -2
- package/routes/email.js +32 -2
- package/routes/faq.js +37 -2
- package/routes/faq_kb.js +496 -133
- package/routes/faqpub.js +5 -0
- package/routes/lead.js +56 -0
- package/routes/message.js +196 -14
- package/routes/messagesRoot.js +39 -0
- package/routes/project.js +76 -4
- package/routes/project_user.js +11 -1
- package/routes/project_user_test.js +19 -0
- package/routes/request.js +134 -30
- package/routes/troubleshooting.js +12 -0
- package/routes/users-util.js +39 -0
- package/routes/users.js +1 -1
- package/routes/widget.js +64 -2
- package/services/BotSubscriptionNotifier.js +5 -0
- package/services/banUserNotifier.js +86 -0
- package/services/cacheEnabler.js +56 -0
- package/services/chatbotService.js +101 -0
- package/services/departmentService.js +25 -3
- package/services/emailService.js +170 -28
- package/services/faqBotHandler.js +2 -3
- package/services/faqService.js +28 -3
- package/services/geoService.js +36 -6
- package/services/labelService.js +1 -1
- package/services/leadService.js +3 -2
- package/services/messageService.js +4 -2
- package/services/modulesManager.js +23 -76
- package/services/operatingHoursService.js +9 -4
- package/services/requestService.js +75 -39
- package/services/subscriptionNotifier.js +9 -4
- package/services/trainingService.js +106 -0
- package/template/email/assignedEmailMessage.html +21 -11
- package/template/email/assignedRequest.html +21 -11
- package/template/email/beenInvitedExistingUser.html +16 -6
- package/template/email/beenInvitedNewUser.html +16 -6
- package/template/email/emailDirect.html +130 -0
- package/template/email/newMessage.html +18 -8
- package/template/email/newMessageFollower.html +22 -12
- package/template/email/passwordChanged.html +15 -5
- package/template/email/pooledEmailMessage.html +21 -11
- package/template/email/pooledRequest.html +20 -10
- package/template/email/resetPassword.html +15 -5
- package/template/email/sendTranscript.html +7 -4
- package/template/email/ticket.html +17 -7
- package/template/email/verify.html +15 -5
- package/test/cannedRoute.js +157 -0
- package/test/chatbot-mock.js +127 -0
- package/test/example-json-intents.txt +1 -0
- package/test/example-json.txt +1 -0
- package/test/example.json +1 -0
- package/test/faqRoute.js +353 -208
- package/test/faqkbRoute.js +669 -64
- package/test/imageRoute.js +1 -1
- package/test/messageRoute.js +387 -5
- package/test/requestRoute.js +6 -6
- package/test/requestService.js +55 -4
- package/test-int/cache-project.js +90 -0
- package/test-int/cache-project_user.js +88 -0
- package/utils/UIDGenerator.js +20 -0
- package/utils/cacheUtil.js +2 -2
- package/utils/orgUtil.js +3 -3
- package/utils/promiseUtil.js +31 -0
- package/utils/recipientEmailUtil.js +66 -0
- package/utils/sendEmailUtil.js +34 -0
- package/utils/sendMessageUtil.js +1 -1
- package/utils/stringUtil.js +12 -0
- package/websocket/webSocketServer.js +33 -10
|
@@ -8,6 +8,8 @@ var winston = require('../config/winston');
|
|
|
8
8
|
const departmentEvent = require('../event/departmentEvent');
|
|
9
9
|
const Request = require('../models/request');
|
|
10
10
|
const RoleConstants = require ('../models/roleConstants')
|
|
11
|
+
var cacheEnabler = require("../services/cacheEnabler");
|
|
12
|
+
var cacheUtil = require("../utils/cacheUtil");
|
|
11
13
|
|
|
12
14
|
class DepartmentService {
|
|
13
15
|
|
|
@@ -86,7 +88,7 @@ roundRobin(operatorSelectedEvent) {
|
|
|
86
88
|
|
|
87
89
|
// let lastRequests = await
|
|
88
90
|
// requestcachefarequi nocachepopulatereqired
|
|
89
|
-
Request.find(query).sort({_id:-1}).limit(1).exec(function (err, lastRequests) {
|
|
91
|
+
Request.find(query).sort({_id:-1}).limit(1).exec(function (err, lastRequests) { // cache_attention use_lean use_select
|
|
90
92
|
if (err) {
|
|
91
93
|
winston.error('Error getting request for RoundRobinOperator', err);
|
|
92
94
|
return reject(err);
|
|
@@ -190,7 +192,12 @@ getOperators(departmentid, projectid, nobot, disableWebHookCall, context) {
|
|
|
190
192
|
// console.log("»»» »»» --> DEPT ID ", departmentid);
|
|
191
193
|
|
|
192
194
|
|
|
193
|
-
|
|
195
|
+
let q = Project.findOne({_id: projectid, status: 100})
|
|
196
|
+
if (cacheEnabler.project) {
|
|
197
|
+
q.cache(cacheUtil.longTTL, "projects:id:"+projectid) //project_cache
|
|
198
|
+
winston.debug('project cache enabled');
|
|
199
|
+
}
|
|
200
|
+
return q.exec(function(err, project){
|
|
194
201
|
if (err) {
|
|
195
202
|
winston.error('Project findById ', err);
|
|
196
203
|
return reject(err);
|
|
@@ -205,6 +212,7 @@ getOperators(departmentid, projectid, nobot, disableWebHookCall, context) {
|
|
|
205
212
|
// TODO questo lo abiliterei solo esplicitamete se si flagga opzione su progetto per performance
|
|
206
213
|
if (disableWebHookCall==undefined) {
|
|
207
214
|
//if pro enabled disableWebHookCall = false
|
|
215
|
+
//secondo me qui manca un parentesi tonda per gli or
|
|
208
216
|
if (project.profile && (project.profile.type === 'free' && project.trialExpired === false) || (project.profile.type === 'payment' && project.isActiveSubscription === true)) {
|
|
209
217
|
// winston.info('disableWebHookCall pro');
|
|
210
218
|
disableWebHookCall = false;
|
|
@@ -389,6 +397,7 @@ getOperators(departmentid, projectid, nobot, disableWebHookCall, context) {
|
|
|
389
397
|
|
|
390
398
|
let objectToReturn = { available_agents: _available_agents, agents: project_users, operators: selectedoperator, department: department, group: group, id_project: projectid, project: project, context: context };
|
|
391
399
|
|
|
400
|
+
// var objectToReturnRoundRobin = objectToReturn;
|
|
392
401
|
that.roundRobin(objectToReturn).then(function(objectToReturnRoundRobin){
|
|
393
402
|
|
|
394
403
|
winston.debug("context2",context);
|
|
@@ -450,6 +459,8 @@ getOperators(departmentid, projectid, nobot, disableWebHookCall, context) {
|
|
|
450
459
|
|
|
451
460
|
let objectToReturn = { available_agents: _available_agents, agents: project_users, operators: selectedoperator, department: department, id_project: projectid, project: project, context: context };
|
|
452
461
|
|
|
462
|
+
// var objectToReturnRoundRobin = objectToReturn;
|
|
463
|
+
|
|
453
464
|
that.roundRobin(objectToReturn).then(function(objectToReturnRoundRobin) {
|
|
454
465
|
winston.debug("context2",context);
|
|
455
466
|
departmentEvent.emit('operator.select.base1', {result:objectToReturnRoundRobin, disableWebHookCall: disableWebHookCall, resolve: resolve, reject: reject, context: context});
|
|
@@ -543,8 +554,19 @@ getOperators(departmentid, projectid, nobot, disableWebHookCall, context) {
|
|
|
543
554
|
|
|
544
555
|
// console.log('-- > OPERATORS [ getRandomAvailableOperator ] - PROJECT USER AVAILABLE LENGHT ', project_users_available.length);
|
|
545
556
|
if (project_users_available.length > 0) {
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
// new
|
|
560
|
+
// num between 0 and 1 * es 3 ->
|
|
561
|
+
// let randomIndex = Math.round(Math.random() * project_users_available.length);
|
|
562
|
+
// // let randomIndex = Math.floor(Math.random() * project_users_available.length);
|
|
563
|
+
|
|
564
|
+
// console.log("randomIndex",randomIndex);
|
|
565
|
+
// var operator = project_users_available[randomIndex];
|
|
566
|
+
// // console.log('OPERATORS - SELECTED MEMBER ID', operator.id_user);
|
|
567
|
+
|
|
546
568
|
var operator = project_users_available[Math.floor(Math.random() * project_users_available.length)];
|
|
547
|
-
|
|
569
|
+
|
|
548
570
|
|
|
549
571
|
return [{ id_user: operator.id_user }];
|
|
550
572
|
// return [operator];
|
package/services/emailService.js
CHANGED
|
@@ -12,6 +12,9 @@ handlebars.registerHelper('ifEquals', function(arg1, arg2, options) {
|
|
|
12
12
|
return (arg1 == arg2) ? options.fn(this) : options.inverse(this);
|
|
13
13
|
});
|
|
14
14
|
|
|
15
|
+
handlebars.registerHelper('dateFormat', require('handlebars-dateformat'));
|
|
16
|
+
|
|
17
|
+
|
|
15
18
|
// var options = {};
|
|
16
19
|
// handlebars.registerHelper('markdown', markdown(options));
|
|
17
20
|
|
|
@@ -45,6 +48,8 @@ const maskOptions = {
|
|
|
45
48
|
|
|
46
49
|
const MESSAGE_ID_DOMAIN = "tiledesk.com";
|
|
47
50
|
|
|
51
|
+
// const hcustomization = require('../utils/hcustomization');
|
|
52
|
+
|
|
48
53
|
class EmailService {
|
|
49
54
|
|
|
50
55
|
constructor() {
|
|
@@ -98,7 +103,11 @@ class EmailService {
|
|
|
98
103
|
this.host = process.env.EMAIL_HOST || config.host;
|
|
99
104
|
winston.info('EmailService host: ' + this.host);
|
|
100
105
|
|
|
101
|
-
this.secure =
|
|
106
|
+
this.secure = false;
|
|
107
|
+
if (process.env.EMAIL_SECURE == "true" || process.env.EMAIL_SECURE ==true) {
|
|
108
|
+
this.secure = true;
|
|
109
|
+
}
|
|
110
|
+
// this.secure = process.env.EMAIL_SECURE || false;
|
|
102
111
|
winston.info('EmailService secure: ' + this.secure);
|
|
103
112
|
|
|
104
113
|
this.user = process.env.EMAIL_USERNAME || config.username;
|
|
@@ -108,7 +117,11 @@ class EmailService {
|
|
|
108
117
|
winston.info('EmailService port: ' + this.port);
|
|
109
118
|
|
|
110
119
|
|
|
111
|
-
this.markdown =
|
|
120
|
+
this.markdown = true;
|
|
121
|
+
if (process.env.EMAIL_MARKDOWN =="false" || process.env.EMAIL_MARKDOWN ==false) {
|
|
122
|
+
this.markdown = false;
|
|
123
|
+
}
|
|
124
|
+
// this.markdown = process.env.EMAIL_MARKDOWN || true;
|
|
112
125
|
winston.info('EmailService markdown: '+ this.markdown);
|
|
113
126
|
|
|
114
127
|
this.headers = {
|
|
@@ -116,6 +129,13 @@ class EmailService {
|
|
|
116
129
|
}
|
|
117
130
|
winston.info('EmailService headers: ' + JSON.stringify(this.headers));
|
|
118
131
|
|
|
132
|
+
this.ccEnabled = false //cc creates loop when you send an email with cc: support@tiledesk.com -> Tiledesk generates an email with ticket id with in cc support@tiledesk.com that loop
|
|
133
|
+
|
|
134
|
+
if (process.env.EMAIL_CC_ENABLED ==="true" || process.env.EMAIL_CC_ENABLED === true ) {
|
|
135
|
+
this.ccEnabled = true;
|
|
136
|
+
}
|
|
137
|
+
winston.info('EmailService ccEnabled: ' + this.ccEnabled);
|
|
138
|
+
|
|
119
139
|
}
|
|
120
140
|
|
|
121
141
|
readTemplate(templateName, settings) {
|
|
@@ -252,6 +272,8 @@ class EmailService {
|
|
|
252
272
|
};
|
|
253
273
|
|
|
254
274
|
winston.debug('mailOptions', mailOptions);
|
|
275
|
+
winston.debug(' mail.config', mail.config);
|
|
276
|
+
|
|
255
277
|
if (!mail.to) {
|
|
256
278
|
return winston.warn("EmailService send method. to field is not defined", mailOptions);
|
|
257
279
|
}
|
|
@@ -262,7 +284,7 @@ class EmailService {
|
|
|
262
284
|
if (mail.callback){
|
|
263
285
|
mail.callback(error, {info:info});
|
|
264
286
|
}
|
|
265
|
-
return winston.error("Error sending email ", {error:error, mailOptions:mailOptions});
|
|
287
|
+
return winston.error("Error sending email ", {error:error, mailConfig: mail.config, mailOptions:mailOptions});
|
|
266
288
|
}
|
|
267
289
|
winston.verbose('Email sent:', {info: info});
|
|
268
290
|
winston.debug('Email sent:', {info: info, mailOptions: mailOptions});
|
|
@@ -1020,7 +1042,7 @@ class EmailService {
|
|
|
1020
1042
|
|
|
1021
1043
|
}
|
|
1022
1044
|
|
|
1023
|
-
|
|
1045
|
+
|
|
1024
1046
|
|
|
1025
1047
|
async sendEmailChannelNotification(to, message, project, tokenQueryString, sourcePage) {
|
|
1026
1048
|
|
|
@@ -1114,14 +1136,17 @@ class EmailService {
|
|
|
1114
1136
|
references = message.request.attributes.email_references;
|
|
1115
1137
|
}
|
|
1116
1138
|
|
|
1117
|
-
if (
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1139
|
+
if (that.ccEnabled==true) {
|
|
1140
|
+
if (message.request.attributes.email_cc) {
|
|
1141
|
+
cc = message.request.attributes.email_cc;
|
|
1142
|
+
}
|
|
1143
|
+
winston.debug("email message.request.attributes.email_ccStr: "+ message.request.attributes.email_ccStr);
|
|
1144
|
+
if (message.request.attributes.email_ccStr!=undefined) {
|
|
1145
|
+
ccString = message.request.attributes.email_ccStr;
|
|
1146
|
+
winston.debug("email set ccString");
|
|
1147
|
+
}
|
|
1124
1148
|
}
|
|
1149
|
+
|
|
1125
1150
|
}
|
|
1126
1151
|
winston.verbose("email inReplyTo: "+ inReplyTo);
|
|
1127
1152
|
winston.verbose("email references: "+ references);
|
|
@@ -1283,13 +1308,15 @@ class EmailService {
|
|
|
1283
1308
|
references = message.request.attributes.email_references;
|
|
1284
1309
|
}
|
|
1285
1310
|
|
|
1286
|
-
if (
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1311
|
+
if (that.ccEnabled==true) {
|
|
1312
|
+
if (message.request.attributes.email_cc) {
|
|
1313
|
+
cc = message.request.attributes.email_cc;
|
|
1314
|
+
}
|
|
1315
|
+
winston.debug("email message.request.attributes.email_ccStr: "+ message.request.attributes.email_ccStr);
|
|
1316
|
+
if (message.request.attributes.email_ccStr!=undefined) {
|
|
1317
|
+
ccString = message.request.attributes.email_ccStr;
|
|
1318
|
+
winston.debug("email set ccString");
|
|
1319
|
+
}
|
|
1293
1320
|
}
|
|
1294
1321
|
}
|
|
1295
1322
|
winston.verbose("email inReplyTo: "+ inReplyTo);
|
|
@@ -1350,10 +1377,6 @@ class EmailService {
|
|
|
1350
1377
|
}
|
|
1351
1378
|
|
|
1352
1379
|
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
1380
|
/*
|
|
1358
1381
|
sendEmailChannelTakingNotification(to, request, project, tokenQueryString) {
|
|
1359
1382
|
|
|
@@ -1401,6 +1424,103 @@ class EmailService {
|
|
|
1401
1424
|
}
|
|
1402
1425
|
*/
|
|
1403
1426
|
|
|
1427
|
+
|
|
1428
|
+
|
|
1429
|
+
|
|
1430
|
+
|
|
1431
|
+
|
|
1432
|
+
|
|
1433
|
+
async sendEmailDirect(to, text, project, request_id, subject, tokenQueryString, sourcePage) {
|
|
1434
|
+
|
|
1435
|
+
var that = this;
|
|
1436
|
+
|
|
1437
|
+
|
|
1438
|
+
if (project.toJSON) {
|
|
1439
|
+
project = project.toJSON();
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
var html = await this.readTemplate('emailDirect.html', project.settings);
|
|
1443
|
+
|
|
1444
|
+
var envTemplate = process.env.EMAIL_DIRECT_HTML_TEMPLATE;
|
|
1445
|
+
winston.debug("envTemplate: " + envTemplate);
|
|
1446
|
+
|
|
1447
|
+
if (envTemplate) {
|
|
1448
|
+
html = envTemplate;
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
winston.debug("html: " + html);
|
|
1452
|
+
|
|
1453
|
+
var template = handlebars.compile(html);
|
|
1454
|
+
|
|
1455
|
+
var baseScope = JSON.parse(JSON.stringify(that));
|
|
1456
|
+
delete baseScope.pass;
|
|
1457
|
+
|
|
1458
|
+
|
|
1459
|
+
let msgText = text;
|
|
1460
|
+
msgText = encode(msgText);
|
|
1461
|
+
if (this.markdown) {
|
|
1462
|
+
msgText = marked(msgText);
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
winston.debug("msgText: " + msgText);
|
|
1466
|
+
winston.debug("baseScope: " + JSON.stringify(baseScope));
|
|
1467
|
+
|
|
1468
|
+
|
|
1469
|
+
var replacements = {
|
|
1470
|
+
project: project,
|
|
1471
|
+
request_id: request_id,
|
|
1472
|
+
seamlessPage: sourcePage,
|
|
1473
|
+
msgText: msgText,
|
|
1474
|
+
tokenQueryString: tokenQueryString,
|
|
1475
|
+
baseScope: baseScope
|
|
1476
|
+
};
|
|
1477
|
+
|
|
1478
|
+
var html = template(replacements);
|
|
1479
|
+
winston.debug("html: " + html);
|
|
1480
|
+
|
|
1481
|
+
|
|
1482
|
+
let replyTo;
|
|
1483
|
+
if (this.replyEnabled && request_id) {
|
|
1484
|
+
replyTo = request_id + this.inboundDomainDomainWithAt;
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
let from;
|
|
1488
|
+
let configEmail;
|
|
1489
|
+
if (project && project.settings && project.settings.email) {
|
|
1490
|
+
if (project.settings.email.config) {
|
|
1491
|
+
configEmail = project.settings.email.config;
|
|
1492
|
+
winston.verbose("custom email configEmail setting found: ", configEmail);
|
|
1493
|
+
}
|
|
1494
|
+
if (project.settings.email.from) {
|
|
1495
|
+
from = project.settings.email.from;
|
|
1496
|
+
winston.verbose("custom from email setting found: "+ from);
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
|
|
1501
|
+
// if (message.request && message.request.lead && message.request.lead.email) {
|
|
1502
|
+
// winston.info("message.request.lead.email: " + message.request.lead.email);
|
|
1503
|
+
// replyTo = replyTo + ", "+ message.request.lead.email;
|
|
1504
|
+
// }
|
|
1505
|
+
|
|
1506
|
+
// if (!subject) {
|
|
1507
|
+
// subject = "Tiledesk"
|
|
1508
|
+
// }
|
|
1509
|
+
|
|
1510
|
+
that.send({
|
|
1511
|
+
from:from,
|
|
1512
|
+
to:to,
|
|
1513
|
+
replyTo: replyTo,
|
|
1514
|
+
subject:subject,
|
|
1515
|
+
text:html,
|
|
1516
|
+
html:html,
|
|
1517
|
+
config:configEmail,
|
|
1518
|
+
});
|
|
1519
|
+
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
|
|
1523
|
+
|
|
1404
1524
|
// ok
|
|
1405
1525
|
async sendPasswordResetRequestEmail(to, resetPswRequestId, userFirstname, userLastname) {
|
|
1406
1526
|
|
|
@@ -1616,7 +1736,7 @@ class EmailService {
|
|
|
1616
1736
|
// ok
|
|
1617
1737
|
|
|
1618
1738
|
async sendRequestTranscript(to, messages, request, project) {
|
|
1619
|
-
|
|
1739
|
+
winston.debug("sendRequestTranscript: "+to);
|
|
1620
1740
|
|
|
1621
1741
|
//if the request came from rabbit mq?
|
|
1622
1742
|
if (request.toJSON) {
|
|
@@ -1664,13 +1784,33 @@ async sendRequestTranscript(to, messages, request, project) {
|
|
|
1664
1784
|
|
|
1665
1785
|
var html = template(replacements);
|
|
1666
1786
|
|
|
1787
|
+
|
|
1788
|
+
|
|
1789
|
+
let from;
|
|
1667
1790
|
let configEmail;
|
|
1668
|
-
if (project && project.settings && project.settings.email
|
|
1669
|
-
|
|
1670
|
-
|
|
1791
|
+
if (project && project.settings && project.settings.email) {
|
|
1792
|
+
if (project.settings.email.config) {
|
|
1793
|
+
configEmail = project.settings.email.config;
|
|
1794
|
+
winston.verbose("custom email configEmail setting found: ", configEmail);
|
|
1795
|
+
}
|
|
1796
|
+
if (project.settings.email.from) {
|
|
1797
|
+
from = project.settings.email.from;
|
|
1798
|
+
winston.verbose("custom from email setting found: "+ from);
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
|
|
1802
|
+
|
|
1803
|
+
|
|
1804
|
+
//custom ocf here
|
|
1805
|
+
// console.log("ocf",project._id);
|
|
1806
|
+
let subject = '[Tiledesk] Transcript';
|
|
1807
|
+
if (project._id =="636a63070d942d001950c023") {
|
|
1808
|
+
subject = "Chiusura richiesta di supporto #" + request.ticket_id;
|
|
1809
|
+
console.log("subject",subject);
|
|
1671
1810
|
}
|
|
1811
|
+
// hcustomization.emailTranscript(to, subject, html, configEmail)
|
|
1672
1812
|
|
|
1673
|
-
that.send({to:to, subject:
|
|
1813
|
+
that.send({from:from, to:to, subject: subject, html:html, config: configEmail});
|
|
1674
1814
|
that.send({to: that.bcc, subject: '[Tiledesk] Transcript - notification', html:html });
|
|
1675
1815
|
|
|
1676
1816
|
}
|
|
@@ -1683,6 +1823,8 @@ async sendRequestTranscript(to, messages, request, project) {
|
|
|
1683
1823
|
|
|
1684
1824
|
var emailService = new EmailService();
|
|
1685
1825
|
|
|
1686
|
-
//
|
|
1826
|
+
// var subject = "abc";
|
|
1827
|
+
// hcustomization.emailTranscript({subject: subject});
|
|
1828
|
+
// console.log("subject", subject);
|
|
1687
1829
|
|
|
1688
1830
|
module.exports = emailService;
|
|
@@ -185,7 +185,7 @@ class FaqBotHandler {
|
|
|
185
185
|
if (clonedfaqs && clonedfaqs.length>0) {
|
|
186
186
|
clonedfaqs = clonedfaqs.shift()
|
|
187
187
|
}
|
|
188
|
-
winston.
|
|
188
|
+
winston.debug("clonedfaqs", clonedfaqs);
|
|
189
189
|
|
|
190
190
|
const intent_info = {
|
|
191
191
|
intent_name: answerObj.intent_display_name,
|
|
@@ -389,7 +389,7 @@ class FaqBotHandler {
|
|
|
389
389
|
if (clonedfaqs && clonedfaqs.length>0) {
|
|
390
390
|
clonedfaqs = clonedfaqs.shift()
|
|
391
391
|
}
|
|
392
|
-
winston.
|
|
392
|
+
winston.debug("clonedfaqs", clonedfaqs);
|
|
393
393
|
|
|
394
394
|
const intent_info = {
|
|
395
395
|
intent_name: answerObj.intent_display_name,
|
|
@@ -468,7 +468,6 @@ class FaqBotHandler {
|
|
|
468
468
|
message.id_project, project_user, "system", undefined);
|
|
469
469
|
}
|
|
470
470
|
|
|
471
|
-
// not sending with ws event with project_user undefined {"_id":"601be8bf5e24bf0012d653be","name":"faqbot.answer_not_found","attributes":{"bot":{"type":"internal","_id":"601baf4d9974d20019469ea8","name":"Bot2","description":"HI,IM","id_project":"60113c4f9974d200191d90d3","trashed":false,"createdBy":"60113ba19974d200191d868a","createdAt":"2021-02-04T08:24:45.137Z","updatedAt":"2021-02-04T08:24:45.137Z","__v":0},"message":{"senderFullname":"IndelishFinal ","type":"text","channel_type":"group","status":0,"_id":"601be8be5e24bf0012d653b7","sender":"acbc3f18-fc6b-41fc-a257-ce68f51f2551","recipient":"support-group-acbc3f18-fc6b-41fc-a257-ce68f51f2551","text":"Chineese","id_project":"60113c4f9974d200191d90d3","createdBy":"acbc3f18-fc6b-41fc-a257-ce68f51f2551","channel":{"name":"chat21"},"createdAt":"2021-02-04T12:29:50.753Z","updatedAt":"2021-02-04T12:29:50.753Z","__v":0,"request":{"_id":"601be8be5e24bf0012d653b4","status":200,"preflight":false,"hasBot":true,"participants":["bot_601baf4d9974d20019469ea8"],"participantsAgents":[],"participantsBots":["601baf4d9974d20019469ea8"],"request_id":"support-group-acbc3f18-fc6b-41fc-a257-ce68f51f2551","requester":{"_id":"601be8945e24bf0012d65311","user_available":true,"number_assigned_requests":0,"last_login_at":"2021-02-04T11:47:39.753Z","status":"active","id_project":"60113c4f9974d200191d90d3","uuid_user":"acbc3f18-fc6b-41fc-a257-ce68f51f2551","role":"guest","createdBy":"acbc3f18-fc6b-41fc-a257-ce68f51f2551","createdAt":"2021-02-04T12:29:08.397Z","updatedAt":"2021-02-04T12:29:08.397Z","__v":0},"lead":{"_id":"601be8be5e24bf0012d653b3","status":100,"lead_id":"acbc3f18-fc6b-41fc-a257-ce68f51f2551","fullname":"IndelishFinal ","id_project":"60113c4f9974d200191d90d3","createdBy":"system","tags":[],"createdAt":"2021-02-04T12:29:50.696Z","updatedAt":"2021-02-04T12:29:50.696Z","__v":0},"first_text":"Chineese","department":{"_id":"60113c4f9974d200191d90d5","routing":"assigned","default":true,"status":1,"name":"Default Department","id_project":"60113c4f9974d200191d90d3","createdBy":"60113ba19974d200191d868a","createdAt":"2021-01-27T10:11:27.117Z","updatedAt":"2021-02-04T08:27:04.354Z","__v":0,"id_bot":"601baf4d9974d20019469ea8","id_group":null,"bot":{"type":"internal","_id":"601baf4d9974d20019469ea8","name":"Bot2","description":"HI,IM","id_project":"60113c4f9974d200191d90d3","trashed":false,"createdBy":"60113ba19974d200191d868a","createdAt":"2021-02-04T08:24:45.137Z","updatedAt":"2021-02-04T08:24:45.137Z","__v":0}},"agents":[{"user_available":false,"number_assigned_requests":4,"last_login_at":"2021-01-21T20:57:22.057Z","status":"active","_id":"601308d89974d2001925e57e","id_project":"60113c4f9974d200191d90d3","id_user":"6012f23e9974d200192594cc","role":"agent","createdBy":"60113ba19974d200191d868a","createdAt":"2021-01-28T18:56:24.213Z","updatedAt":"2021-01-28T18:56:24.213Z","__v":0,"max_assigned_chat":-1},{"user_available":false,"number_assigned_requests":12,"last_login_at":"2021-01-21T20:57:22.057Z","status":"active","_id":"60113c4f9974d200191d90d4","id_project":"60113c4f9974d200191d90d3","id_user":"60113ba19974d200191d868a","role":"owner","createdBy":"60113ba19974d200191d868a","createdAt":"2021-01-27T10:11:27.110Z","updatedAt":"2021-01-27T10:11:27.110Z","__v":0,"presence":{"status":"online","changedAt":"2021-02-04T12:21:50.878Z"},"max_assigned_chat":-1}],"assigned_at":"2021-02-04T12:29:50.732Z","id_project":"60113c4f9974d200191d90d3","createdBy":"acbc3f18-fc6b-41fc-a257-ce68f51f2551","channel":{"name":"chat21"},"tags":[],"notes":[],"channelOutbound":{"name":"chat21"},"createdAt":"2021-02-04T12:29:50.739Z","updatedAt":"2021-02-04T12:29:50.739Z","__v":0,"participatingAgents":[],"participatingBots":[{"_id":"601baf4d9974d20019469ea8","type":"internal","name":"Bot2","description":"HI,IM","id_project":"60113c4f9974d200191d90d3","trashed":false,"createdBy":"60113ba19974d200191d868a","createdAt":"2021-02-04T08:24:45.137Z","updatedAt":"2021-02-04T08:24:45.137Z","__v":0}]}}},"id_project":"60113c4f9974d200191d90d3","createdBy":"system","createdAt":"2021-02-04T12:29:51.074Z","updatedAt":"2021-02-04T12:29:51.074Z","__v":0,"id":"601be8bf5e24bf0012d653be"}
|
|
472
471
|
|
|
473
472
|
var attr = botAns.attributes;
|
|
474
473
|
if (!attr) {
|
package/services/faqService.js
CHANGED
|
@@ -8,7 +8,7 @@ const ActionsConstants = require('../models/actionsConstants');
|
|
|
8
8
|
class FaqService {
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
create(name, url, projectid, user_id, type, description, webhook_url, webhook_enabled, language, template) {
|
|
11
|
+
create(name, url, projectid, user_id, type, description, webhook_url, webhook_enabled, language, template, mainCategory, intentsEngine) {
|
|
12
12
|
var that = this;
|
|
13
13
|
return new Promise(function (resolve, reject) {
|
|
14
14
|
|
|
@@ -22,6 +22,10 @@ class FaqService {
|
|
|
22
22
|
webhook_enabled: webhook_enabled,
|
|
23
23
|
type: type,
|
|
24
24
|
language: language,
|
|
25
|
+
public: false,
|
|
26
|
+
certified: false,
|
|
27
|
+
mainCategory: mainCategory,
|
|
28
|
+
intentsEngine: intentsEngine,
|
|
25
29
|
trashed: false,
|
|
26
30
|
createdBy: user_id,
|
|
27
31
|
updatedBy: user_id
|
|
@@ -39,10 +43,10 @@ class FaqService {
|
|
|
39
43
|
|
|
40
44
|
winston.debug('type '+ type)
|
|
41
45
|
|
|
42
|
-
if (type==="internal") {
|
|
46
|
+
if (type==="internal" || type==="tilebot") {
|
|
43
47
|
|
|
44
48
|
if (!template) {
|
|
45
|
-
template = "
|
|
49
|
+
template = "empty";
|
|
46
50
|
}
|
|
47
51
|
winston.debug('template '+ template);
|
|
48
52
|
that.createGreetingsAndOperationalsFaqs(savedFaq_kb._id, savedFaq_kb.createdBy, savedFaq_kb.id_project, template);
|
|
@@ -63,6 +67,7 @@ class FaqService {
|
|
|
63
67
|
|
|
64
68
|
// aggiungi esempio tdAction con intent_id
|
|
65
69
|
|
|
70
|
+
// TODO non scatta i trigger sui rest hook. fare?
|
|
66
71
|
winston.debug('template: '+ template);
|
|
67
72
|
|
|
68
73
|
var faqsArray;
|
|
@@ -113,6 +118,10 @@ class FaqService {
|
|
|
113
118
|
]
|
|
114
119
|
|
|
115
120
|
}
|
|
121
|
+
|
|
122
|
+
if (template === "empty") {
|
|
123
|
+
faqsArray = [];
|
|
124
|
+
}
|
|
116
125
|
|
|
117
126
|
|
|
118
127
|
faqsArray.forEach(faq => {
|
|
@@ -121,6 +130,7 @@ class FaqService {
|
|
|
121
130
|
id_faq_kb: faq_kb_id,
|
|
122
131
|
question: faq.question,
|
|
123
132
|
answer: faq.answer,
|
|
133
|
+
reply: faq.reply,
|
|
124
134
|
intent_display_name: faq.intent_display_name,
|
|
125
135
|
language: "en",
|
|
126
136
|
id_project: projectid,
|
|
@@ -144,6 +154,21 @@ class FaqService {
|
|
|
144
154
|
});
|
|
145
155
|
}
|
|
146
156
|
|
|
157
|
+
getAll(faq_kb_id) {
|
|
158
|
+
|
|
159
|
+
winston.debug("(Service) GET ALL FAQ OF THE BOT ID (req.query): ", faq_kb_id);
|
|
160
|
+
|
|
161
|
+
return new Promise((resolve, reject) => {
|
|
162
|
+
|
|
163
|
+
Faq.find({ id_faq_kb: faq_kb_id}, (err, faqs) => {
|
|
164
|
+
if (err) {
|
|
165
|
+
reject(err);
|
|
166
|
+
}
|
|
167
|
+
resolve(faqs);
|
|
168
|
+
}).lean().exec()
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
|
|
147
172
|
|
|
148
173
|
}
|
|
149
174
|
|
package/services/geoService.js
CHANGED
|
@@ -8,6 +8,13 @@ var geoip = require('geoip-lite');
|
|
|
8
8
|
|
|
9
9
|
class GeoService {
|
|
10
10
|
|
|
11
|
+
constructor() {
|
|
12
|
+
this.enabled = true;
|
|
13
|
+
if (process.env.GEO_SERVICE_ENABLED=="false" || process.env.GEO_SERVICE_ENABLED==false) {
|
|
14
|
+
this.enabled = false;
|
|
15
|
+
}
|
|
16
|
+
winston.debug("GeoService this.enabled: "+ this.enabled);
|
|
17
|
+
}
|
|
11
18
|
|
|
12
19
|
|
|
13
20
|
// https://medium.com/@rossbulat/node-js-client-ip-location-with-geoip-lite-fallback-c25833c94a76
|
|
@@ -16,7 +23,12 @@ class GeoService {
|
|
|
16
23
|
|
|
17
24
|
listen() {
|
|
18
25
|
|
|
19
|
-
|
|
26
|
+
if (this.enabled==true) {
|
|
27
|
+
winston.info("GeoService listener started");
|
|
28
|
+
} else {
|
|
29
|
+
return winston.info("GeoService listener disabled");
|
|
30
|
+
}
|
|
31
|
+
|
|
20
32
|
|
|
21
33
|
|
|
22
34
|
|
|
@@ -36,15 +48,25 @@ class GeoService {
|
|
|
36
48
|
// area: 200 }
|
|
37
49
|
|
|
38
50
|
|
|
39
|
-
requestEvent.on('request.create', function(request) {
|
|
40
51
|
|
|
41
|
-
|
|
52
|
+
var requestCreateKey = 'request.create';
|
|
53
|
+
if (requestEvent.queueEnabled) {
|
|
54
|
+
requestCreateKey = 'request.create.queue';
|
|
55
|
+
}
|
|
56
|
+
winston.debug('GeoService requestCreateKey: ' + requestCreateKey);
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
requestEvent.on(requestCreateKey, function(request) {
|
|
60
|
+
|
|
61
|
+
setImmediate(() => {
|
|
62
|
+
|
|
63
|
+
winston.debug("request", request);
|
|
42
64
|
|
|
43
65
|
var ip = (request.location && request.location.ipAddress) || (request.attributes && request.attributes.ipAddress);
|
|
44
66
|
winston.debug("ip" + ip);
|
|
45
67
|
if (ip) {
|
|
46
68
|
var geo = geoip.lookup(ip);
|
|
47
|
-
winston.
|
|
69
|
+
winston.debug("Geo result", geo);
|
|
48
70
|
|
|
49
71
|
// var update = {};
|
|
50
72
|
if (geo) {
|
|
@@ -106,7 +128,11 @@ class GeoService {
|
|
|
106
128
|
|
|
107
129
|
winston.debug("geo request saving", request);
|
|
108
130
|
|
|
109
|
-
|
|
131
|
+
|
|
132
|
+
if (request.markModified) {
|
|
133
|
+
request.markModified('location');
|
|
134
|
+
}
|
|
135
|
+
|
|
110
136
|
request.save(function(err, reqL) {
|
|
111
137
|
// return Request.findByIdAndUpdate("5fb297bd1d838b14607b3b62", update, { new: true, upsert: false }).exec( function(err, reqL) {
|
|
112
138
|
if (err) {
|
|
@@ -114,11 +140,15 @@ class GeoService {
|
|
|
114
140
|
}
|
|
115
141
|
return winston.verbose("Saved location metadata for request with id " + request._id);
|
|
116
142
|
});
|
|
143
|
+
|
|
144
|
+
//TODO AGGIORNA ANCHE LEAD e req.snapshot.lead?
|
|
145
|
+
// leggi ip da request e nn da attributes
|
|
117
146
|
|
|
118
147
|
}
|
|
119
148
|
}
|
|
120
149
|
});
|
|
121
|
-
|
|
150
|
+
});
|
|
151
|
+
}
|
|
122
152
|
|
|
123
153
|
|
|
124
154
|
}
|
package/services/labelService.js
CHANGED
|
@@ -74,7 +74,7 @@ getAll(id_project) {
|
|
|
74
74
|
|
|
75
75
|
|
|
76
76
|
return Label.findOne(query).lean()
|
|
77
|
-
//@DISABLED_CACHE .cache(cacheUtil.longTTL, id_project+":labels:query:all")
|
|
77
|
+
//@DISABLED_CACHE .cache(cacheUtil.longTTL, id_project+":labels:query:all") //label_cache
|
|
78
78
|
.exec(function (err, labels) {
|
|
79
79
|
if (err) {
|
|
80
80
|
winston.error('Label ROUTE - REQUEST FIND ERR ', err)
|
package/services/leadService.js
CHANGED
|
@@ -14,7 +14,7 @@ class LeadService {
|
|
|
14
14
|
var that = this;
|
|
15
15
|
return new Promise(function (resolve, reject) {
|
|
16
16
|
return Lead.findOne({email: email, id_project: id_project})
|
|
17
|
-
//@DISABLED_CACHE .cache(cacheUtil.defaultTTL, id_project+":leads:email:"+email)
|
|
17
|
+
//@DISABLED_CACHE .cache(cacheUtil.defaultTTL, id_project+":leads:email:"+email) //lead_cache
|
|
18
18
|
.exec(function(err, lead) {
|
|
19
19
|
if (err) {
|
|
20
20
|
return reject(err);
|
|
@@ -58,7 +58,7 @@ class LeadService {
|
|
|
58
58
|
var that = this;
|
|
59
59
|
return new Promise(function (resolve, reject) {
|
|
60
60
|
return Lead.findOne({lead_id: lead_id, id_project: id_project})
|
|
61
|
-
//@DISABLED_CACHE .cache(cacheUtil.defaultTTL, id_project+":leads:lead_id:"+lead_id)
|
|
61
|
+
//@DISABLED_CACHE .cache(cacheUtil.defaultTTL, id_project+":leads:lead_id:"+lead_id) //lead_cache
|
|
62
62
|
.exec(function(err, lead) {
|
|
63
63
|
if (err) {
|
|
64
64
|
winston.error("Error createIfNotExistsWithLeadId", err);
|
|
@@ -130,6 +130,7 @@ class LeadService {
|
|
|
130
130
|
leadEvent.emit('lead.update', updatedLead);
|
|
131
131
|
leadEvent.emit('lead.email.update', updatedLead);
|
|
132
132
|
leadEvent.emit('lead.fullname.update', updatedLead);
|
|
133
|
+
leadEvent.emit('lead.fullname.email.update', updatedLead);
|
|
133
134
|
return resolve(updatedLead);
|
|
134
135
|
});
|
|
135
136
|
});
|
|
@@ -17,7 +17,7 @@ class MessageService {
|
|
|
17
17
|
if (!id) {
|
|
18
18
|
return this.create(sender, senderFullname, recipient, text, id_project, createdBy, status, attributes, type, metadata, language);
|
|
19
19
|
} else {
|
|
20
|
-
winston.debug("Message changeStatus"
|
|
20
|
+
winston.debug("Message upsert changeStatus:"+ status);
|
|
21
21
|
return this.changeStatus(id, status);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -173,7 +173,10 @@ class MessageService {
|
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
// TODO must update also message.attributes from chat21
|
|
176
|
+
// attento già scatta su chat21handler
|
|
177
|
+
|
|
176
178
|
changeStatus(message_id, newstatus) {
|
|
179
|
+
winston.debug("changeStatus. "+message_id + " "+ newstatus);
|
|
177
180
|
var that = this;
|
|
178
181
|
return new Promise(function (resolve, reject) {
|
|
179
182
|
// winston.debug("request_id", request_id);
|
|
@@ -188,7 +191,6 @@ class MessageService {
|
|
|
188
191
|
// winston.debug("updatedMessage", updatedMessage);
|
|
189
192
|
|
|
190
193
|
that.emitMessage(updatedMessage);
|
|
191
|
-
|
|
192
194
|
return resolve(updatedMessage);
|
|
193
195
|
});
|
|
194
196
|
});
|