@tiledesk/tiledesk-server 2.3.27 → 2.3.29

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/routes/request.js CHANGED
@@ -17,6 +17,10 @@ var Message = require("../models/message");
17
17
  var cacheUtil = require('../utils/cacheUtil');
18
18
  var RequestConstants = require("../models/requestConstants");
19
19
  var cacheEnabler = require("../services/cacheEnabler");
20
+ var Project_user = require("../models/project_user");
21
+ var Lead = require("../models/lead");
22
+ var UIDGenerator = require("../utils/UIDGenerator");
23
+
20
24
 
21
25
  csv = require('csv-express');
22
26
  csv.separator = ';';
@@ -32,9 +36,9 @@ const { check, validationResult } = require('express-validator');
32
36
  // TODO make a synchronous chat21 version (with query parameter?) with request.support_group.create
33
37
  router.post('/',
34
38
  [
35
- check('text').notEmpty(),
39
+ check('first_text').notEmpty(),
36
40
  ],
37
- function (req, res) {
41
+ async (req, res) => {
38
42
 
39
43
  var startTimestamp = new Date();
40
44
  winston.debug("request create timestamp: " + startTimestamp);
@@ -54,41 +58,113 @@ function (req, res) {
54
58
  winston.debug("req.projectuser", req.projectuser);
55
59
  }
56
60
 
57
-
61
+ var project_user = req.projectuser;
62
+
63
+ var sender = req.body.sender;
64
+ var fullname = req.body.senderFullname || req.user.fullName;
65
+ var email = req.body.email || req.user.email;
66
+
58
67
  let messageStatus = req.body.status || MessageConstants.CHAT_MESSAGE_STATUS.SENDING;
59
68
  winston.debug('messageStatus: ' + messageStatus);
60
69
 
61
- var request_id = req.params.request_id || 'support-group-' + req.projectid + "-" + uuidv4();
70
+ var request_id = req.params.request_id || 'support-group-' + req.projectid + "-" + UIDGenerator.generate();
71
+ winston.debug('request_id: ' + request_id);
62
72
 
63
- // createIfNotExistsWithLeadId(lead_id, fullname, email, id_project, createdBy, attributes) {
64
- return leadService.createIfNotExistsWithLeadId(req.body.sender || req.user._id, req.body.senderFullname || req.user.fullName , req.body.email || req.user.email, req.projectid, null, req.body.attributes || req.user.attributes)
65
- .then(function(createdLead) {
73
+ if (sender) {
66
74
 
67
- // TODO USE NEW .create()
68
- // createWithIdAndRequester(request_id, project_user_id, lead_id, id_project, first_text, departmentid, sourcePage, language, userAgent, status, createdBy, attributes) {
69
- return requestService.createWithIdAndRequester(request_id, req.projectuser._id, createdLead._id, req.projectid,
70
- req.body.text, req.body.departmentid, req.body.sourcePage,
71
- req.body.language, req.body.userAgent, null, req.user._id, req.body.attributes, req.body.subject).then(function (savedRequest) {
75
+ var isObjectId = mongoose.Types.ObjectId.isValid(sender);
76
+ winston.debug("isObjectId:"+ isObjectId);
77
+
78
+ var queryProjectUser = {id_project:req.projectid, status: "active" };
79
+
80
+ if (isObjectId) {
81
+ queryProjectUser.id_user = sender;
82
+ } else {
83
+ queryProjectUser.uuid_user = sender;
84
+ }
85
+
86
+ winston.debug("queryProjectUser", queryProjectUser);
87
+
88
+ project_user = await Project_user.findOne(queryProjectUser).populate({path:'id_user', select:{'firstname':1, 'lastname':1, 'email':1}})
89
+ winston.debug("project_user", project_user);
90
+
91
+ if (!project_user) {
92
+ return res.status(403).send({success: false, msg: 'Unauthorized. Project_user not found with user id : '+ sender });
93
+ }
94
+
95
+ if ( project_user.id_user) {
96
+ fullname = project_user.id_user.fullName;
97
+ winston.debug("pu fullname: "+ fullname);
98
+ email = project_user.id_user.email;
99
+ winston.debug("pu email: "+ email);
100
+ } else if (project_user.uuid_user) {
101
+ var lead = await Lead.findOne({lead_id: project_user.uuid_user, id_project: req.projectid});
102
+ winston.debug("lead: ",lead);
103
+ if (lead) {
104
+ fullname = lead.fullname;
105
+ winston.debug("lead fullname: "+ fullname);
106
+ email = lead.email;
107
+ winston.debug("lead email: "+ email);
108
+ }else {
109
+ winston.warn("lead not found: " + JSON.stringify({lead_id: project_user.uuid_user, id_project: req.projectid}));
110
+ }
111
+
112
+ } else {
113
+ winston.warn("pu fullname and email empty");
114
+ }
115
+
116
+ }
72
117
 
73
118
 
74
- // createWithId(request_id, requester_id, id_project, first_text, departmentid, sourcePage, language, userAgent, status, createdBy, attributes) {
75
- // return requestService.createWithId(req.params.request_id, req.body.sender, req.projectid,
76
- // req.body.text, req.body.departmentid, req.body.sourcePage,
77
- // req.body.language, req.body.userAgent, null, req.user._id, req.body.attributes).then(function (savedRequest) {
119
+ // createIfNotExistsWithLeadId(lead_id, fullname, email, id_project, createdBy, attributes) {
120
+ return leadService.createIfNotExistsWithLeadId(sender || req.user._id, fullname, email, req.projectid, null, req.body.attributes || req.user.attributes)
121
+ .then(function(createdLead) {
122
+
123
+
124
+
125
+ var new_request = {
126
+ request_id: request_id,
127
+ project_user_id: req.projectuser._id,
128
+ lead_id: createdLead._id,
129
+ id_project:req.projectid,
130
+ first_text: req.body.first_text,
131
+ departmentid: req.body.departmentid,
132
+ sourcePage:req.body.sourcePage,
133
+ language: req.body.language,
134
+ userAgent:req.body.userAgent,
135
+ status:null,
136
+ createdBy: req.user._id,
137
+ attributes: req.body.attributes,
138
+ subject: req.body.subject,
139
+ preflight:undefined,
140
+ channel: req.body.channel,
141
+ location: req.body.location,
142
+ participants: req.body.participants,
143
+ lead: createdLead, requester: project_user,
144
+ priority: req.body.priority,
145
+ followers: req.body.followers,
146
+ };
147
+
148
+ return requestService.create(new_request).then(function (savedRequest) {
149
+ // createWithIdAndRequester(request_id, project_user_id, lead_id, id_project, first_text, departmentid, sourcePage, language, userAgent, status, createdBy, attributes) {
150
+ // return requestService.createWithIdAndRequester(request_id, req.projectuser._id, createdLead._id, req.projectid,
151
+ // req.body.text, req.body.departmentid, req.body.sourcePage,
152
+ // req.body.language, req.body.userAgent, null, req.user._id, req.body.attributes, req.body.subject).then(function (savedRequest) {
78
153
 
79
154
 
155
+ // return messageService.create(sender || req.user._id, fullname, request_id, req.body.text,
156
+ // req.projectid, req.user._id, messageStatus, req.body.attributes, req.body.type, req.body.metadata, req.body.language, undefined, req.body.channel).then(function(savedMessage){
157
+
80
158
  // create(sender, senderFullname, recipient, text, id_project, createdBy, status, attributes, type, metadata) {
81
- return messageService.create(req.body.sender || req.user._id, req.body.senderFullname || req.user.fullName, request_id, req.body.text,
82
- req.projectid, req.user._id, messageStatus, req.body.attributes, req.body.type, req.body.metadata).then(function(savedMessage){
159
+ // return messageService.create(req.body.sender || req.user._id, req.body.senderFullname || req.user.fullName, request_id, req.body.text,
160
+ // req.projectid, req.user._id, messageStatus, req.body.attributes, req.body.type, req.body.metadata).then(function(savedMessage){
83
161
 
84
- // return requestService.incrementMessagesCountByRequestId(savedRequest.request_id, savedRequest.id_project).then(function(savedRequestWithIncrement) {
85
-
86
162
 
87
163
  winston.debug('res.json(savedRequest)');
88
164
  var endTimestamp = new Date();
89
165
  winston.verbose("request create end: " + (endTimestamp - startTimestamp));
90
166
  return res.json(savedRequest);
91
- });
167
+ // });
92
168
  // });
93
169
  });
94
170
 
@@ -20,6 +20,10 @@ class BotSubscriptionNotifier {
20
20
 
21
21
  var url = bot.url;
22
22
 
23
+ // if (url.startsWith("$ext_url")) {
24
+ // // url = url.replace ("$res_bot_url", prendi da env)
25
+ // }
26
+
23
27
  var json = {timestamp: Date.now(), payload: payload};
24
28
 
25
29
 
@@ -53,6 +57,7 @@ class BotSubscriptionNotifier {
53
57
 
54
58
  }, function(err, result, json){
55
59
  winston.verbose("SENT notify for bot with url " + url + " with err " + err);
60
+ winston.debug("SENT notify for bot with url ", result);
56
61
  if (err) {
57
62
  winston.error("Error sending notify for bot with url " + url + " with err " + err);
58
63
  //TODO Reply with error
@@ -1,21 +1,26 @@
1
1
 
2
2
  class CacheEnabler {
3
3
  constructor() {
4
+
5
+ // long TTL
4
6
  this.trigger = true;
5
7
  if (process.env.CACHE_TRIGGER_ENABLED=="false" || process.env.CACHE_TRIGGER_ENABLED==false) {
6
8
  this.trigger = false;
7
9
  }
8
10
 
11
+ // long TTL
9
12
  this.subscription = true;
10
13
  if (process.env.CACHE_SUBSCRIPTION_ENABLED=="false" || process.env.CACHE_SUBSCRIPTION_ENABLED==false) {
11
14
  this.subscription = false;
12
15
  }
13
16
 
17
+ //default TTL
14
18
  this.project = true;
15
19
  if (process.env.CACHE_PROJECT_ENABLED=="false" || process.env.CACHE_PROJECT_ENABLED==false) {
16
20
  this.project = false;
17
21
  }
18
22
 
23
+ //default TTL
19
24
  this.request = true;
20
25
  if (process.env.CACHE_REQUEST_ENABLED=="false" || process.env.CACHE_REQUEST_ENABLED==false) {
21
26
  this.request = false;
@@ -27,10 +32,10 @@ class CacheEnabler {
27
32
  }
28
33
 
29
34
 
30
- // this.project_user = true;
31
- // if (process.env.CACHE_PROJECT_USER_ENABLED=="false" || process.env.CACHE_PROJECT_USER_ENABLED==false) {
32
- // this.project_user = false;
33
- // }
35
+ this.project_user = true;
36
+ if (process.env.CACHE_PROJECT_USER_ENABLED=="false" || process.env.CACHE_PROJECT_USER_ENABLED==false) {
37
+ this.project_user = false;
38
+ }
34
39
 
35
40
  // this.user = true;
36
41
  // if (process.env.CACHE_USER_ENABLED=="false" || process.env.CACHE_USER_ENABLED==false) {
@@ -88,7 +88,7 @@ roundRobin(operatorSelectedEvent) {
88
88
 
89
89
  // let lastRequests = await
90
90
  // requestcachefarequi nocachepopulatereqired
91
- Request.find(query).sort({_id:-1}).limit(1).exec(function (err, lastRequests) { // cache_attention
91
+ Request.find(query).sort({_id:-1}).limit(1).exec(function (err, lastRequests) { // cache_attention use_lean use_select
92
92
  if (err) {
93
93
  winston.error('Error getting request for RoundRobinOperator', err);
94
94
  return reject(err);
@@ -193,8 +193,8 @@ getOperators(departmentid, projectid, nobot, disableWebHookCall, context) {
193
193
 
194
194
 
195
195
  let q = Project.findOne({_id: projectid, status: 100})
196
- if (cacheEnabler.project) {
197
- q.cache(cacheUtil.defaultTTL, "projects:id:"+projectid) //project_cache
196
+ if (cacheEnabler.project) {
197
+ q.cache(cacheUtil.longTTL, "projects:id:"+projectid) //project_cache
198
198
  winston.debug('project cache enabled');
199
199
  }
200
200
  return q.exec(function(err, project){
@@ -185,7 +185,7 @@ class FaqBotHandler {
185
185
  if (clonedfaqs && clonedfaqs.length>0) {
186
186
  clonedfaqs = clonedfaqs.shift()
187
187
  }
188
- winston.verbose("clonedfaqs", clonedfaqs);
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.verbose("clonedfaqs", clonedfaqs);
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) {
@@ -22,6 +22,7 @@ class FaqService {
22
22
  webhook_enabled: webhook_enabled,
23
23
  type: type,
24
24
  language: language,
25
+ public: false,
25
26
  trashed: false,
26
27
  createdBy: user_id,
27
28
  updatedBy: user_id
@@ -42,7 +43,7 @@ class FaqService {
42
43
  if (type==="internal" || type==="tilebot") {
43
44
 
44
45
  if (!template) {
45
- template = "example";
46
+ template = "empty";
46
47
  }
47
48
  winston.debug('template '+ template);
48
49
  that.createGreetingsAndOperationalsFaqs(savedFaq_kb._id, savedFaq_kb.createdBy, savedFaq_kb.id_project, template);
@@ -63,6 +64,7 @@ class FaqService {
63
64
 
64
65
  // aggiungi esempio tdAction con intent_id
65
66
 
67
+ // TODO non scatta i trigger sui rest hook. fare?
66
68
  winston.debug('template: '+ template);
67
69
 
68
70
  var faqsArray;
@@ -113,6 +115,10 @@ class FaqService {
113
115
  ]
114
116
 
115
117
  }
118
+
119
+ if (template === "empty") {
120
+ faqsArray = [];
121
+ }
116
122
 
117
123
 
118
124
  faqsArray.forEach(faq => {
@@ -121,6 +127,7 @@ class FaqService {
121
127
  id_faq_kb: faq_kb_id,
122
128
  question: faq.question,
123
129
  answer: faq.answer,
130
+ reply: faq.reply,
124
131
  intent_display_name: faq.intent_display_name,
125
132
  language: "en",
126
133
  id_project: projectid,
@@ -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)
@@ -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);
@@ -173,6 +173,8 @@ 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) {
177
179
  var that = this;
178
180
  return new Promise(function (resolve, reject) {
@@ -188,7 +190,6 @@ class MessageService {
188
190
  // winston.debug("updatedMessage", updatedMessage);
189
191
 
190
192
  that.emitMessage(updatedMessage);
191
-
192
193
  return resolve(updatedMessage);
193
194
  });
194
195
  });
@@ -12,8 +12,8 @@ class OperatingHoursService {
12
12
 
13
13
  // winston.debug('O ---> [ OHS ] -> PROJECT ID ', projectId)
14
14
  let q = Project.findOne({_id: projectId, status: 100});
15
- if (cacheEnabler.project) {
16
- q.cache(cacheUtil.defaultTTL, "projects:id:"+projectId) //project_cache
15
+ if (cacheEnabler.project) {
16
+ q.cache(cacheUtil.longTTL, "projects:id:"+projectId) //project_cache
17
17
  winston.debug('project cache enabled');
18
18
  }
19
19
  q.exec(function (err, project) {
package/test/faqRoute.js CHANGED
@@ -23,15 +23,12 @@ describe('FaqKBRoute', () => {
23
23
 
24
24
  describe('/create', () => {
25
25
 
26
-
27
-
28
26
  it('create', (done) => {
27
+
28
+ // this.timeout();
29
29
 
30
-
31
- // this.timeout();
32
-
33
- var email = "test-signup-" + Date.now() + "@email.com";
34
- var pwd = "pwd";
30
+ var email = "test-signup-" + Date.now() + "@email.com";
31
+ var pwd = "pwd";
35
32
 
36
33
  userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
37
34
  projectService.create("test-faqkb-create", savedUser._id).then(function(savedProject) {
@@ -44,7 +41,9 @@ describe('FaqKBRoute', () => {
44
41
  console.log("res.body", res.body);
45
42
  res.should.have.status(200);
46
43
  res.body.should.be.a('object');
47
- expect(res.body.name).to.equal("testbot");
44
+ expect(res.body.name).to.equal("testbot");
45
+ expect(res.body.public).to.exist;
46
+ expect(res.body.public).to.equal(false);
48
47
  var id_faq_kb = res.body._id;
49
48
 
50
49
  chai.request(server)
@@ -73,6 +72,123 @@ describe('FaqKBRoute', () => {
73
72
 
74
73
  });
75
74
 
75
+ it('create with template example', (done) => {
76
+
77
+ var email = "test-signup-" + Date.now() + "@email.com";
78
+ var pwd = "pwd";
79
+
80
+ userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
81
+ projectService.create("test-faqkb-create", savedUser._id).then((savedProject) => {
82
+
83
+ chai.request(server)
84
+ .post('/'+ savedProject._id + '/faq_kb')
85
+ .auth(email, pwd)
86
+ .send({"name":"testbot", type: "internal", template: "example" })
87
+ .end((err, res) => {
88
+ //console.log("res", res);
89
+ console.log("res.body", res.body);
90
+ res.should.have.status(200);
91
+ res.body.should.be.a('object');
92
+ expect(res.body.name).to.equal("testbot");
93
+ var id_faq_kb = res.body._id;
94
+
95
+ chai.request(server)
96
+ .get('/' + savedProject._id + '/faq?id_faq_kb=' + id_faq_kb)
97
+ .auth(email, pwd)
98
+ .end((err, res) => {
99
+ console.log("faq_list: ", res.body);
100
+ res.should.have.status(200);
101
+ res.body.should.be.an('array').that.is.not.empty;
102
+
103
+ done();
104
+
105
+ })
106
+
107
+
108
+
109
+ });
110
+ })
111
+ })
112
+ })
113
+
114
+
115
+ it('create with template empty', (done) => {
116
+
117
+
118
+ // this.timeout();
119
+
120
+ var email = "test-signup-" + Date.now() + "@email.com";
121
+ var pwd = "pwd";
122
+
123
+ userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
124
+ projectService.create("test-faqkb-create", savedUser._id).then(function(savedProject) {
125
+ chai.request(server)
126
+ .post('/'+ savedProject._id + '/faq_kb')
127
+ .auth(email, pwd)
128
+ .send({"name":"testbot", type: "tilebot"})
129
+ .end((err, res) => {
130
+ //console.log("res", res);
131
+ console.log("res.body (faqkb)", res.body);
132
+ res.should.have.status(200);
133
+ res.body.should.be.a('object');
134
+ expect(res.body.name).to.equal("testbot");
135
+ expect(res.body.type).to.equal("tilebot");
136
+ var id_faq_kb = res.body._id;
137
+
138
+ chai.request(server)
139
+ .get('/' + savedProject._id + '/faq?id_faq_kb=' + id_faq_kb)
140
+ .auth(email, pwd)
141
+ .end((err, res) => {
142
+ console.log("faq_list: ", res.body);
143
+ res.should.have.status(200);
144
+ res.body.should.be.an('array').that.is.empty;
145
+
146
+ var reply_example = {
147
+ type: "text",
148
+ text: "Hello with buttons",
149
+ attributes: {
150
+ attachment: {
151
+ type:"template",
152
+ buttons: [
153
+ {
154
+ type: "text",
155
+ value: "REPLY ONE"
156
+ },
157
+ {
158
+ type: "text",
159
+ value: "REPLY TWO"
160
+ }
161
+ ]
162
+ }
163
+ }
164
+ }
165
+
166
+ chai.request(server)
167
+ .post('/'+ savedProject._id + '/faq')
168
+ .auth(email, pwd)
169
+ .send({id_faq_kb: id_faq_kb, question: "question1", reply: reply_example })
170
+ .end((err, res) => {
171
+ //console.log("res", res);
172
+ console.log("res.body (faq reply)", res.body);
173
+ res.should.have.status(200);
174
+ res.body.should.be.a('object');
175
+ res.body.reply.should.be.a('object');
176
+ expect(res.body.id_faq_kb).to.equal(id_faq_kb);
177
+ expect(res.body.question).to.equal("question1");
178
+ expect(res.body.reply.type).to.equal(reply_example.type);
179
+ expect(res.body.reply.text).to.equal(reply_example.text);
180
+ expect(res.body.intent_display_name).to.not.equal(undefined);
181
+ expect(res.body.webhook_enabled).to.equal(false);
182
+
183
+ done();
184
+ });
185
+
186
+ })
187
+ });
188
+ });
189
+ });
190
+ });
191
+
76
192
 
77
193
 
78
194
 
@@ -90,7 +206,7 @@ describe('FaqKBRoute', () => {
90
206
  chai.request(server)
91
207
  .post('/'+ savedProject._id + '/faq_kb')
92
208
  .auth(email, pwd)
93
- .send({"name":"testbot", type: "internal", language: "it"})
209
+ .send({"name":"testbot", type: "internal", template: "example", language: "it"})
94
210
  .end((err, res) => {
95
211
  //console.log("res", res);
96
212
  console.log("res.body", res.body);
@@ -145,7 +261,7 @@ describe('FaqKBRoute', () => {
145
261
  chai.request(server)
146
262
  .post('/'+ savedProject._id + '/faq_kb')
147
263
  .auth(email, pwd)
148
- .send({"name":"testbot", type: "internal"})
264
+ .send({"name":"testbot", type: "internal", template: "example",})
149
265
  .end((err, res) => {
150
266
  //console.log("res", res);
151
267
  console.log("res.body", res.body);
@@ -277,7 +393,7 @@ describe('FaqKBRoute', () => {
277
393
  .post('/'+ savedProject._id + '/faq/uploadcsv')
278
394
  .auth(email, pwd)
279
395
  .set('Content-Type', 'text/csv')
280
- .attach('uploadFile', fs.readFileSync('./test/example-faqs.csv'), 'example-faqs.csv')
396
+ .attach('uploadFile', fs.readFileSync('./example-faqs.csv'), 'example-faqs.csv')
281
397
  .field('id_faq_kb', id_faq_kb)
282
398
  .field('delimiter', ';')
283
399
  // .send({id_faq_kb: id_faq_kb})
@@ -287,7 +403,7 @@ describe('FaqKBRoute', () => {
287
403
  res.should.have.status(200);
288
404
  res.body.should.be.a('object');
289
405
 
290
- done();
406
+ done();
291
407
  });
292
408
 
293
409
  });
@@ -331,7 +447,7 @@ describe('FaqKBRoute', () => {
331
447
  .post('/'+ savedProject._id + '/faq/uploadcsv')
332
448
  .auth(email, pwd)
333
449
  .set('Content-Type', 'text/csv')
334
- .attach('uploadFile', fs.readFileSync('./test/example-faqs.csv'), 'example-faqs.csv')
450
+ .attach('uploadFile', fs.readFileSync('./example-faqs.csv'), 'example-faqs.csv')
335
451
  .field('id_faq_kb', id_faq_kb)
336
452
  .field('delimiter', ';')
337
453
  // .send({id_faq_kb: id_faq_kb})
@@ -341,7 +457,7 @@ describe('FaqKBRoute', () => {
341
457
  res.should.have.status(200);
342
458
  res.body.should.be.a('object');
343
459
 
344
- done();
460
+ done();
345
461
  });
346
462
 
347
463
  });
@@ -146,7 +146,7 @@ it('upload-avatar', (done) => {
146
146
  });
147
147
 
148
148
  });
149
- });
149
+ }).timeout(1000);
150
150
 
151
151
 
152
152