@tiledesk/tiledesk-server 2.4.36 → 2.4.38

Sign up to get free protection for your applications and to get access to all the features.
package/routes/faq.js CHANGED
@@ -6,8 +6,10 @@ var multer = require('multer')
6
6
  var upload = multer()
7
7
  const faqBotEvent = require('../event/faqBotEvent');
8
8
  var winston = require('../config/winston');
9
+ const faqEvent = require('../event/faqBotEvent')
9
10
 
10
11
  var parsecsv = require("fast-csv");
12
+ const botEvent = require('../event/botEvent');
11
13
  csv = require('csv-express');
12
14
  csv.separator = ';';
13
15
 
@@ -135,6 +137,10 @@ router.post('/', function (req, res) {
135
137
  newFaq.actions = req.body.actions
136
138
  }
137
139
 
140
+ if (req.body.attributes) {
141
+ newFaq.attributes = req.body.attributes
142
+ }
143
+
138
144
  newFaq.save(function (err, savedFaq) {
139
145
  if (err) {
140
146
  if (err.code == 11000) {
@@ -159,6 +165,56 @@ router.post('/', function (req, res) {
159
165
  });
160
166
  });
161
167
 
168
+ router.patch('/:faqid/attributes', function (req, res) {
169
+ let data = req.body;
170
+ console.log("data: ", data);
171
+
172
+ Faq.findById(req.params.faqid, function (err, updatedFaq) {
173
+ if (err) {
174
+ winston.error('Find Faq by id ERROR: ', err);
175
+ return res.status(500).send({ success: false, msg: 'Error updating object.' });
176
+ }
177
+
178
+ if (!updatedFaq) {
179
+ return res.status(404).send({ success: false, msg: 'Object not found.' });
180
+ }
181
+
182
+ if (!updatedFaq.attributes) {
183
+ console.log("empty attributes");
184
+ winston.debug("empty attributes");
185
+ updatedFaq.attributes = {};
186
+ }
187
+
188
+ winston.debug("updatedFaq attributes", updatedFaq.attributes);
189
+
190
+ Object.keys(data).forEach(function(key) {
191
+ var val = data[key];
192
+ winston.debug("data attributes" + key + " " + val);
193
+ updatedFaq.attributes[key] = val;
194
+ })
195
+
196
+ console.log("updatedFaq: ", updatedFaq);
197
+ console.log("updatedFaq attributes: ", updatedFaq.attributes);
198
+
199
+ winston.debug("updatedBot attributes", updatedFaq.attributes)
200
+
201
+ updatedFaq.markModified('attributes');
202
+
203
+ //cache invalidation
204
+ updatedFaq.save(function (err, savedFaq) {
205
+ if (err) {
206
+ winston.error("saving faq attributes ERROR: ", err);
207
+ return res.status(500).send({ success: false, msg: 'Error saving object.' });
208
+ }
209
+
210
+ console.log("saved faq attributes", savedFaq.toObject());
211
+
212
+ winston.verbose("saved faq attributes", savedFaq.toObject());
213
+ faqBotEvent.emit('faq.update', savedFaq);
214
+ res.json(savedFaq);
215
+ })
216
+ })
217
+ })
162
218
 
163
219
  router.put('/:faqid', function (req, res) {
164
220
 
@@ -202,6 +258,9 @@ router.put('/:faqid', function (req, res) {
202
258
  if (req.body.actions != undefined) {
203
259
  update.actions = req.body.actions;
204
260
  }
261
+ if (req.body.attributes != undefined) {
262
+ update.attributes = req.body.attributes;
263
+ }
205
264
 
206
265
  Faq.findByIdAndUpdate(req.params.faqid, update, { new: true, upsert: true }, function (err, updatedFaq) {
207
266
  if (err) {
@@ -401,9 +401,9 @@ class EmailService {
401
401
  "X-TILEDESK-TICKET-ID":request.ticket_id,
402
402
  };
403
403
 
404
- winston.verbose("messageId: " + messageId);
405
- winston.verbose("replyTo: " + replyTo);
406
- winston.verbose("email headers", headers);
404
+ winston.debug("messageId: " + messageId);
405
+ winston.debug("replyTo: " + replyTo);
406
+ winston.debug("email headers", headers);
407
407
  }
408
408
 
409
409
  let inReplyTo;
@@ -416,19 +416,19 @@ class EmailService {
416
416
  references = request.attributes.email_references;
417
417
  }
418
418
  }
419
- winston.verbose("email inReplyTo: "+ inReplyTo);
420
- winston.verbose("email references: "+ references);
419
+ winston.debug("email inReplyTo: "+ inReplyTo);
420
+ winston.debug("email references: "+ references);
421
421
 
422
422
  let from;
423
423
  let configEmail;
424
424
  if (project && project.settings && project.settings.email) {
425
425
  if (project.settings.email.config) {
426
426
  configEmail = project.settings.email.config;
427
- winston.verbose("custom email configEmail setting found: ", configEmail);
427
+ winston.debug("custom email configEmail setting found: ", configEmail);
428
428
  }
429
429
  if (project.settings.email.from) {
430
430
  from = project.settings.email.from;
431
- winston.verbose("custom from email setting found: "+ from);
431
+ winston.debug("custom from email setting found: "+ from);
432
432
  }
433
433
  }
434
434
 
@@ -554,9 +554,9 @@ class EmailService {
554
554
 
555
555
  headers = {"X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": message.request.request_id, "X-TILEDESK-TICKET-ID":message.request.ticket_id };
556
556
 
557
- winston.verbose("sendNewAssignedAgentMessageEmailNotification messageId: " + messageId);
558
- winston.verbose("sendNewAssignedAgentMessageEmailNotification replyTo: " + replyTo);
559
- winston.verbose("sendNewAssignedAgentMessageEmailNotification email headers", headers);
557
+ winston.debug("sendNewAssignedAgentMessageEmailNotification messageId: " + messageId);
558
+ winston.debug("sendNewAssignedAgentMessageEmailNotification replyTo: " + replyTo);
559
+ winston.debug("sendNewAssignedAgentMessageEmailNotification email headers", headers);
560
560
  }
561
561
 
562
562
  let inReplyTo;
@@ -569,19 +569,19 @@ class EmailService {
569
569
  references = message.request.attributes.email_references;
570
570
  }
571
571
  }
572
- winston.verbose("sendNewAssignedAgentMessageEmailNotification email inReplyTo: "+ inReplyTo);
573
- winston.verbose("sendNewAssignedAgentMessageEmailNotification email references: "+ references);
572
+ winston.debug("sendNewAssignedAgentMessageEmailNotification email inReplyTo: "+ inReplyTo);
573
+ winston.debug("sendNewAssignedAgentMessageEmailNotification email references: "+ references);
574
574
 
575
575
  let from;
576
576
  let configEmail;
577
577
  if (project && project.settings && project.settings.email) {
578
578
  if (project.settings.email.config) {
579
579
  configEmail = project.settings.email.config;
580
- winston.verbose("sendNewAssignedAgentMessageEmailNotification custom email configEmail setting found: ", configEmail);
580
+ winston.debug("sendNewAssignedAgentMessageEmailNotification custom email configEmail setting found: ", configEmail);
581
581
  }
582
582
  if (project.settings.email.from) {
583
583
  from = project.settings.email.from;
584
- winston.verbose("sendNewAssignedAgentMessageEmailNotification custom from email setting found: "+ from);
584
+ winston.debug("sendNewAssignedAgentMessageEmailNotification custom from email setting found: "+ from);
585
585
  }
586
586
  }
587
587
 
@@ -671,7 +671,7 @@ class EmailService {
671
671
  msgText = marked(msgText);
672
672
  }
673
673
 
674
- winston.verbose("msgText: " + msgText);
674
+ winston.debug("msgText: " + msgText);
675
675
 
676
676
  var replacements = {
677
677
  request: request,
@@ -701,9 +701,9 @@ class EmailService {
701
701
 
702
702
  headers = {"X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": request.request_id, "X-TILEDESK-TICKET-ID":request.ticket_id };
703
703
 
704
- winston.verbose("sendNewPooledRequestNotification messageId: " + messageId);
705
- winston.verbose("sendNewPooledRequestNotification replyTo: " + replyTo);
706
- winston.verbose("sendNewPooledRequestNotification email headers", headers);
704
+ winston.debug("sendNewPooledRequestNotification messageId: " + messageId);
705
+ winston.debug("sendNewPooledRequestNotification replyTo: " + replyTo);
706
+ winston.debug("sendNewPooledRequestNotification email headers", headers);
707
707
  }
708
708
 
709
709
  let inReplyTo;
@@ -716,19 +716,19 @@ class EmailService {
716
716
  references = request.attributes.email_references;
717
717
  }
718
718
  }
719
- winston.verbose("sendNewPooledRequestNotification email inReplyTo: "+ inReplyTo);
720
- winston.verbose("sendNewPooledRequestNotification email references: "+ references);
719
+ winston.debug("sendNewPooledRequestNotification email inReplyTo: "+ inReplyTo);
720
+ winston.debug("sendNewPooledRequestNotification email references: "+ references);
721
721
 
722
722
  let from;
723
723
  let configEmail;
724
724
  if (project && project.settings && project.settings.email) {
725
725
  if (project.settings.email.config) {
726
726
  configEmail = project.settings.email.config;
727
- winston.verbose("sendNewPooledRequestNotification custom email configEmail setting found: ", configEmail);
727
+ winston.debug("sendNewPooledRequestNotification custom email configEmail setting found: ", configEmail);
728
728
  }
729
729
  if (project.settings.email.from) {
730
730
  from = project.settings.email.from;
731
- winston.verbose("sendNewPooledRequestNotification custom from email setting found: "+ from);
731
+ winston.debug("sendNewPooledRequestNotification custom from email setting found: "+ from);
732
732
  }
733
733
  }
734
734
 
@@ -807,7 +807,7 @@ class EmailService {
807
807
  msgText = marked(msgText);
808
808
  }
809
809
 
810
- winston.verbose("msgText: " + msgText);
810
+ winston.debug("msgText: " + msgText);
811
811
 
812
812
  // passa anche tutti i messages in modo da stampare tutto
813
813
  // Stampa anche contact.email
@@ -845,9 +845,9 @@ class EmailService {
845
845
 
846
846
  headers = {"X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": message.request.request_id, "X-TILEDESK-TICKET-ID":message.request.ticket_id };
847
847
 
848
- winston.verbose("sendNewPooledMessageEmailNotification messageId: " + messageId);
849
- winston.verbose("sendNewPooledMessageEmailNotification replyTo: " + replyTo);
850
- winston.verbose("sendNewPooledMessageEmailNotification email headers", headers);
848
+ winston.debug("sendNewPooledMessageEmailNotification messageId: " + messageId);
849
+ winston.debug("sendNewPooledMessageEmailNotification replyTo: " + replyTo);
850
+ winston.debug("sendNewPooledMessageEmailNotification email headers", headers);
851
851
  }
852
852
 
853
853
  let inReplyTo;
@@ -860,19 +860,19 @@ class EmailService {
860
860
  references = message.request.attributes.email_references;
861
861
  }
862
862
  }
863
- winston.verbose("sendNewPooledMessageEmailNotification email inReplyTo: "+ inReplyTo);
864
- winston.verbose("sendNewPooledMessageEmailNotification email references: "+ references);
863
+ winston.debug("sendNewPooledMessageEmailNotification email inReplyTo: "+ inReplyTo);
864
+ winston.debug("sendNewPooledMessageEmailNotification email references: "+ references);
865
865
 
866
866
  let from;
867
867
  let configEmail;
868
868
  if (project && project.settings && project.settings.email) {
869
869
  if (project.settings.email.config) {
870
870
  configEmail = project.settings.email.config;
871
- winston.verbose("sendNewPooledMessageEmailNotification custom email configEmail setting found: ", configEmail);
871
+ winston.debug("sendNewPooledMessageEmailNotification custom email configEmail setting found: ", configEmail);
872
872
  }
873
873
  if (project.settings.email.from) {
874
874
  from = project.settings.email.from;
875
- winston.verbose("sendNewPooledMessageEmailNotification custom from email setting found: "+ from);
875
+ winston.debug("sendNewPooledMessageEmailNotification custom from email setting found: "+ from);
876
876
  }
877
877
  }
878
878
 
@@ -990,9 +990,9 @@ class EmailService {
990
990
 
991
991
  headers = {"X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": message.request.request_id, "X-TILEDESK-TICKET-ID":message.request.ticket_id };
992
992
 
993
- winston.verbose("messageId: " + messageId);
994
- winston.verbose("replyTo: " + replyTo);
995
- winston.verbose("email headers", headers);
993
+ winston.debug("messageId: " + messageId);
994
+ winston.debug("replyTo: " + replyTo);
995
+ winston.debug("email headers", headers);
996
996
  }
997
997
 
998
998
  let inReplyTo;
@@ -1006,19 +1006,19 @@ class EmailService {
1006
1006
  references = message.request.attributes.email_references;
1007
1007
  }
1008
1008
  }
1009
- winston.verbose("email inReplyTo: "+ inReplyTo);
1010
- winston.verbose("email references: "+ references);
1009
+ winston.debug("email inReplyTo: "+ inReplyTo);
1010
+ winston.debug("email references: "+ references);
1011
1011
 
1012
1012
  let from;
1013
1013
  let configEmail;
1014
1014
  if (project && project.settings && project.settings.email) {
1015
1015
  if (project.settings.email.config) {
1016
1016
  configEmail = project.settings.email.config;
1017
- winston.verbose("custom email configEmail setting found: ", configEmail);
1017
+ winston.debug("custom email configEmail setting found: ", configEmail);
1018
1018
  }
1019
1019
  if (project.settings.email.from) {
1020
1020
  from = project.settings.email.from;
1021
- winston.verbose("custom from email setting found: "+ from);
1021
+ winston.debug("custom from email setting found: "+ from);
1022
1022
  }
1023
1023
  }
1024
1024
 
@@ -1128,9 +1128,9 @@ class EmailService {
1128
1128
 
1129
1129
  headers = {"X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": message.request.request_id, "X-TILEDESK-TICKET-ID":message.request.ticket_id };
1130
1130
 
1131
- winston.verbose("messageId: " + messageId);
1132
- winston.verbose("replyTo: " + replyTo);
1133
- winston.verbose("email headers", headers);
1131
+ winston.debug("messageId: " + messageId);
1132
+ winston.debug("replyTo: " + replyTo);
1133
+ winston.debug("email headers", headers);
1134
1134
  }
1135
1135
 
1136
1136
 
@@ -1161,21 +1161,21 @@ class EmailService {
1161
1161
  }
1162
1162
 
1163
1163
  }
1164
- winston.verbose("email inReplyTo: "+ inReplyTo);
1165
- winston.verbose("email references: "+ references);
1166
- winston.verbose("email cc: ", cc);
1167
- winston.verbose("email ccString: "+ ccString);
1164
+ winston.debug("email inReplyTo: "+ inReplyTo);
1165
+ winston.debug("email references: "+ references);
1166
+ winston.debug("email cc: ", cc);
1167
+ winston.debug("email ccString: "+ ccString);
1168
1168
 
1169
1169
  let from;
1170
1170
  let configEmail;
1171
1171
  if (project && project.settings && project.settings.email) {
1172
1172
  if (project.settings.email.config) {
1173
1173
  configEmail = project.settings.email.config;
1174
- winston.verbose("custom email configEmail setting found: ", configEmail);
1174
+ winston.debug("custom email configEmail setting found: ", configEmail);
1175
1175
  }
1176
1176
  if (project.settings.email.from) {
1177
1177
  from = project.settings.email.from;
1178
- winston.verbose("custom from email setting found: "+ from);
1178
+ winston.debug("custom from email setting found: "+ from);
1179
1179
  }
1180
1180
  }
1181
1181
 
@@ -1312,9 +1312,9 @@ class EmailService {
1312
1312
 
1313
1313
  headers = {"X-TILEDESK-PROJECT-ID": project._id, "X-TILEDESK-REQUEST-ID": message.request.request_id, "X-TILEDESK-TICKET-ID":message.request.ticket_id };
1314
1314
 
1315
- winston.verbose("messageId: " + messageId);
1316
- winston.verbose("replyTo: " + replyTo);
1317
- winston.verbose("email headers", headers);
1315
+ winston.debug("messageId: " + messageId);
1316
+ winston.debug("replyTo: " + replyTo);
1317
+ winston.debug("email headers", headers);
1318
1318
  }
1319
1319
 
1320
1320
 
@@ -1344,21 +1344,21 @@ class EmailService {
1344
1344
  }
1345
1345
  }
1346
1346
  }
1347
- winston.verbose("email inReplyTo: "+ inReplyTo);
1348
- winston.verbose("email references: "+ references);
1349
- winston.verbose("email cc: ", cc);
1350
- winston.verbose("email ccString: "+ ccString);
1347
+ winston.debug("email inReplyTo: "+ inReplyTo);
1348
+ winston.debug("email references: "+ references);
1349
+ winston.debug("email cc: ", cc);
1350
+ winston.debug("email ccString: "+ ccString);
1351
1351
 
1352
1352
  let from;
1353
1353
  let configEmail;
1354
1354
  if (project && project.settings && project.settings.email) {
1355
1355
  if (project.settings.email.config) {
1356
1356
  configEmail = project.settings.email.config;
1357
- winston.verbose("custom email configEmail setting found: ", configEmail);
1357
+ winston.debug("custom email configEmail setting found: ", configEmail);
1358
1358
  }
1359
1359
  if (project.settings.email.from) {
1360
1360
  from = project.settings.email.from;
1361
- winston.verbose("custom from email setting found: "+ from);
1361
+ winston.debug("custom from email setting found: "+ from);
1362
1362
  }
1363
1363
  }
1364
1364
 
@@ -1457,7 +1457,7 @@ class EmailService {
1457
1457
 
1458
1458
 
1459
1459
 
1460
- async sendEmailDirect(to, text, project, request_id, subject, tokenQueryString, sourcePage, payload) {
1460
+ async sendEmailDirect(to, text, project, request_id, subject, tokenQueryString, sourcePage, payload, replyTo) {
1461
1461
 
1462
1462
  var that = this;
1463
1463
 
@@ -1507,8 +1507,9 @@ async sendEmailDirect(to, text, project, request_id, subject, tokenQueryString,
1507
1507
  winston.debug("html: " + html);
1508
1508
 
1509
1509
 
1510
- let replyTo;
1511
- if (this.replyEnabled && request_id) {
1510
+ // let replyTo;
1511
+
1512
+ if (!replyTo && this.replyEnabled && request_id) {
1512
1513
  replyTo = request_id + this.inboundDomainDomainWithAt;
1513
1514
  }
1514
1515
 
@@ -1517,11 +1518,11 @@ async sendEmailDirect(to, text, project, request_id, subject, tokenQueryString,
1517
1518
  if (project && project.settings && project.settings.email) {
1518
1519
  if (project.settings.email.config) {
1519
1520
  configEmail = project.settings.email.config;
1520
- winston.verbose("custom email configEmail setting found: ", configEmail);
1521
+ winston.debug("custom email configEmail setting found: ", configEmail);
1521
1522
  }
1522
1523
  if (project.settings.email.from) {
1523
1524
  from = project.settings.email.from;
1524
- winston.verbose("custom from email setting found: "+ from);
1525
+ winston.debug("custom from email setting found: "+ from);
1525
1526
  }
1526
1527
  }
1527
1528
 
@@ -1820,11 +1821,11 @@ async sendRequestTranscript(to, messages, request, project) {
1820
1821
  if (project && project.settings && project.settings.email) {
1821
1822
  if (project.settings.email.config) {
1822
1823
  configEmail = project.settings.email.config;
1823
- winston.verbose("custom email configEmail setting found: ", configEmail);
1824
+ winston.debug("custom email configEmail setting found: ", configEmail);
1824
1825
  }
1825
1826
  if (project.settings.email.from) {
1826
1827
  from = project.settings.email.from;
1827
- winston.verbose("custom from email setting found: "+ from);
1828
+ winston.debug("custom from email setting found: "+ from);
1828
1829
  }
1829
1830
  }
1830
1831
 
@@ -1878,11 +1879,11 @@ parseText(text, payload) {
1878
1879
  formatText(templateName, defaultText, payload, settings) {
1879
1880
 
1880
1881
  let text = defaultText;
1881
- winston.verbose("formatText defaultText: "+ defaultText);
1882
+ winston.debug("formatText defaultText: "+ defaultText);
1882
1883
 
1883
1884
  let template = this.getTemplate(templateName, settings);
1884
1885
 
1885
- winston.verbose("formatText template: "+ template);
1886
+ winston.debug("formatText template: "+ template);
1886
1887
 
1887
1888
  if (template) {
1888
1889
  text = template;
@@ -1891,7 +1892,7 @@ formatText(templateName, defaultText, payload, settings) {
1891
1892
  var baseScope = JSON.parse(JSON.stringify(this));
1892
1893
  delete baseScope.pass;
1893
1894
 
1894
- winston.verbose("formatText text: "+ text);
1895
+ winston.debug("formatText text: "+ text);
1895
1896
 
1896
1897
  var templateHand = handlebars.compile(text);
1897
1898
 
@@ -1902,7 +1903,7 @@ formatText(templateName, defaultText, payload, settings) {
1902
1903
  };
1903
1904
 
1904
1905
  var textTemplate = templateHand(replacements);
1905
- winston.verbose("formatText textTemplate: "+ textTemplate);
1906
+ winston.debug("formatText textTemplate: "+ textTemplate);
1906
1907
 
1907
1908
  return textTemplate;
1908
1909
 
@@ -1911,21 +1912,21 @@ formatText(templateName, defaultText, payload, settings) {
1911
1912
  getTemplate(templateName, settings) {
1912
1913
 
1913
1914
  var that = this;
1914
- winston.verbose('getTemplate formatSubject: ' + JSON.stringify(settings));
1915
+ winston.debug('getTemplate formatSubject: ' + JSON.stringify(settings));
1915
1916
 
1916
1917
 
1917
1918
  if (settings && settings.email && settings.email.templates) {
1918
- winston.verbose('getTemplate settings.email.templates: ',settings.email.templates);
1919
+ winston.debug('getTemplate settings.email.templates: ',settings.email.templates);
1919
1920
 
1920
1921
  var templates = settings.email.templates;
1921
- winston.verbose('getTemplate templates: ',templates);
1922
+ winston.debug('getTemplate templates: ',templates);
1922
1923
 
1923
1924
  var templateDbName = templateName.replace(".subject", "");
1924
- winston.verbose('getTemplate templateDbName: '+templateDbName);
1925
+ winston.debug('getTemplate templateDbName: '+templateDbName);
1925
1926
 
1926
1927
 
1927
1928
  var template = templates[templateDbName];
1928
- winston.verbose('getTemplate template: '+template);
1929
+ winston.debug('getTemplate template: '+template);
1929
1930
 
1930
1931
  if (template) {
1931
1932
  // that.callback(template);
@@ -145,14 +145,15 @@ class ModulesManager {
145
145
 
146
146
 
147
147
  try {
148
- this.stripe = require('@tiledesk-ent/tiledesk-server-payments').stripeRoute;
148
+ this.stripe = require('../pubmodules/s').stripeRoute;
149
+ // this.stripe = require('@tiledesk-ent/tiledesk-server-payments').stripeRoute;
149
150
  winston.info("ModulesManager stripe initialized");
150
151
  } catch(err) {
151
152
  // if (err.code == 'MODULE_NOT_FOUND') {
152
153
  // winston.info("ModulesManager init stripe module not found");
153
154
  // }else {
154
155
  winston.error("ModulesManager error initializing init stripe module", err);
155
- // }
156
+ // }
156
157
  }
157
158
 
158
159