@tiledesk/tiledesk-server 2.7.22 → 2.7.24

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,13 @@
5
5
  🚀 IN PRODUCTION 🚀
6
6
  (https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77)
7
7
 
8
+ # 2.7.24
9
+ - Updated whatsapp-jobworker to 0.0.8
10
+ - Updated knowledge base route
11
+
12
+ # 2.7.23
13
+ - Updated tybot-connector to 0.2.69
14
+
8
15
  # 2.7.22
9
16
  - Updated whatsapp-connector to 0.1.72
10
17
 
package/app.js CHANGED
@@ -142,7 +142,7 @@ var urls = require('./routes/urls');
142
142
  var email = require('./routes/email');
143
143
  var property = require('./routes/property');
144
144
  var segment = require('./routes/segment');
145
-
145
+ var webhook = require('./routes/webhook');
146
146
 
147
147
  var bootDataLoader = require('./services/bootDataLoader');
148
148
  var settingDataLoader = require('./services/settingDataLoader');
@@ -199,9 +199,9 @@ let whatsappQueue = require('@tiledesk/tiledesk-whatsapp-jobworker');
199
199
  winston.info("whatsappQueue");
200
200
  jobsManager.listenWhatsappQueue(whatsappQueue);
201
201
 
202
- let trainingQueue = require('@tiledesk/tiledesk-train-jobworker');
203
- winston.info("trainingQueue");
204
- jobsManager.listenTrainingQueue(trainingQueue);
202
+ // let trainingQueue = require('@tiledesk/tiledesk-train-jobworker');
203
+ // winston.info("trainingQueue");
204
+ // jobsManager.listenTrainingQueue(trainingQueue);
205
205
 
206
206
 
207
207
  var channelManager = require('./channels/channelManager');
@@ -503,6 +503,8 @@ app.use('/users_util', usersUtil);
503
503
  // app.use('/logs', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], logs);
504
504
  app.use('/requests_util', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken], requestUtilRoot);
505
505
 
506
+ app.use('/webhook', webhook);
507
+
506
508
  // TODO security issues
507
509
  if (process.env.DISABLE_TRANSCRIPT_VIEW_PAGE ) {
508
510
  winston.info(" Transcript view page is disabled");
package/jobs.js CHANGED
@@ -104,9 +104,9 @@ async function main()
104
104
  winston.info("whatsappQueue");
105
105
  jobsManager.listenWhatsappQueue(whatsappQueue);
106
106
 
107
- let trainingQueue = require('@tiledesk/tiledesk-train-jobworker');
108
- winston.info("trainingQueue");
109
- jobsManager.listenTrainingQueue(trainingQueue);
107
+ // let trainingQueue = require('@tiledesk/tiledesk-train-jobworker');
108
+ // winston.info("trainingQueue");
109
+ // jobsManager.listenTrainingQueue(trainingQueue);
110
110
 
111
111
 
112
112
  let scheduler = require('./pubmodules/scheduler');
package/jobsManager.js CHANGED
@@ -87,13 +87,13 @@ class JobsManager {
87
87
  // this.whatsappQueue.listen(); // oppure codice
88
88
  }
89
89
 
90
- listenTrainingQueue(trainingQueue) {
91
- console.log("JobsManager listenTrainingQueue started");
92
- console.log("trainingQueue is: ", trainingQueue)
93
- if (this.jobWorkerEnabled == true) {
94
- return winston.info("JobsManager jobWorkerEnabled is enabled. Skipping listener for Training Queue");
95
- }
96
- }
90
+ // listenTrainingQueue(trainingQueue) {
91
+ // console.log("JobsManager listenTrainingQueue started");
92
+ // console.log("trainingQueue is: ", trainingQueue)
93
+ // if (this.jobWorkerEnabled == true) {
94
+ // return winston.info("JobsManager jobWorkerEnabled is enabled. Skipping listener for Training Queue");
95
+ // }
96
+ // }
97
97
  }
