@tiledesk/tiledesk-server 2.2.22 → 2.2.26

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.
@@ -60,14 +60,14 @@ function populateMessageWithRequest(message, eventPrefix) {
60
60
  populate('participatingBots').
61
61
  populate('participatingAgents').
62
62
  populate({path:'requester',populate:{path:'id_user'}}).
63
- lean().
63
+ lean()
64
64
  //perche lean?
65
65
  // TODO availableAgentsCount nn c'è per il lean problema trigger
66
66
  // request.department._id DA CORREGGERE ANCHE PER REQUEST.CREATE
67
67
  // request.department.hasBot
68
68
  // request.isOpen
69
- cache(cacheUtil.defaultTTL, message.id_project+":requests:request_id:"+message.recipient).
70
- exec(function (err, request) {
69
+ //@DISABLED_CACHE .cache(cacheUtil.defaultTTL, message.id_project+":requests:request_id:"+message.recipient)
70
+ .exec(function (err, request) {
71
71
 
72
72
  if (err) {
73
73
  winston.error("Error getting request on messageEvent.populateMessage",err );
@@ -83,7 +83,7 @@ function populateMessageWithRequest(message, eventPrefix) {
83
83
  if (request.department && request.department.id_bot) {
84
84
  // if (request.department) {
85
85
  Faq_kb.findById(request.department.id_bot)
86
- .cache(cacheUtil.defaultTTL, message.id_project+":faq_kbs:id:"+request.department.id_bot)
86
+ //@DISABLED_CACHE .cache(cacheUtil.defaultTTL, message.id_project+":faq_kbs:id:"+request.department.id_bot)
87
87
  .exec(function(err, bot) {
88
88
  winston.debug('bot', bot);
89
89
  requestJson.department.bot = bot
@@ -138,7 +138,7 @@ class RoleChecker {
138
138
  winston.debug("hasRoleOrType query " + JSON.stringify(query));
139
139
 
140
140
  Project_user.findOne(query)
141
- .cache(cacheUtil.defaultTTL, req.params.projectid+":project_users:id:"+req.user.id)
141
+ //@DISABLED_CACHE .cache(cacheUtil.defaultTTL, req.params.projectid+":project_users:id:"+req.user.id)
142
142
  .exec(function (err, project_user) {
143
143
  if (err) {
144
144
  winston.error("Error getting project_user for hasrole",err);
@@ -129,7 +129,7 @@ module.exports = function(passport) {
129
129
 
130
130
  winston.debug("project id: "+ AudienceId );
131
131
  Project.findOne({_id: AudienceId, status: 100}).select('+jwtSecret')
132
- .cache(cacheUtil.queryTTL, "projects:query:id:status:100:"+AudienceId+":select:+jwtSecret")
132
+ //@DISABLED_CACHE .cache(cacheUtil.queryTTL, "projects:query:id:status:100:"+AudienceId+":select:+jwtSecret")
133
133
  .exec(function (err, project){
134
134
  if (err) {
135
135
  winston.error("auth Project err: ", {error:err, decoded: decoded} );
@@ -317,7 +317,7 @@ module.exports = function(passport) {
317
317
  } else {
318
318
  winston.debug("Passport JWT generic user");
319
319
  User.findOne({_id: identifier, status: 100})
320
- .cache(cacheUtil.defaultTTL, "users:id:"+identifier)
320
+ //@DISABLED_CACHE .cache(cacheUtil.defaultTTL, "users:id:"+identifier)
321
321
  .exec(function(err, user) {
322
322
  if (err) {
323
323
  winston.error("Passport JWT generic err ", err);
@@ -349,7 +349,7 @@ module.exports = function(passport) {
349
349
  winston.debug("email lowercase: " + email);
350
350
 
351
351
  User.findOne({ email: email, status: 100}, 'email firstname lastname password emailverified id')
352
- .cache(cacheUtil.defaultTTL, "users:email:"+email)
352
+ //@DISABLED_CACHE .cache(cacheUtil.defaultTTL, "users:email:"+email)
353
353
  .exec(function (err, user) {
354
354
 
355
355
  if (err) {
@@ -5,6 +5,7 @@ var Schema = mongoose.Schema;
5
5
  var winston = require('../config/winston');
6
6
  var RoleConstants = require('./roleConstants');
7
7
  var PresenceSchema = require('./presence');
8
+ var TagSchema = require("../models/tag");
8
9
 
9
10
 
10
11
 
@@ -58,6 +59,7 @@ var PresenceSchema = require('./presence');
58
59
  settings: {
59
60
  type: Object,
60
61
  },
62
+ tags: [TagSchema],
61
63
  createdBy: {
62
64
  type: String,
63
65
  required: true
package/models/request.js CHANGED
@@ -429,7 +429,7 @@ RequestSchema.index({ id_project: 1, status: 1, preflight:1, updatedAt: -1 }); /
429
429
 
430
430
  RequestSchema.index({ id_project: 1, preflight:1, updatedAt: -1 }); // used query ws (topic.endsWith('/requests'))
431
431
 
432
-
432
+ RequestSchema.index({ hasBot: 1, createdAt: 1 }); // suggested by atlas
433
433
 
434
434
 
435
435
  // cannot index parallel arrays [agents] [participants] {"driv
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.2.22",
4
+ "version": "2.2.26",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
@@ -109,7 +109,7 @@
109
109
  "chai-string": "^1.5.0",
110
110
  "loadtest": "^5.1.2",
111
111
  "mocha": "^8.4.0",
112
- "mongodb-runner": "4.8.1",
112
+ "mongodb-runner": "4.8.3",
113
113
  "nodemon": "^2.0.12",
114
114
  "sinon": "^9.2.4",
115
115
  "sinon-mongoose": "^2.3.0"
@@ -376,7 +376,7 @@ sendToAgentEmailChannelEmail(projectid, message) {
376
376
  }
377
377
 
378
378
  User.findOne({_id: userid , status: 100})
379
- .cache(cacheUtil.defaultTTL, "users:id:"+userid)
379
+ //@DISABLED_CACHE .cache(cacheUtil.defaultTTL, "users:id:"+userid)
380
380
  .exec(function (err, user) {
381
381
  if (err) {
382
382
  // winston.debug(err);
@@ -430,7 +430,7 @@ sendToAgentEmailChannelEmail(projectid, message) {
430
430
  }
431
431
 
432
432
  User.findOne({_id: assignedId, status: 100})
433
- .cache(cacheUtil.defaultTTL, "users:id:"+assignedId)
433
+ //@DISABLED_CACHE .cache(cacheUtil.defaultTTL, "users:id:"+assignedId)
434
434
  .exec(function (err, user) {
435
435
  if (err) {
436
436
  winston.error("Error sending email to " + savedRequest.participants[0], err);
@@ -707,7 +707,7 @@ sendAgentEmail(projectid, savedRequest) {
707
707
  }
708
708
 
709
709
  User.findOne({_id: userid , status: 100})
710
- .cache(cacheUtil.defaultTTL, "users:id:"+userid)
710
+ //@DISABLED_CACHE .cache(cacheUtil.defaultTTL, "users:id:"+userid)
711
711
  .exec(function (err, user) {
712
712
  if (err) {
713
713
  // winston.debug(err);
@@ -769,7 +769,7 @@ sendAgentEmail(projectid, savedRequest) {
769
769
  return winston.warn("RequestNotification email notification for the user with id : " + assignedId + " not found project_user");
770
770
  }
771
771
  User.findOne({_id: assignedId, status: 100})
772
- .cache(cacheUtil.defaultTTL, "users:id:"+assignedId)
772
+ //@DISABLED_CACHE .cache(cacheUtil.defaultTTL, "users:id:"+assignedId)
773
773
  .exec(function (err, user) {
774
774
  if (err) {
775
775
  winston.error("Error sending email to " + savedRequest.participants[0], err);
@@ -38,9 +38,9 @@ class MessageHandlebarsTransformerInterceptor {
38
38
  populate({path:'requester',populate:{path:'id_user'}});
39
39
  // }
40
40
 
41
- var request = await q1.
42
- cache(cacheUtil.defaultTTL, message.id_project+":requests:request_id:"+message.recipient).
43
- exec();
41
+ var request = await q1
42
+ //@DISABLED_CACHE .cache(cacheUtil.defaultTTL, message.id_project+":requests:request_id:"+message.recipient)
43
+ .exec();
44
44
 
45
45
 
46
46
 
@@ -37,14 +37,14 @@ class MessageTransformerInterceptor {
37
37
  var language = "EN";
38
38
 
39
39
  // cacherequest // requestcachefarequi nocachepopulatereqired
40
- var request = await Request.findOne({request_id: message.recipient, id_project: message.id_project}).
40
+ var request = await Request.findOne({request_id: message.recipient, id_project: message.id_project})
41
41
  // populate('lead').
42
42
  // populate('department').
43
43
  // populate('participatingBots').
44
44
  // populate('participatingAgents').
45
45
  // populate({path:'requester',populate:{path:'id_user'}}).
46
- cache(cacheUtil.defaultTTL, message.id_project+":requests:request_id:"+message.recipient).
47
- exec();
46
+ //@DISABLED_CACHE .cache(cacheUtil.defaultTTL, message.id_project+":requests:request_id:"+message.recipient)
47
+ .exec();
48
48
 
49
49
  winston.debug('request mti: ', request);
50
50
 
@@ -48,9 +48,15 @@ scheduleUnresponsiveRequests() {
48
48
  // }
49
49
 
50
50
  //https://crontab.guru/examples.html
51
- var s= schedule.scheduleJob(this.cronExp, function(fireDate){
52
- winston.debug('CloseBotUnresponsiveRequestTask scheduleUnresponsiveRequests job was supposed to run at ' + fireDate + ', but actually ran at ' + new Date());
53
- that.findUnresponsiveRequests();
51
+ var s= schedule.scheduleJob(this.cronExp, function(fireDate){ //TODO aggiungi un bias random
52
+
53
+ let timeInMs = Math.random() * (1000); // avoid cluster concurrent jobs in multiple nodes between 0 and 1sec
54
+ winston.info('timeInMs => '+ timeInMs);
55
+
56
+ setTimeout(function () {
57
+ winston.debug('CloseBotUnresponsiveRequestTask scheduleUnresponsiveRequests job was supposed to run at ' + fireDate + ', but actually ran at ' + new Date());
58
+ that.findUnresponsiveRequests();
59
+ },timeInMs );
54
60
  });
55
61
  }
56
62
 
@@ -65,6 +71,8 @@ findUnresponsiveRequests() {
65
71
  query.id_project = JSON.parse(this.queryProject);
66
72
  }
67
73
 
74
+
75
+
68
76
  winston.debug("CloseBotUnresponsiveRequestTask query",query);
69
77
 
70
78
  Request.find(query)
@@ -84,6 +92,7 @@ findUnresponsiveRequests() {
84
92
  winston.debug("CloseBotUnresponsiveRequestTask: found unresponsive requests ", requests);
85
93
 
86
94
  requests.forEach(request => {
95
+
87
96
  winston.debug("********unresponsive request ", request);
88
97
 
89
98
  return requestService.closeRequestByRequestId(request.request_id, request.id_project, false, false).then(function(updatedStatusRequest) {
@@ -166,7 +166,7 @@ router.get('/allstatus', [passport.authenticate(['basic', 'jwt'], { session: fal
166
166
  winston.debug("## GET ALL DEPTS QUERY (1)", query)
167
167
  // return Department.find({ "id_project": req.projectid }, function (err, departments) {
168
168
  return Department.find(query)
169
- .cache(cacheUtil.defaultTTL, req.projectid+":departments:query:allstatus")
169
+ //@DISABLED_CACHE .cache(cacheUtil.defaultTTL, req.projectid+":departments:query:allstatus")
170
170
  .exec(function (err, departments) {
171
171
  if (err) {
172
172
  winston.error('Error getting the departments.', err);
package/routes/faq.js CHANGED
@@ -273,7 +273,7 @@ router.get('/', function (req, res, next) {
273
273
  query.id_faq_kb = req.query.id_faq_kb;
274
274
  }
275
275
 
276
- var limit = 1000; // Number of request per page
276
+ var limit = 3000; // Number of request per page
277
277
 
278
278
  if (req.query.limit) {
279
279
  limit = parseInt(req.query.limit);
package/routes/faq_kb.js CHANGED
@@ -10,9 +10,8 @@ var httpUtil = require("../utils/httpUtil");
10
10
 
11
11
  router.post('/', function (req, res) {
12
12
  winston.info('create BOT ', req.body);
13
- // create(name, url, projectid, user_id, type, description) {
14
- faqService.create(req.body.name, req.body.url, req.projectid, req.user.id, req.body.type, req.body.description, undefined, undefined,
15
- req.body.language).then(function(savedFaq_kb) {
13
+ // create(name, url, projectid, user_id, type, description, webhook_url, webhook_enabled, language, template)
14
+ faqService.create(req.body.name, req.body.url, req.projectid, req.user.id, req.body.type, req.body.description, undefined, undefined, req.body.language, req.body.template).then(function(savedFaq_kb) {
16
15
  res.json(savedFaq_kb);
17
16
  });
18
17
 
package/routes/message.js CHANGED
@@ -66,7 +66,7 @@ async (req, res) => {
66
66
  // .populate('participatingBots')
67
67
  // .populate('participatingAgents')
68
68
  // .populate({path:'requester',populate:{path:'id_user'}})
69
- .cache(cacheUtil.defaultTTL, req.projectid+":requests:request_id:"+req.params.request_id)
69
+ //@DISABLED_CACHE .cache(cacheUtil.defaultTTL, req.projectid+":requests:request_id:"+req.params.request_id)
70
70
  .exec(async(err, request) => {
71
71
 
72
72
  if (err) {
package/routes/project.js CHANGED
@@ -313,7 +313,7 @@ router.patch('/:projectid', [passport.authenticate(['basic', 'jwt'], { session:
313
313
  router.get('/:projectid', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRoleOrTypes('agent', ['subscription'])], function (req, res) {
314
314
  winston.debug(req.body);
315
315
  Project.findOne({_id: req.params.projectid, status:100})
316
- .cache(cacheUtil.defaultTTL, "projects:id:"+req.params.projectid)
316
+ //@DISABLED_CACHE .cache(cacheUtil.defaultTTL, "projects:id:"+req.params.projectid)
317
317
  .exec(function (err, project) {
318
318
  if (err) {
319
319
  winston.error('Error getting project ', err);
@@ -196,7 +196,8 @@ router.post('/', [passport.authenticate(['basic', 'jwt'], { session: false }), v
196
196
  // role: RoleConstants.USER,
197
197
  // - Create project_user endpoint by agent (Ticketing) now is with Guest Role
198
198
  role: RoleConstants.GUEST,
199
- user_available: false,
199
+ user_available: false,
200
+ tags: req.body.tags,
200
201
  createdBy: req.user.id,
201
202
  updatedBy: req.user.id
202
203
  });
@@ -234,6 +235,10 @@ router.put('/', [passport.authenticate(['basic', 'jwt'], { session: false }), va
234
235
  if (req.body["settings.email.notification.conversation.pooled"]!=undefined) {
235
236
  update["settings.email.notification.conversation.pooled"] = req.body["settings.email.notification.conversation.pooled"];
236
237
  }
238
+ if (req.body.tags!=undefined) {
239
+ update.tags = req.body.tags;
240
+ }
241
+
237
242
 
238
243
 
239
244
  Project_user.findByIdAndUpdate(req.projectuser.id, update, { new: true, upsert: true }, function (err, updatedProject_user) {
@@ -289,7 +294,9 @@ router.put('/:project_userid', [passport.authenticate(['basic', 'jwt'], { sessio
289
294
  update["settings.email.notification.conversation.pooled"] = req.body["settings.email.notification.conversation.pooled"];
290
295
  }
291
296
 
292
-
297
+ if (req.body.tags!=undefined) {
298
+ update.tags = req.body.tags;
299
+ }
293
300
 
294
301
  winston.debug("project_userid update", update);
295
302
 
@@ -462,8 +469,8 @@ router.get('/users/:user_id', [passport.authenticate(['basic', 'jwt'], { session
462
469
  * RETURN THE PROJECT-USERS OBJECTS FILTERD BY PROJECT-ID AND WITH NESTED THE USER OBJECT
463
470
  * WF: 1. GET PROJECT-USER by the passed project ID
464
471
  * 2. POPULATE THE user_id OF THE PROJECT-USER object WITH THE USER OBJECT
465
- */
466
- router.get('/', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRole('agent')], function (req, res) {
472
+ */
473
+ router.get('/', [passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRoleOrTypes('agent', ['subscription'])], function (req, res) {
467
474
 
468
475
  var role = [RoleConstants.OWNER, RoleConstants.ADMIN, RoleConstants.SUPERVISOR, RoleConstants.AGENT];
469
476
 
package/routes/widget.js CHANGED
@@ -117,7 +117,7 @@ router.get('/', function(req, res, next) {
117
117
  // TOOD add labels
118
118
  Promise.all([
119
119
  Project.findOne({_id: req.projectid, status: 100}).select('-settings')
120
- .cache(cacheUtil.queryTTL, "projects:query:id:status:100:"+req.projectid+":select:-settings")
120
+ //@DISABLED_CACHE .cache(cacheUtil.queryTTL, "projects:query:id:status:100:"+req.projectid+":select:-settings")
121
121
  ,
122
122
  availableUsers()
123
123
  ,
@@ -283,6 +283,7 @@ getOperators(departmentid, projectid, nobot, disableWebHookCall, context) {
283
283
  return resolve ({
284
284
  department: department, available_agents: _available_agents, agents: project_users,
285
285
  id_bot:department.id_bot, project: project,
286
+ context: context,
286
287
  // botprefix
287
288
  operators: [{ id_user: 'bot_' + department.id_bot }]
288
289
  });
@@ -386,7 +387,7 @@ getOperators(departmentid, projectid, nobot, disableWebHookCall, context) {
386
387
  selectedoperator = that.getRandomAvailableOperator(_available_agents);
387
388
  }
388
389
 
389
- let objectToReturn = { available_agents: _available_agents, agents: project_users, operators: selectedoperator, department: department, group: group, id_project: projectid, project: project };
390
+ let objectToReturn = { available_agents: _available_agents, agents: project_users, operators: selectedoperator, department: department, group: group, id_project: projectid, project: project, context: context };
390
391
 
391
392
  that.roundRobin(objectToReturn).then(function(objectToReturnRoundRobin){
392
393
 
@@ -409,7 +410,7 @@ getOperators(departmentid, projectid, nobot, disableWebHookCall, context) {
409
410
 
410
411
  } else {
411
412
  // here subscription notifier??
412
- var objectToReturn = { available_agents: [], agents: [], operators: [] };
413
+ var objectToReturn = { available_agents: [], agents: [], operators: [], context: context };
413
414
  return resolve(objectToReturn);
414
415
  }
415
416
 
@@ -447,7 +448,7 @@ getOperators(departmentid, projectid, nobot, disableWebHookCall, context) {
447
448
  selectedoperator = that.getRandomAvailableOperator(_available_agents);
448
449
  }
449
450
 
450
- let objectToReturn = { available_agents: _available_agents, agents: project_users, operators: selectedoperator, department: department, id_project: projectid, project: project };
451
+ let objectToReturn = { available_agents: _available_agents, agents: project_users, operators: selectedoperator, department: department, id_project: projectid, project: project, context: context };
451
452
 
452
453
  that.roundRobin(objectToReturn).then(function(objectToReturnRoundRobin) {
453
454
  winston.debug("context2",context);
@@ -474,7 +475,7 @@ getOperators(departmentid, projectid, nobot, disableWebHookCall, context) {
474
475
 
475
476
  } else {
476
477
  // here subscription notifier??
477
- let objectToReturn = { available_agents: [], agents: [], operators: [] };
478
+ let objectToReturn = { available_agents: [], agents: [], operators: [], context: context };
478
479
  return resolve(objectToReturn);
479
480
  }
480
481
 
@@ -88,7 +88,7 @@ class FaqBotHandler {
88
88
 
89
89
 
90
90
  Faq_kb.findById(botId)
91
- .cache(cacheUtil.defaultTTL, message.id_project+":faq_kbs:id:"+botId)
91
+ //@DISABLED_CACHE .cache(cacheUtil.defaultTTL, message.id_project+":faq_kbs:id:"+botId)
92
92
  .exec(function(err, faq_kb) {
93
93
  if (err) {
94
94
  return winston.error("Error getting bot object.",err);
@@ -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) {
11
+ create(name, url, projectid, user_id, type, description, webhook_url, webhook_enabled, language, template) {
12
12
  var that = this;
13
13
  return new Promise(function (resolve, reject) {
14
14
 
@@ -37,8 +37,15 @@ class FaqService {
37
37
 
38
38
  botEvent.emit('faqbot.create', savedFaq_kb);
39
39
 
40
+ winston.debug('type '+ type)
41
+
40
42
  if (type==="internal") {
41
- that.createGreetingsAndOperationalsFaqs(savedFaq_kb._id, savedFaq_kb.createdBy, savedFaq_kb.id_project);
43
+
44
+ if (!template) {
45
+ template = "example";
46
+ }
47
+ winston.debug('template '+ template);
48
+ that.createGreetingsAndOperationalsFaqs(savedFaq_kb._id, savedFaq_kb.createdBy, savedFaq_kb.id_project, template);
42
49
  } else {
43
50
  winston.debug('external bot: ', savedFaq_kb);
44
51
  }
@@ -50,33 +57,63 @@ class FaqService {
50
57
  });
51
58
  }
52
59
 
53
- createGreetingsAndOperationalsFaqs(faq_kb_id, created_by, projectid, remote_faqkb_key) {
60
+ createGreetingsAndOperationalsFaqs(faq_kb_id, created_by, projectid, template) {
54
61
  var that = this;
55
62
  return new Promise(function (resolve, reject) {
56
63
 
57
64
  // aggiungi esempio tdAction con intent_id
58
- var faqsArray = [
59
- { 'question': 'Hi', 'answer': 'Hi', 'topic': 'greetings' },
60
- { 'question': 'Hello', 'answer': 'Hello', 'topic': 'greetings' },
61
- { 'question': 'Who are you?', 'answer': 'Hi, I\'m a bot 🤖. You can find more about me [here](https://tiledesk.com/chatbot-for-customer-service).\ntdImage:https://console.tiledesk.com/assets/images/tily-welcomebot.gif\n* See the website https://tiledesk.com/\n* Back to start tdAction:start', 'topic': 'greetings' },
62
- { 'question': '👨🏻‍🦰 I want an agent', 'answer': 'We are looking for an operator.. '+ActionsConstants.CHAT_ACTION_MESSAGE.AGENT, 'intent_display_name': 'agent_handoff', 'topic': 'internal' },
63
- { 'question': 'Close\nResolved', 'answer': ActionsConstants.CHAT_ACTION_MESSAGE.CLOSE, 'topic': 'internal' },
64
- { 'question': '\\start', 'answer': 'Hello 👋. I\'m a bot 🤖.\n\nChoose one of the options below or write a message to reach our staff.\n* Who are you?\n* Where are you?\n* What can you do?\n* 👨🏻‍🦰 I want an agent', 'intent_display_name': 'start', 'topic': 'internal' },
65
- { 'question': 'defaultFallback', 'answer': 'I can not provide an adequate answer. Write a new question or talk to a human agent.\n* Back to start tdAction:start\n* See the docs https://docs.tiledesk.com/\n* 👨🏻‍🦰 I want an agent', 'topic': 'internal' }, //TODO se metto spazio n * nn va
66
- { 'question': 'What can you do?', 'answer': 'Using natural language processing, I\'m able to find the best answer for your users. I also support images, videos etc.. Let\'s try:\n* Sample Image\n* Sample Video\n* Sample Action tdAction:action1\n* Sample Frame\n* Back to start tdAction:start', 'topic': 'sample' },
67
- { 'question': 'Sample Image', 'answer': 'tdImage:https://tiledesk.com/tiledesk-logo-x1.png\n* What can you do?\n* Back to start tdAction:start', 'topic': 'sample' },
68
- { 'question': 'Sample Frame', 'answer': 'tdFrame:https://www.emanueleferonato.com/wp-content/uploads/2019/02/runner/\n* What can you do?\n* Back to start tdAction:start', 'topic': 'sample' },
69
- { 'question': 'Sample Video', 'answer': 'tdVideo:https://www.youtube.com/embed/EngW7tLk6R8\n* What can you do?\n* Back to start tdAction:start', 'topic': 'sample' },
70
- { 'question': 'Where are you?', 'answer': 'We are here ❤️\ntdFrame:https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d6087916.923447935!2d8.234804542117423!3d41.836572992140624!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x12d4fe82448dd203%3A0xe22cf55c24635e6f!2sItaly!5e0!3m2!1sen!2sit!4v1613657475377!5m2!1sen!2sit\n* Back to start tdAction:start', 'topic': 'sample' },
71
-
72
- // { 'question': 'Sample Webhook', 'answer': 'tdWebhook:https://tiledesk-bot-webhook.tiledesk.repl.co', 'topic': 'sample' },
73
- { 'question': 'Sample Action', 'answer': 'Hello 👋 Would you like to take a closer look at our offer?\n* Yes, please tdAction:yes_action\n* No tdAction:no_action','intent_display_name': 'action1', 'topic': 'sample' },
74
- { 'question': 'Yes Action', 'answer': 'Great! Take a look here:\n* Tiledesk Pricing https://tiledesk.com/pricing-cloud/', 'intent_display_name': 'yes_action','topic': 'sample' },
75
- { 'question': 'No Action', 'answer': 'All right! If you need anything, let us know.', 'intent_display_name': 'no_action','topic': 'sample' },
76
-
77
-
78
- // action button nn si può fare perche gli id cambiano
79
- ]
65
+
66
+ winston.debug('template: '+ template);
67
+
68
+ var faqsArray;
69
+
70
+ if (template==="example") {
71
+
72
+ faqsArray = [
73
+ { 'question': 'Hi', 'answer': 'Hi', 'topic': 'greetings' },
74
+ { 'question': 'Hello', 'answer': 'Hello', 'topic': 'greetings' },
75
+ { 'question': 'Who are you?', 'answer': 'Hi, I\'m a bot 🤖. You can find more about me [here](https://tiledesk.com/chatbot-for-customer-service).\ntdImage:https://console.tiledesk.com/assets/images/tily-welcomebot.gif\n* See the website https://tiledesk.com/\n* Back to start tdAction:start', 'topic': 'greetings' },
76
+ { 'question': '👨🏻‍🦰 I want an agent', 'answer': 'We are looking for an operator.. '+ActionsConstants.CHAT_ACTION_MESSAGE.AGENT, 'intent_display_name': 'agent_handoff', 'topic': 'internal' },
77
+ { 'question': 'Close\nResolved', 'answer': ActionsConstants.CHAT_ACTION_MESSAGE.CLOSE, 'topic': 'internal' },
78
+ { 'question': '\\start', 'answer': 'Hello 👋. I\'m a bot 🤖.\n\nChoose one of the options below or write a message to reach our staff.\n* Who are you?\n* Where are you?\n* What can you do?\n* 👨🏻‍🦰 I want an agent', 'intent_display_name': 'start', 'topic': 'internal' },
79
+ { 'question': 'defaultFallback', 'answer': 'I can not provide an adequate answer. Write a new question or talk to a human agent.\n* Back to start tdAction:start\n* See the docs https://docs.tiledesk.com/\n* 👨🏻‍🦰 I want an agent', 'intent_display_name': 'defaultFallback', 'topic': 'internal' }, //TODO se metto spazio n * nn va
80
+ { 'question': 'What can you do?', 'answer': 'Using natural language processing, I\'m able to find the best answer for your users. I also support images, videos etc.. Let\'s try:\n* Sample Image\n* Sample Video\n* Sample Action tdAction:action1\n* Sample Frame\n* Back to start tdAction:start', 'topic': 'sample' },
81
+ { 'question': 'Sample Image', 'answer': 'tdImage:https://tiledesk.com/tiledesk-logo-x1.png\n* What can you do?\n* Back to start tdAction:start', 'topic': 'sample' },
82
+ { 'question': 'Sample Frame', 'answer': 'tdFrame:https://www.emanueleferonato.com/wp-content/uploads/2019/02/runner/\n* What can you do?\n* Back to start tdAction:start', 'topic': 'sample' },
83
+ { 'question': 'Sample Video', 'answer': 'tdVideo:https://www.youtube.com/embed/EngW7tLk6R8\n* What can you do?\n* Back to start tdAction:start', 'topic': 'sample' },
84
+ { 'question': 'Where are you?', 'answer': 'We are here ❤️\ntdFrame:https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d6087916.923447935!2d8.234804542117423!3d41.836572992140624!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x12d4fe82448dd203%3A0xe22cf55c24635e6f!2sItaly!5e0!3m2!1sen!2sit!4v1613657475377!5m2!1sen!2sit\n* Back to start tdAction:start', 'topic': 'sample' },
85
+
86
+ // { 'question': 'Sample Webhook', 'answer': 'tdWebhook:https://tiledesk-bot-webhook.tiledesk.repl.co', 'topic': 'sample' },
87
+ { 'question': 'Sample Action', 'answer': 'Hello 👋 Would you like to take a closer look at our offer?\n* Yes, please tdAction:yes_action\n* No tdAction:no_action','intent_display_name': 'action1', 'topic': 'sample' },
88
+ { 'question': 'Yes Action', 'answer': 'Great! Take a look here:\n* Tiledesk Pricing https://tiledesk.com/pricing-cloud/', 'intent_display_name': 'yes_action','topic': 'sample' },
89
+ { 'question': 'No Action', 'answer': 'All right! If you need anything, let us know.', 'intent_display_name': 'no_action','topic': 'sample' },
90
+
91
+
92
+ // action button nn si può fare perche gli id cambiano
93
+ ]
94
+
95
+ }
96
+
97
+ if (template==="blank") {
98
+
99
+ faqsArray = [
100
+ { 'question': '\\start', 'answer': 'Hello', 'intent_display_name': 'start', 'topic': 'internal' },
101
+ { 'question': 'defaultFallback', 'answer': 'I can not provide an adequate answer. Write a new question or talk to a human agent.\n* Back to start tdAction:start\n* See the docs https://docs.tiledesk.com/\n* 👨🏻‍🦰 I want an agent', 'intent_display_name': 'defaultFallback', 'topic': 'internal' }, //TODO se metto spazio n * nn va
102
+ ]
103
+
104
+ }
105
+
106
+
107
+ if (template==="handoff") {
108
+
109
+ faqsArray = [
110
+ { 'question': '\\start', 'answer': 'Hello', 'intent_display_name': 'start', 'topic': 'internal' },
111
+ { 'question': '👨🏻‍🦰 I want an agent', 'answer': 'We are looking for an operator.. '+ActionsConstants.CHAT_ACTION_MESSAGE.AGENT, 'intent_display_name': 'agent_handoff', 'topic': 'internal' },
112
+ { 'question': 'defaultFallback', 'answer': 'I can not provide an adequate answer. Write a new question or talk to a human agent.\n* Back to start tdAction:start\n* See the docs https://docs.tiledesk.com/\n* 👨🏻‍🦰 I want an agent', 'intent_display_name': 'defaultFallback', 'topic': 'internal' }, //TODO se metto spazio n * nn va
113
+ ]
114
+
115
+ }
116
+
80
117
 
81
118
  faqsArray.forEach(faq => {
82
119
 
@@ -101,10 +138,6 @@ class FaqService {
101
138
  winston.debug('FAQ SERVICE (save new faq) - QUESTION OF THE NEW GREETINGS FAQ CREATED ', savedFaq.question)
102
139
  winston.debug('FAQ SERVICE (save new faq) - ANSWER OF THE NEW GREETINGS FAQ CREATED ', savedFaq.answer)
103
140
  winston.debug('FAQ SERVICE (save new faq) - ID FAQKB GET IN THE OBJECT OF NEW FAQ CREATED ', savedFaq.id_faq_kb)
104
- // res.json({ 'Greetings Faqs': savedFaq });
105
- // return resolve(savedFaq);
106
-
107
- // that.createRemoteFaq(remote_faqkb_key, savedFaq);
108
141
 
109
142
  })
110
143
  });
@@ -122,7 +122,7 @@ getAllMerged(id_project) {
122
122
 
123
123
 
124
124
  return Label.findOne(query).lean()
125
- .cache(cacheUtil.longTTL, id_project+":labels:query:all")
125
+ //@DISABLED_CACHE .cache(cacheUtil.longTTL, id_project+":labels:query:all")
126
126
  .exec(function (err, labels) {
127
127
  if (err) {
128
128
  winston.error('Label ROUTE - REQUEST FIND ERR ', err)
@@ -167,7 +167,7 @@ getAll(id_project) {
167
167
 
168
168
 
169
169
  return Label.findOne(query).lean()
170
- .cache(cacheUtil.longTTL, id_project+":labels:query:all")
170
+ //@DISABLED_CACHE .cache(cacheUtil.longTTL, id_project+":labels:query:all")
171
171
  .exec(function (err, labels) {
172
172
  if (err) {
173
173
  winston.error('Label ROUTE - REQUEST FIND ERR ', err)
@@ -74,7 +74,7 @@ getAll(id_project) {
74
74
 
75
75
 
76
76
  return Label.findOne(query).lean()
77
- .cache(cacheUtil.longTTL, id_project+":labels:query:all")
77
+ //@DISABLED_CACHE .cache(cacheUtil.longTTL, id_project+":labels:query:all")
78
78
  .exec(function (err, labels) {
79
79
  if (err) {
80
80
  winston.error('Label ROUTE - REQUEST FIND ERR ', err)
@@ -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
- .cache(cacheUtil.defaultTTL, id_project+":leads:email:"+email)
17
+ //@DISABLED_CACHE .cache(cacheUtil.defaultTTL, id_project+":leads:email:"+email)
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
- .cache(cacheUtil.defaultTTL, id_project+":leads:lead_id:"+lead_id)
61
+ //@DISABLED_CACHE .cache(cacheUtil.defaultTTL, id_project+":leads:lead_id:"+lead_id)
62
62
  .exec(function(err, lead) {
63
63
  if (err) {
64
64
  winston.error("Error createIfNotExistsWithLeadId", err);
@@ -12,7 +12,7 @@ class OperatingHoursService {
12
12
 
13
13
  // winston.debug('O ---> [ OHS ] -> PROJECT ID ', projectId)
14
14
  Project.findOne({_id: projectId, status: 100})
15
- .cache(cacheUtil.defaultTTL, "projects:id:"+projectId)
15
+ //@DISABLED_CACHE .cache(cacheUtil.defaultTTL, "projects:id:"+projectId)
16
16
  .exec(function (err, project) {
17
17
  // winston.debug("XXXXXXXX project", project);
18
18
  if (err) {
@@ -170,7 +170,7 @@ class RequestService {
170
170
 
171
171
  return Request
172
172
  .findOne({request_id: request_id, id_project: id_project})
173
- .cache(cacheUtil.defaultTTL, id_project+":requests:request_id:"+request_id)
173
+ //@DISABLED_CACHE .cache(cacheUtil.defaultTTL, id_project+":requests:request_id:"+request_id)
174
174
  .exec( function(err, request) {
175
175
 
176
176
  if (err) {
@@ -322,7 +322,7 @@ class RequestService {
322
322
 
323
323
  return Request
324
324
  .findOne({request_id: request_id, id_project: id_project})
325
- .cache(cacheUtil.defaultTTL, id_project+":requests:request_id:"+request_id)
325
+ //@DISABLED_CACHE .cache(cacheUtil.defaultTTL, id_project+":requests:request_id:"+request_id)
326
326
  .exec( function(err, request) {
327
327
 
328
328
  if (err) {
@@ -901,7 +901,7 @@ class RequestService {
901
901
  .populate('participatingBots')
902
902
  .populate('participatingAgents')
903
903
  .populate({path:'requester',populate:{path:'id_user'}})
904
- .cache(cacheUtil.defaultTTL, id_project+":requests:request_id:"+request_id)
904
+ //@DISABLED_CACHE .cache(cacheUtil.defaultTTL, id_project+":requests:request_id:"+request_id)
905
905
  .exec(function(err, request) {
906
906
  if (err) {
907
907
  winston.error(err);
@@ -23,14 +23,14 @@ async send(sender, senderFullname, recipient, text, id_project, createdBy, attri
23
23
  winston.debug("bot id: "+id);
24
24
  sender = id; //change sender removing bot_
25
25
  var bot = await Faq_kb.findById(id)
26
- .cache(cacheUtil.defaultTTL, id_project+":faq_kbs:id:"+id)
26
+ //@DISABLED_CACHE .cache(cacheUtil.defaultTTL, id_project+":faq_kbs:id:"+id)
27
27
  .exec();
28
28
  winston.debug("bot",bot);
29
29
  senderFullname = bot.name;
30
30
  } else {
31
31
  winston.debug("user id: "+sender);
32
32
  var user = await User.findById(sender)
33
- .cache(cacheUtil.defaultTTL, "users:id:"+sender)
33
+ //@DISABLED_CACHE .cache(cacheUtil.defaultTTL, "users:id:"+sender)
34
34
  .exec()
35
35
  winston.debug("user", user);
36
36
  senderFullname = user.fullName;