98
98
 
99
99
 
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.7.22",
4
+ "version": "2.7.24",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
@@ -46,11 +46,11 @@
46
46
  "@tiledesk/tiledesk-kaleyra-proxy": "^0.1.7",
47
47
  "@tiledesk/tiledesk-messenger-connector": "^0.1.21",
48
48
  "@tiledesk/tiledesk-rasa-connector": "^1.0.10",
49
+ "@tiledesk/tiledesk-train-jobworker": "^0.0.11",
49
50
  "@tiledesk/tiledesk-telegram-connector": "^0.1.14",
50
- "@tiledesk/tiledesk-train-jobworker": "^0.0.7",
51
- "@tiledesk/tiledesk-tybot-connector": "^0.2.67",
51
+ "@tiledesk/tiledesk-tybot-connector": "^0.2.69",
52
52
  "@tiledesk/tiledesk-whatsapp-connector": "^0.1.72",
53
- "@tiledesk/tiledesk-whatsapp-jobworker": "^0.0.7",
53
+ "@tiledesk/tiledesk-whatsapp-jobworker": "^0.0.8",
54
54
  "amqplib": "^0.5.5",
55
55
  "app-root-path": "^3.0.0",
56
56
  "bcrypt-nodejs": "0.0.3",
package/routes/kb.js CHANGED
@@ -7,11 +7,13 @@ var upload = multer()
7
7
  const openaiService = require('../services/openaiService');
8
8
  const JobManager = require('../utils/jobs-worker-queue-manager/JobManagerV2');
9
9
  const { Scheduler } = require('../services/Scheduler');
10
-
10
+ var configGlobal = require('../config/global');
11
11
  const Sitemapper = require('sitemapper');
12
12
 
13
13
  const AMQP_MANAGER_URL = process.env.AMQP_MANAGER_URL;
14
14
  const JOB_TOPIC_EXCHANGE = process.env.JOB_TOPIC_EXCHANGE_TRAIN || 'tiledesk-trainer';
15
+ const KB_WEBHOOK_TOKEN = process.env.KB_WEBHOOK_TOKEN || 'kbcustomtoken';
16
+ const apiUrl = process.env.API_URL || configGlobal.apiUrl;
15
17
 
16
18
  let jobManager = new JobManager(AMQP_MANAGER_URL, {
17
19
  debug: false,
@@ -27,6 +29,7 @@ router.get('/', async (req, res) => {
27
29
 
28
30
  let project_id = req.projectid;
29
31
  let status;
32
+ let type;
30
33
  let limit = 200;
31
34
  let page = 0;
32
35
  let direction = -1;
@@ -41,6 +44,13 @@ router.get('/', async (req, res) => {
41
44
  query["status"] = status;
42
45
  winston.debug("Get kb status: " + status)
43
46
  }
47
+
48
+ if (req.query.type) {
49
+ type = req.query.type;
50
+ query["type"] = type;
51
+ winston.debug("Get kb type: " + type);
52
+ }
53
+
44
54
  if (req.query.limit) {
45
55
  limit = parseInt(req.query.limit);
46
56
  winston.debug("Get kb limit: " + limit)
@@ -193,13 +203,17 @@ router.post('/', async (req, res) => {
193
203
 
194
204
  res.status(200).send(raw);
195
205
 
206
+ let webhook = apiUrl + '/webhook/kb/status?token=' + KB_WEBHOOK_TOKEN;
207
+
196
208
  let json = {
197
209
  id: raw.value._id,
198
210
  type: raw.value.type,
199
211
  source: raw.value.source,
200
212
  content: "",
201
- namespace: raw.value.namespace
213
+ namespace: raw.value.namespace,
214
+ webhook: webhook
202
215
  }
216
+ winston.debug("json: ", json);
203
217
 
204
218
  if (raw.value.content) {
205
219
  json.content = raw.value.content;
@@ -221,7 +235,6 @@ router.post('/', async (req, res) => {
221
235
 
222
236
  })
223
237
 
224
-
225
238
  router.post('/multi', upload.single('uploadFile'), async (req, res) => {
226
239
 
227
240
  let list;
@@ -256,6 +269,8 @@ router.post('/multi', upload.single('uploadFile'), async (req, res) => {
256
269
  return res.status(403).send({ success: false, error: "Too many urls. Can't index more than 300 urls at a time."})
257
270
  }
258
271
 
272
+ let webhook = apiUrl + '/webhook/kb/status?token=' + KB_WEBHOOK_TOKEN;
273
+
259
274
  let kbs = [];
260
275
  list.forEach(url => {
261
276
  kbs.push({
@@ -284,9 +299,9 @@ router.post('/multi', upload.single('uploadFile'), async (req, res) => {
284
299
 
285
300
  let resources = result.map(({ name, status, __v, createdAt, updatedAt, id_project, ...keepAttrs }) => keepAttrs)
286
301
  resources = resources.map(({ _id, ...rest }) => {
287
- return { id: _id, ...rest };
302
+ return { id: _id, webhook: webhook, ...rest };
288
303
  });
289
- winston.verbose("resources to be sent to worker: ", resources)
304
+ winston.verbose("resources to be sent to worker: ", resources);
290
305
  scheduleScrape(resources);
291
306
  res.status(200).send(result);
292
307
 
@@ -316,7 +331,6 @@ router.post('/sitemap', async (req, res) => {
316
331
 
317
332
  })
318
333
 
319
-
320
334
  router.put('/:kb_id', async (req, res) => {
321
335
 
322
336
  let kb_id = req.params.kb_id;
@@ -351,7 +365,6 @@ router.put('/:kb_id', async (req, res) => {
351
365
 
352
366
  })
353
367
 
354
-
355
368
  // PROXY PUGLIA AI V2 - START
356
369
  router.post('/scrape/single', async (req, res) => {
357
370
 
@@ -560,7 +573,7 @@ router.delete('/:kb_id', async (req, res) => {
560
573
  } else {
561
574
  winston.verbose("resp.data: ", resp.data);
562
575
 
563
- KB.findOneAndDelete({ _id: kb_id, status: { $in: [-1, 3, 4] } }, (err, deletedKb) => {
576
+ KB.findOneAndDelete({ _id: kb_id, status: { $in: [-1, 3, 4, 100, 300, 400] } }, (err, deletedKb) => {
564
577
  if (err) {
565
578
  winston.error("findOneAndDelete err: ", err);
566
579
  return res.status(500).send({ success: false, error: "Unable to delete the content due to an error" })
@@ -581,6 +594,33 @@ router.delete('/:kb_id', async (req, res) => {
581
594
 
582
595
  })
583
596
 
597
+ router.delete('/namespace/:namespace_id', async (req, res) => {
598
+
599
+ let id_project = req.projectid;
600
+ let namespace_id = req.params.namespace_id;
601
+
602
+ let data = {
603
+ namespace: namespace_id
604
+ }
605
+
606
+ openaiService.deleteNamespace(data).then((resp) => {
607
+ winston.debug("delete namespace resp: ", resp.data);
608
+
609
+ KB.deleteMany({ id_project: id_project, namespace: namespace_id }, (err, deleteResponse) => {
610
+ if (err) {
611
+ winston.error("deleteMany error: ", err);
612
+ return res.status(500).send({ success: false, error: "Unable to delete namespace due to an error" })
613
+ }
614
+ winston.debug("deleteResponse: ", deleteResponse);
615
+ res.status(200).send({ success: true, message: "Namespace deleted succesfully" })
616
+ })
617
+
618
+ }).catch((err) => {
619
+ let status = err.response.status;
620
+ res.status(status).send({ success: false, error: "Unable to delete namespace"})
621
+ })
622
+ })
623
+
584
624
  async function saveBulk(operations, kbs, project_id) {
585
625
 
586
626
  return new Promise((resolve, reject) => {
@@ -629,9 +669,12 @@ async function statusConverter(status) {
629
669
  async function updateStatus(id, status) {
630
670
  return new Promise((resolve) => {
631
671
 
632
- KB.findByIdAndUpdate(id, { status: status }, (err, updatedKb) => {
672
+ KB.findByIdAndUpdate(id, { status: status }, { new: true }, (err, updatedKb) => {
633
673
  if (err) {
634
674
  resolve(false)
675
+ } else if (!updatedKb) {
676
+ winston.verbose("Unable to update status. Data source not found.")
677
+ resolve(false)
635
678
  } else {
636
679
  winston.debug("updatedKb: ", updatedKb)
637
680
  resolve(true);
@@ -642,17 +685,25 @@ async function updateStatus(id, status) {
642
685
 
643
686
  async function scheduleScrape(resources) {
644
687
 
645
- let data = {
646
- resources: resources
647
- }
648
- winston.info("Schedule job with following data: ", data);
688
+ // let data = {
689
+ // resources: resources
690
+ // }
649
691
  let scheduler = new Scheduler({ jobManager: jobManager });
650
- scheduler.trainSchedule(data, (err, result) => {
651
- if (err) {
652
- winston.error("Scheduling error: ", err);
653
- }
654
- winston.info("Scheduling result: ", result);
655
- });
692
+
693
+ resources.forEach(r => {
694
+ winston.debug("Schedule job with following data: ", r);
695
+ scheduler.trainSchedule(r, async (err, result) => {
696
+ let error_code = 100;
697
+ if (err) {
698
+ winston.error("Scheduling error: ", err);
699
+ error_code = 400;
700
+ } else {
701
+ winston.info("Scheduling result: ", result);
702
+ }
703
+ await updateStatus(r.id, error_code);
704
+ });
705
+ })
706
+
656
707
 
657
708
  return true;
658
709
  }
@@ -0,0 +1,55 @@
1
+ var express = require('express');
2
+ var router = express.Router();
3
+ var { KB } = require('../models/kb_setting');
4
+ var winston = require('../config/winston');
5
+
6
+ const KB_WEBHOOK_TOKEN = process.env.KB_WEBHOOK_TOKEN || 'kbcustomtoken';
7
+
8
+ router.post('/kb/status', async (req, res) => {
9
+
10
+ winston.info("(webhook) kb status called");
11
+ winston.info("(webhook) req.body: ", req.body);
12
+
13
+ winston.info("(webhook) x-auth-token: " + req.headers['x-auth-token']);
14
+ winston.info("(webhook) KB_WEBHOOK_TOKEN: " + KB_WEBHOOK_TOKEN);
15
+
16
+ if (!req.headers['x-auth-token']) {
17
+ winston.error("Unauthorized: A x-auth-token must be provided")
18
+ return res.status(401).send({ success: false, error: "Unauthorized", message: "A x-auth-token must be provided" })
19
+ }
20
+
21
+ if (req.headers['x-auth-token'] != KB_WEBHOOK_TOKEN) {
22
+ winston.error("Unauthorized: You don't have the authorization to accomplish this operation")
23
+ return res.status(401).send({ success: false, error: "Unauthorized", message: "You don't have the authorization to accomplish this operation" });
24
+ }
25
+
26
+ let body = req.body;
27
+ winston.verbose('/webhook kb status body: ', body);
28
+
29
+ let kb_id = body.id;
30
+ winston.verbose('/webhook kb status body: ' + kb_id);
31
+
32
+ let update = {};
33
+
34
+ if (body.status) {
35
+ update.status = body.status;
36
+ }
37
+
38
+ KB.findByIdAndUpdate(kb_id, update, { new: true }, (err, kb) => {
39
+ if (err) {
40
+ winston.error(err);
41
+ return res.status(500).send({ success: false, error: err });
42
+ }
43
+
44
+ if (!kb) {
45
+ winston.info("Knwoledge Base content to be updated not found")
46
+ return res.status(404).send({ success: false, messages: "Knwoledge Base content not found with id " + kb_id });
47
+ }
48
+
49
+ winston.info("kb updated succesfully: ", kb);
50
+ res.status(200).send(kb);
51
+ })
52
+
53
+ })
54
+
55
+ module.exports = router;
@@ -137,6 +137,11 @@ class EmailService {
137
137
  }
138
138
  winston.info('EmailService ccEnabled: ' + this.ccEnabled);
139
139
 
140
+ this.brand_name = "Tiledesk"
141
+ if (process.env.BRAND_NAME) {
142
+ this.brand_name = process.env.BRAND_NAME;
143
+ }
144
+
140
145
  }
141
146
 
142
147
  readTemplate(templateName, settings, environmentVariableKey) {
@@ -351,7 +356,7 @@ class EmailService {
351
356
 
352
357
  var html = template(replacements);
353
358
 
354
- return that.send({ to: to, subject: `Tiledesk test email`, config: configEmail, html: html, callback: callback });
359
+ return that.send({ to: to, subject: `${this.brand_name} test email`, config: configEmail, html: html, callback: callback });
355
360
 
356
361
  }
357
362
 
@@ -465,10 +470,10 @@ class EmailService {
465
470
  // cambiare in [Nicky:Dashboard Support] Assigned Chat
466
471
  // serve per aggiornare native... fai aggiornamento
467
472
 
468
- let subjectDef = `[Tiledesk ${project ? project.name : '-'}] New Assigned Chat`;
473
+ let subjectDef = `[${this.brand_name} ${project ? project.name : '-'}] New Assigned Chat`;
469
474
 
470
475
  if (request.subject) {
471
- subjectDef = `[Tiledesk ${project ? project.name : '-'}] ${request.subject}`;
476
+ subjectDef = `[${this.brand_name} ${project ? project.name : '-'}] ${request.subject}`;
472
477
  }
473
478
 
474
479
  let subject = that.formatText("assignedRequestSubject", subjectDef, request, project.settings);
@@ -607,13 +612,13 @@ class EmailService {
607
612
  }
608
613
 
609
614
 
610
- let subjectDef = `[Tiledesk ${project ? project.name : '-'}] New message`;
615
+ let subjectDef = `[${this.brand_name} ${project ? project.name : '-'}] New message`;
611
616
 
612
617
  if (request.subject) {
613
- subjectDef = `[Tiledesk ${project ? project.name : '-'}] ${request.subject}`;
618
+ subjectDef = `[${this.brand_name} ${project ? project.name : '-'}] ${request.subject}`;
614
619
  }
615
620
  if (request.ticket_id) {
616
- subjectDef = `[Ticket #${request.ticket_id}] New message`;
621
+ subjectDef = `[${this.brand_name} #${request.ticket_id}] New message`;
617
622
  }
618
623
 
619
624
  if (request.ticket_id && request.subject) {
@@ -746,10 +751,10 @@ class EmailService {
746
751
  }
747
752
  }
748
753
 
749
- let subjectDef = `[Tiledesk ${project ? project.name : '-'}] New Pooled Chat`;
754
+ let subjectDef = `[${this.brand_name} ${project ? project.name : '-'}] New Pooled Chat`;
750
755
 
751
756
  if (request.subject) {
752
- subjectDef = `[Tiledesk ${project ? project.name : '-'}] ${request.subject}`;
757
+ subjectDef = `[${this.brand_name} ${project ? project.name : '-'}] ${request.subject}`;
753
758
  }
754
759
 
755
760
  let subject = that.formatText("pooledRequestSubject", subjectDef, request, project.settings);
@@ -882,10 +887,10 @@ class EmailService {
882
887
  }
883
888
 
884
889
 
885
- let subjectDef = `[Tiledesk ${project ? project.name : '-'}] New Message`;
890
+ let subjectDef = `[${this.brand_name} ${project ? project.name : '-'}] New Message`;
886
891
 
887
892
  if (request.subject) {
888
- subjectDef = `[Tiledesk ${project ? project.name : '-'}] ${request.subject}`;
893
+ subjectDef = `[${this.brand_name} ${project ? project.name : '-'}] ${request.subject}`;
889
894
  }
890
895
  if (request.ticket_id) {
891
896
  subjectDef = `[Ticket #${request.ticket_id}] New Message`;
@@ -1019,7 +1024,7 @@ class EmailService {
1019
1024
  }
1020
1025
 
1021
1026
 
1022
- let subject = that.formatText("newMessageSubject", `[Tiledesk ${project ? project.name : '-'}] New Offline Message`, message, project.settings);
1027
+ let subject = that.formatText("newMessageSubject", `[${this.brand_name} ${project ? project.name : '-'}] New Offline Message`, message, project.settings);
1023
1028
 
1024
1029
  that.send({
1025
1030
  messageId: messageId,
@@ -1044,7 +1049,7 @@ class EmailService {
1044
1049
  replyTo: replyTo,
1045
1050
  inReplyTo: inReplyTo,
1046
1051
  references: references,
1047
- subject: `[Tiledesk ${project ? project.name : '-'}] New Offline Message - notification`,
1052
+ subject: `[${this.brand_name} ${project ? project.name : '-'}] New Offline Message - notification`,
1048
1053
  html: html,
1049
1054
  headers: headers
1050
1055
  });
@@ -1552,8 +1557,8 @@ class EmailService {
1552
1557
  var html = template(replacements);
1553
1558
 
1554
1559
 
1555
- that.send({ to: to, subject: '[Tiledesk] Password reset request', html: html });
1556
- that.send({ to: that.bcc, subject: '[Tiledesk] Password reset request - notification', html: html });
1560
+ that.send({ to: to, subject: `[${this.brand_name}] Password reset request`, html: html });
1561
+ that.send({ to: that.bcc, subject: `[${this.brand_name}] Password reset request - notification`, html: html });
1557
1562
 
1558
1563
  }
1559
1564
 
@@ -1582,8 +1587,8 @@ class EmailService {
1582
1587
  var html = template(replacements);
1583
1588
 
1584
1589
 
1585
- that.send({ to: to, subject: '[Tiledesk] Your password has been changed', html: html });
1586
- that.send({ to: that.bcc, subject: '[Tiledesk] Your password has been changed - notification', html: html });
1590
+ that.send({ to: to, subject: `[${this.brand_name}] Your password has been changed`, html: html });
1591
+ that.send({ to: that.bcc, subject: `[${this.brand_name}] Your password has been changed - notification`, html: html });
1587
1592
 
1588
1593
  }
1589
1594
 
@@ -1622,8 +1627,8 @@ class EmailService {
1622
1627
  var html = template(replacements);
1623
1628
 
1624
1629
 
1625
- that.send({ to: to, subject: `[Tiledesk] You have been invited to the '${projectName}' project`, html: html });
1626
- that.send({ to: that.bcc, subject: `[Tiledesk] You have been invited to the '${projectName}' project - notification`, html: html });
1630
+ that.send({ to: to, subject: `[${this.brand_name}] You have been invited to the '${projectName}' project`, html: html });
1631
+ that.send({ to: that.bcc, subject: `[${this.brand_name}] You have been invited to the '${projectName}' project - notification`, html: html });
1627
1632
  }
1628
1633
 
1629
1634
  // ok
@@ -1659,8 +1664,8 @@ class EmailService {
1659
1664
 
1660
1665
  var html = template(replacements);
1661
1666
 
1662
- that.send({ to: to, subject: `[Tiledesk] You have been invited to the '${projectName}' project`, html: html });
1663
- that.send({ to: that.bcc, subject: `[Tiledesk] You have been invited to the '${projectName}' project - notification`, html: html });
1667
+ that.send({ to: to, subject: `[${this.brand_name}] You have been invited to the '${projectName}' project`, html: html });
1668
+ that.send({ to: that.bcc, subject: `[${this.brand_name}] You have been invited to the '${projectName}' project - notification`, html: html });
1664
1669
 
1665
1670
  }
1666
1671
 
@@ -1691,8 +1696,8 @@ class EmailService {
1691
1696
  var html = template(replacements);
1692
1697
 
1693
1698
 
1694
- that.send({ to: to, subject: `[Tiledesk] Verify your email address`, html: html });
1695
- that.send({ to: that.bcc, subject: `[Tiledesk] Verify your email address ` + to + " - notification", html: html });
1699
+ that.send({ to: to, subject: `[${this.brand_name}] Verify your email address`, html: html });
1700
+ that.send({ to: that.bcc, subject: `[${this.brand_name}] Verify your email address ` + to + " - notification", html: html });
1696
1701
 
1697
1702
  }
1698
1703
 
@@ -1765,7 +1770,7 @@ class EmailService {
1765
1770
 
1766
1771
  //custom ocf here
1767
1772
  // console.log("ocf",project._id);
1768
- let subject = that.formatText("sendTranscriptSubject", '[Tiledesk] Transcript', request, project.settings);
1773
+ let subject = that.formatText("sendTranscriptSubject", `[${this.brand_name}] Transcript`, request, project.settings);
1769
1774
 
1770
1775
  //prod //pre
1771
1776
  // if (project._id =="6406e34727b57500120b1bd6" || project._id == "642c609f179910002cc56b3e") {
@@ -1779,7 +1784,7 @@ class EmailService {
1779
1784
  // hcustomization.emailTranscript(to, subject, html, configEmail)
1780
1785
 
1781
1786
  that.send({ from: from, to: to, subject: subject, html: html, config: configEmail });
1782
- that.send({ to: that.bcc, subject: '[Tiledesk] Transcript - notification', html: html });
1787
+ that.send({ to: that.bcc, subject: `[${this.brand_name}] Transcript - notification`, html: html });
1783
1788
 
1784
1789
  }
1785
1790
 
@@ -1807,7 +1812,7 @@ class EmailService {
1807
1812
 
1808
1813
  html = template(replacements);
1809
1814
 
1810
- that.send({ to: to, subject: "Join Tiledesk from Desktop", html: html });
1815
+ that.send({ to: to, subject: `Join ${this.brand_name} from Desktop`, html: html });
1811
1816
 
1812
1817
  }
1813
1818
 
package/test/kbRoute.js CHANGED
@@ -1,12 +1,15 @@
1
1
  //During the test the env variable is set to test
2
2
  process.env.NODE_ENV = 'test';
3
3
  process.env.GPTKEY = "fakegptkey";
4
+ process.env.KB_WEBHOOK_TOKEN = "testtoken"
4
5
 
5
6
  var userService = require('../services/userService');
6
7
  var projectService = require('../services/projectService');
7
8
 
8
9
  let log = false;
9
10
 
11
+ var config = require('../config/global');
12
+
10
13
  //Require the dev-dependencies
11
14
  let chai = require('chai');
12
15
  let chaiHttp = require('chai-http');
@@ -14,12 +17,15 @@ let server = require('../app');
14
17
  let should = chai.should();
15
18
  var fs = require('fs');
16
19
  const path = require('path');
20
+ const mongoose = require('mongoose');
17
21
 
18
22
  // chai.config.includeStack = true;
19
23
 
20
24
  var expect = chai.expect;
21
25
  var assert = chai.assert;
22
26
 
27
+ mongoose.connect(config.databasetest);
28
+
23
29
  chai.use(chaiHttp);
24
30
 
25
31
  describe('KbRoute', () => {
@@ -199,7 +205,7 @@ describe('KbRoute', () => {
199
205
  if (log) { console.log("create kb res.body: ", res.body); }
200
206
  res.should.have.status(200);
201
207
 
202
- let query = "?status=-1&limit=5&page=0&direction=-1&sortField=updatedAt&search=example";
208
+ let query = "?status=-1&type=url&limit=5&page=0&direction=-1&sortField=updatedAt&search=example";
203
209
  //let query = "";
204
210
  console.log("query: ", query);
205
211
 
@@ -208,11 +214,12 @@ describe('KbRoute', () => {
208
214
  .auth(email, pwd)
209
215
  .end((err, res) => {
210
216
  if (log) { console.log("getall res.body: ", res.body); }
217
+ console.log("getall res.body: ", res.body);
211
218
  res.should.have.status(200);
212
219
  res.body.should.be.a('object');
213
220
  res.body.kbs.should.be.a('array');
214
- expect(res.body.kbs.length).to.equal(3);
215
- expect(res.body.count).to.equal(3);
221
+ expect(res.body.kbs.length).to.equal(2);
222
+ expect(res.body.count).to.equal(2);
216
223
  res.body.query.should.be.a('object');
217
224
  expect(res.body.query.status).to.equal(-1);
218
225
  expect(res.body.query.limit).to.equal(5);
@@ -389,7 +396,7 @@ describe('KbRoute', () => {
389
396
 
390
397
  }).timeout(10000)
391
398
 
392
- it('multiadd-fail', (done) => {
399
+ it('multiaddFail', (done) => {
393
400
 
394
401
  var email = "test-signup-" + Date.now() + "@email.com";
395
402
  var pwd = "pwd";
@@ -514,10 +521,6 @@ describe('KbRoute', () => {
514
521
  if (err) { console.log("error: ", err) };
515
522
  if (log) { console.log("res.body: ", res.body) }
516
523
 
517
- console.log("error: ", err)
518
- console.log("res.body: ", res.body)
519
-
520
- console.log("sites length: ", res.body.sites.length)
521
524
  res.should.have.status(200);
522
525
  res.body.should.be.a('object');
523
526
  res.body.sites.should.be.a('array');
@@ -531,6 +534,59 @@ describe('KbRoute', () => {
531
534
 
532
535
  }).timeout(10000)
533
536
 
537
+ it('webhook', (done) => {
538
+
539
+ var email = "test-signup-" + Date.now() + "@email.com";
540
+ var pwd = "pwd";
541
+
542
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
543
+ projectService.create("test-kb-webhook", savedUser._id).then(function (savedProject) {
544
+
545
+ let kb = {
546
+ name: "example_name6",
547
+ type: "url",
548
+ source: "https://www.exampleurl6.com",
549
+ content: "",
550
+ }
551
+
552
+ chai.request(server)
553
+ .post('/' + savedProject._id + '/kb/')
554
+ .auth(email, pwd)
555
+ .send(kb)
556
+ .end((err, res) => {
557
+
558
+ if (err) { console.log("error: ", err) };
559
+ if (log) { console.log("res.body: ", res.body) };
560
+
561
+ res.should.have.status(200);
562
+ res.body.should.be.a('object');
563
+
564
+ let kb_id = res.body.value._id;
565
+
566
+ chai.request(server)
567
+ .post('/webhook/kb/status')
568
+ .set("x-auth-token", "testtoken")
569
+ .send({ id: kb_id, status: 300 })
570
+ .end((err, res) => {
571
+
572
+ if (err) { console.error("err: ", err) };
573
+ if (log) { console.log("res.body: ", res.body) };
574
+
575
+ res.should.have.status(200);
576
+ res.body.should.be.a('object');
577
+ expect(res.body.status).to.equal(300);
578
+
579
+ done();
580
+
581
+ })
582
+
583
+
584
+ })
585
+
586
+ });
587
+ });
588
+ }).timeout(10000)
589
+
534
590
  })
535
591
  });
536
592