@tiledesk/tiledesk-server 2.4.101 → 2.4.102

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,11 @@
5
5
  🚀 IN PRODUCTION 🚀
6
6
  (https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77)
7
7
 
8
+ # 2.4.102
9
+ - Updated whatsapp-connector to 0.1.63
10
+ - Updated messenger-connector to 0.1.17
11
+ - Added quote management
12
+
8
13
  # 2.4.101
9
14
  - Added new route for knowledge base
10
15
  - Bug fix: conflicts with old knowledge base
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.4.101",
4
+ "version": "2.4.102",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
@@ -42,11 +42,11 @@
42
42
  "@tiledesk/tiledesk-dialogflow-connector": "^1.8.4",
43
43
  "@tiledesk/tiledesk-json-rules-engine": "^4.0.3",
44
44
  "@tiledesk/tiledesk-kaleyra-proxy": "^0.1.7",
45
- "@tiledesk/tiledesk-messenger-connector": "^0.1.15",
45
+ "@tiledesk/tiledesk-messenger-connector": "^0.1.17",
46
46
  "@tiledesk/tiledesk-rasa-connector": "^1.0.10",
47
47
  "@tiledesk/tiledesk-telegram-connector": "^0.1.10",
48
48
  "@tiledesk/tiledesk-tybot-connector": "^0.2.50",
49
- "@tiledesk/tiledesk-whatsapp-connector": "^0.1.61",
49
+ "@tiledesk/tiledesk-whatsapp-connector": "^0.1.63",
50
50
  "@tiledesk/tiledesk-whatsapp-jobworker": "^0.0.7",
51
51
  "@tiledesk/tiledesk-chatbot-templates": "^0.1.2",
52
52
  "amqplib": "^0.5.5",
package/routes/auth.js CHANGED
@@ -276,7 +276,8 @@ router.post('/signinWithCustomToken', [
276
276
  if (req.user.role) {
277
277
  role = req.user.role;
278
278
  }
279
- winston.debug("role: " + role );
279
+ winston.debug("role1: " + role );
280
+ winston.debug("id_project: " + id_project + " uuid_user " + req.user._id + " role " + role);
280
281
 
281
282
 
282
283
  Project_user.findOne({ id_project: id_project, uuid_user: req.user._id, role: role}).
@@ -285,15 +286,18 @@ router.post('/signinWithCustomToken', [
285
286
  winston.error(err);
286
287
  return res.json({ success: true, token: req.headers["authorization"], user: req.user });
287
288
  }
289
+ winston.debug("project_user: ", project_user );
290
+
291
+
288
292
  if (!project_user) {
289
293
 
290
294
  let createNewUser = false;
291
- winston.debug('role: '+ role)
295
+ winston.debug('role2: '+ role)
292
296
 
293
297
 
294
298
  if (role === RoleConstants.OWNER || role === RoleConstants.ADMIN || role === RoleConstants.AGENT) {
295
299
  createNewUser = true;
296
-
300
+ winston.debug('role owner admin agent');
297
301
  var newUser;
298
302
  try {
299
303
 
@@ -328,6 +332,8 @@ router.post('/signinWithCustomToken', [
328
332
  updatedBy: req.user._id
329
333
  });
330
334
 
335
+ winston.debug('newProject_user', newProject_user);
336
+
331
337
  // testtare qiestp cpm dpcker dev partemdp da ui
332
338
  if (createNewUser===true) {
333
339
  newProject_user.id_user = newUser._id;
@@ -375,7 +381,11 @@ router.post('/signinWithCustomToken', [
375
381
 
376
382
  }
377
383
 
378
- if (returnToken.indexOf("JWT")==0) {
384
+ winston.debug('returnToken '+returnToken);
385
+
386
+ winston.debug('returnToken.indexOf("JWT") '+returnToken.indexOf("JWT"));
387
+
388
+ if (returnToken.indexOf("JWT")<0) {
379
389
  returnToken = "JWT " + returnToken;
380
390
  }
381
391
 
@@ -408,7 +418,7 @@ router.post('/signinWithCustomToken', [
408
418
  let returnToken = jwt.sign(userJson, configSecret, signOptions); //priv_jwt pp_jwt
409
419
 
410
420
 
411
- if (returnToken.indexOf("JWT")==0) {
421
+ if (returnToken.indexOf("JWT")<0) {
412
422
  returnToken = "JWT " + returnToken;
413
423
  }
414
424
  return res.json({ success: true, token: returnToken, user: userFromDB });
@@ -416,6 +426,8 @@ router.post('/signinWithCustomToken', [
416
426
 
417
427
 
418
428
  } else {
429
+ winston.debug('req.headers["authorization"]: '+req.headers["authorization"]);
430
+
419
431
  return res.json({ success: true, token: req.headers["authorization"], user: userToReturn });
420
432
  }
421
433
 
package/routes/faq.js CHANGED
@@ -467,7 +467,6 @@ router.put('/:faqid', function (req, res) {
467
467
  // DELETE REMOTE AND LOCAL FAQ
468
468
  router.delete('/:faqid', function (req, res) {
469
469
 
470
- console.log("delete called")
471
470
  winston.debug('DELETE FAQ - FAQ ID ', req.params.faqid);
472
471
 
473
472
  let faqid = req.params.faqid;
package/routes/faq_kb.js CHANGED
@@ -639,7 +639,7 @@ router.post('/fork/:id_faq_kb', async (req, res) => {
639
639
 
640
640
  let globals = req.query.globals;
641
641
  winston.debug("export globals " + globals);
642
- console.log("export globals? --> globals ", globals);
642
+
643
643
 
644
644
  let token = req.headers.authorization;
645
645
 
@@ -647,7 +647,7 @@ router.post('/fork/:id_faq_kb', async (req, res) => {
647
647
 
648
648
  let chatbot = await cs.getBotById(id_faq_kb, public, api_url, chatbot_templates_api_url, token, current_project_id, globals);
649
649
  winston.debug("chatbot: ", chatbot)
650
- console.log("/fork chatbot after getBotById: ", chatbot);
650
+
651
651
  if (!chatbot) {
652
652
  return res.status(500).send({ success: false, message: "Unable to get chatbot" });
653
653
  }
@@ -982,8 +982,6 @@ router.post('/importjson/:id_faq_kb', upload.single('uploadFile'), async (req, r
982
982
  router.get('/exportjson/:id_faq_kb', (req, res) => {
983
983
 
984
984
  winston.debug("exporting bot...")
985
- console.log("exportjson req.query.globals: ", req.query.globals);
986
-
987
985
 
988
986
  let id_faq_kb = req.params.id_faq_kb;
989
987
 
@@ -1000,12 +998,10 @@ router.get('/exportjson/:id_faq_kb', (req, res) => {
1000
998
  const intents = faqs.map(({ _id, id_project, topic, status, id_faq_kb, createdBy, createdAt, updatedAt, __v, ...keepAttrs }) => keepAttrs)
1001
999
 
1002
1000
  if (!req.query.globals) {
1003
- console.log("Delete globals from attributes!")
1001
+ winston.verbose("Delete globals from attributes!")
1004
1002
  if (faq_kb.attributes) {
1005
1003
  delete faq_kb.attributes.globals;
1006
1004
  }
1007
- } else {
1008
- console.log("Keep globals")
1009
1005
  }
1010
1006
 
1011
1007
  let json = {
@@ -1033,7 +1029,6 @@ router.get('/exportjson/:id_faq_kb', (req, res) => {
1033
1029
  // return res.status(200).send(json);
1034
1030
  // }
1035
1031
  let json_string = JSON.stringify(json);
1036
- console.log("json_string: ", json_string)
1037
1032
  res.set({ "Content-Disposition": "attachment; filename=\"bot.json\"" });
1038
1033
  return res.send(json_string);
1039
1034
  }
package/routes/kb.js CHANGED
@@ -39,8 +39,6 @@ router.post('/', async (req, res) => {
39
39
 
40
40
  let project_id = req.projectid;
41
41
  let body = req.body;
42
- console.log("create new kb project_id " + project_id);
43
- console.log("create new kb body ", body);
44
42
 
45
43
  let new_kb = {
46
44
  id_project: project_id,
@@ -4,22 +4,6 @@ const requestEvent = require('../event/requestEvent');
4
4
  const messageEvent = require('../event/messageEvent');
5
5
  const emailEvent = require('../event/emailEvent');
6
6
 
7
- // const PLANS_LIST = {
8
- // FREE_TRIAL: { users: 2, requests: 3000, chatbots: 20, kbs: 3, kb_pages: 500, tokens: 250000 }, // same as PREMIUM
9
- // SANDBOX: { users: 1, requests: 200, chatbots: 2, kbs: 1, kb_pages: 50, tokens: 10000 },
10
- // BASIC: { users: 1, requests: 810, chatbots: 5, kbs: 2, kb_pages: 250, tokens: 50000 },
11
- // PREMIUM: { users: 2, requests: 3000, chatbots: 20, kbs: 3, kb_pages: 500, tokens: 250000 },
12
- // CUSTOM: { users: 100, conversations: 10000, chatbots: 100, kbs: 100, kb_pages: 1000, tokens: 100000 } // manage it --> get limit directly from project info
13
- // }
14
-
15
- // const PLANS_LIST = {
16
- // FREE_TRIAL: { users: 2, requests: 3000, chatbots: 20, kbs: 3, kb_pages: 500, tokens: 250000 }, // same as PREMIUM
17
- // SANDBOX: { users: 1, requests: 200, chatbots: 2, kbs: 1, kb_pages: 50, tokens: 10000 },
18
- // BASIC: { users: 1, requests: 800, chatbots: 5, kbs: 2, kb_pages: 250, tokens: 50000 },
19
- // PREMIUM: { users: 2, requests: 3000, chatbots: 20, kbs: 3, kb_pages: 500, tokens: 250000 },
20
- // CUSTOM: { users: 2, requests: 3000, chatbots: 20, kbs: 3, kb_pages: 5000, tokens: 1000000 }
21
- // }
22
-
23
7
  const PLANS_LIST = {
24
8
  FREE_TRIAL: { requests: 3000, messages: 0, tokens: 250000, email: 200 }, // same as PREMIUM
25
9
  SANDBOX: { requests: 200, messages: 0, tokens: 10000, email: 200 },
@@ -99,6 +83,8 @@ class QuoteManager {
99
83
 
100
84
  async generateKey(object, type) {
101
85
 
86
+ winston.info("generateKey object ", object)
87
+ winston.info("generateKey type " + type)
102
88
  let subscriptionDate;
103
89
  if (this.project.profile.subStart) {
104
90
  subscriptionDate = this.project.profile.subStart;
@@ -106,6 +92,7 @@ class QuoteManager {
106
92
  subscriptionDate = this.project.createdAt;
107
93
  }
108
94
  let objectDate = object.createdAt;
95
+ winston.info("objectDate " + objectDate);
109
96
 
110
97
  // converts date in timestamps and transform from ms to s
111
98
  const objectDateTimestamp = ceil(objectDate.getTime() / 1000);
@@ -127,7 +114,7 @@ class QuoteManager {
127
114
 
128
115
  this.project = project;
129
116
  let key = await this.generateKey(object, type);
130
- winston.verbose("[QuoteManager] getCurrentQuote key: " + key);
117
+ winston.info("[QuoteManager] getCurrentQuote key: " + key);
131
118
 
132
119
  let quote = await this.tdCache.get(key);
133
120
  return Number(quote);
@@ -142,18 +129,15 @@ class QuoteManager {
142
129
 
143
130
  let quotes = {}
144
131
  for (let type of typesList) {
145
- console.log("*** get all quotes --> search for type: ", type);
132
+
146
133
  let key = await this.generateKey(obj, type);
147
- console.log("*** get all quotes --> key generated: ", key);
148
134
  let quote = await this.tdCache.get(key);
149
- console.log("*** get all quotes --> quote retrieved: ", quote);
150
135
 
151
136
  quotes[type] = {
152
137
  quote: Number(quote)
153
138
  };
154
139
  }
155
140
  return quotes;
156
-
157
141
  }
158
142
 
159
143
  /**
@@ -163,15 +147,19 @@ class QuoteManager {
163
147
  */
164
148
  async checkQuote(project, object, type) {
165
149
 
150
+ winston.info("checkQuote project ", project);
151
+ winston.info("checkQuote object ", object);
152
+ winston.info("checkQuote type " + type);
166
153
  if (quotes_enabled === false) {
167
- winston.debug("QUOTES DISABLED - checkQuote for type " + type);
154
+ winston.info("QUOTES DISABLED - checkQuote for type " + type);
168
155
  return true;
169
156
  }
170
157
 
171
158
  this.project = project;
172
159
  let limits = await this.getPlanLimits();
173
- console.log("limits for current plan: ", limits)
160
+ winston.info("limits for current plan: ", limits)
174
161
  let quote = await this.getCurrentQuote(project, object, type);
162
+ winston.info("getCurrentQuote resp: ", quote)
175
163
 
176
164
  if (quote == null) {
177
165
  return true;
@@ -258,8 +246,7 @@ class QuoteManager {
258
246
  let result = await this.incrementRequestsCount(payload.project, payload.request);
259
247
  return result;
260
248
  } else {
261
- console.log("QUOTES DISABLED - request.create.quote event")
262
- winston.debug("QUOTES DISABLED - request.create.quote event")
249
+ winston.info("QUOTES DISABLED - request.create.quote event")
263
250
  }
264
251
  })
265
252
  // REQUESTS EVENTS - END
@@ -282,7 +269,7 @@ class QuoteManager {
282
269
  let result = await this.incrementMessagesCount(payload.project, payload.message);
283
270
  return result;
284
271
  } else {
285
- winston.debug("QUOTES DISABLED - message.create.quote event")
272
+ winston.info("QUOTES DISABLED - message.create.quote event")
286
273
  }
287
274
  })
288
275
  // MESSAGES EVENTS - END
@@ -305,7 +292,7 @@ class QuoteManager {
305
292
  let result = await this.incrementEmailCount(payload.project, payload.email);
306
293
  return result;
307
294
  } else {
308
- winston.debug("QUOTES DISABLED - email.send event")
295
+ winston.info("QUOTES DISABLED - email.send event")
309
296
  }
310
297
  })
311
298
  // EMAIL EVENTS - END
@@ -32,7 +32,6 @@ class ChatbotService {
32
32
  async getBotById(id_faq_kb, published, api_url, chatbot_templates_api_url, token, project_id, globals) {
33
33
 
34
34
  winston.debug("[CHATBOT SERVICE] getBotById");
35
- console.log("getBotById globals: ", globals);
36
35
 
37
36
  // private bot
38
37
  if (published == "false") {
@@ -46,52 +46,13 @@ class MessageService {
46
46
 
47
47
  save(message) {
48
48
 
49
- let total_1;
50
- let total_e;
51
- let total_1_end_e;
52
- let total_2;
53
-
54
49
  var that = this;
55
50
  winston.debug('message.save called');
56
51
 
57
- message.createdAt = new Date();
58
-
59
- // let start1 = Date.now();
60
- // let project;
61
- // let payload;
62
- // let q = Project.findOne({ _id: message.id_project, status: 100 });
63
- // if (cacheEnabler.project) {
64
- // q.cache(cacheUtil.longTTL, "projects:id:" + message.id_project) //project_cache
65
- // winston.debug('project cache enabled for /project detail');
66
- // }
67
- // q.exec(async function (err, p) {
68
- // if (err) {
69
- // winston.error('Error getting project ', err);
70
- // }
71
- // if (!p) {
72
- // winston.warn('Project not found ');
73
- // }
74
- // //TODO REMOVE settings from project
75
- // project = p;
76
- // payload = {
77
- // project: project,
78
- // message: message
79
- // }
80
-
81
- // let end1 = Date.now();
82
- // total_1 = end1 - start1;
83
-
84
- // let start_e = Date.now();
85
- // let result = await messageEvent.emit('message.create.quote.before', payload);
86
- // let end_e = Date.now();
87
- // total_e = end_e - start_e;
88
- // if (result === false) {
89
- // winston.info("Messages limits reached for project " + project._id)
90
- // // return false in the second phase
91
- // }
92
- // });
93
-
94
- // let start2 = Date.now();
52
+ if (!message.createdAt) {
53
+ message.createdAt = new Date();
54
+ }
55
+
95
56
  let sender = message.sender;
96
57
  let senderFullname = message.senderFullname;
97
58
  let recipient = message.recipient;
@@ -111,6 +72,9 @@ class MessageService {
111
72
 
112
73
  return new Promise(function (resolve, reject) {
113
74
 
75
+ //let q = Project.findOne({ _id: request.id_project, status: 100 });
76
+ // Continue quotes code here (see at requestService)
77
+
114
78
  if (!createdBy) {
115
79
  createdBy = sender;
116
80
  }
@@ -196,11 +160,7 @@ class MessageService {
196
160
  message: message
197
161
  }
198
162
 
199
- let result = await messageEvent.emit('message.create.quote', payload);
200
- if (result === false) {
201
- winston.info("Messages limits reached for project " + p._id)
202
- // return false in the second phase
203
- }
163
+ messageEvent.emit('message.create.quote', payload);
204
164
  });
205
165
 
206
166
 
@@ -212,13 +172,6 @@ class MessageService {
212
172
  // messageEvent.emit('message.sending.simple', savedMessage);
213
173
  // }
214
174
 
215
- // console.log("total 1: ", total_1);
216
- // console.log("total e: ", total_e);
217
- // total_1_end_e = total_1 + total_e;
218
- // console.log("total 1 + e: ", total_1_end_e);
219
- // console.log("total 2: ", total_2);
220
-
221
-
222
175
  return resolve(savedMessage);
223
176
  });
224
177
 
@@ -11,7 +11,7 @@ class OpenaiService {
11
11
  // OPEN AI
12
12
  completions(data, gptkey) {
13
13
 
14
- winston.debug("[OPENAI SERVICE] openai endpoint: ", openai_endpoint);
14
+ winston.debug("[OPENAI SERVICE] openai endpoint: " + openai_endpoint);
15
15
 
16
16
  return new Promise((resolve, reject) => {
17
17
 
@@ -36,7 +36,7 @@ class OpenaiService {
36
36
 
37
37
  // PUGLIA AI
38
38
  checkStatus(data) {
39
- winston.debug("[OPENAI SERVICE] kb endpoint: ", kb_endpoint);
39
+ winston.debug("[OPENAI SERVICE] kb endpoint: " + kb_endpoint);
40
40
 
41
41
  return new Promise((resolve, reject) => {
42
42
 
@@ -50,7 +50,6 @@ class OpenaiService {
50
50
  }).then((resbody) => {
51
51
  resolve(resbody);
52
52
  }).catch((err) => {
53
- console.log("checkStatus err: ", err)
54
53
  reject(err);
55
54
  })
56
55
 
@@ -58,7 +57,7 @@ class OpenaiService {
58
57
  }
59
58
 
60
59
  startScrape(data) {
61
- winston.debug("[OPENAI SERVICE] kb endpoint: ", kb_endpoint);
60
+ winston.debug("[OPENAI SERVICE] kb endpoint: " + kb_endpoint);
62
61
 
63
62
  return new Promise((resolve, reject) => {
64
63
 
@@ -79,7 +78,7 @@ class OpenaiService {
79
78
  }
80
79
 
81
80
  ask(data) {
82
- winston.debug("[OPENAI SERVICE] kb endpoint: ", kb_endpoint);
81
+ winston.debug("[OPENAI SERVICE] kb endpoint: " + kb_endpoint);
83
82
 
84
83
  return new Promise((resolve, reject) => {
85
84
 
@@ -93,7 +92,6 @@ class OpenaiService {
93
92
  }).then((resbody) => {
94
93
  resolve(resbody);
95
94
  }).catch((err) => {
96
- console.log("err: ", err);
97
95
  reject(err);
98
96
  })
99
97
 
@@ -102,7 +100,7 @@ class OpenaiService {
102
100
 
103
101
  // PUGLIA AI V2
104
102
  singleScrape(data) {
105
- winston.debug("[OPENAI SERVICE] kb endpoint: ", kb_endpoint_dev);
103
+ winston.debug("[OPENAI SERVICE] kb endpoint: " + kb_endpoint_dev);
106
104
 
107
105
  return new Promise((resolve, reject) => {
108
106
 
@@ -123,7 +121,7 @@ class OpenaiService {
123
121
  }
124
122
 
125
123
  scrapeStatus(data) {
126
- winston.debug("[OPENAI SERVICE] kb endpoint: ", kb_endpoint_dev);
124
+ winston.debug("[OPENAI SERVICE] kb endpoint: " + kb_endpoint_dev);
127
125
 
128
126
  return new Promise((resolve, reject) => {
129
127
 
@@ -143,7 +141,7 @@ class OpenaiService {
143
141
  }
144
142
 
145
143
  askNamespace(data) {
146
- winston.debug("[OPENAI SERVICE] kb endpoint: ", kb_endpoint_dev);
144
+ winston.debug("[OPENAI SERVICE] kb endpoint: " + kb_endpoint_dev);
147
145
 
148
146
  return new Promise((resolve, reject) => {
149
147
 
@@ -164,7 +162,7 @@ class OpenaiService {
164
162
  }
165
163
 
166
164
  deleteIndex(data) {
167
- winston.debug("[OPENAI SERVICE] kb endpoint: ", kb_endpoint_dev);
165
+ winston.debug("[OPENAI SERVICE] kb endpoint: " + kb_endpoint_dev);
168
166
 
169
167
  return new Promise((resolve, reject) => {
170
168
 
@@ -184,7 +182,7 @@ class OpenaiService {
184
182
  }
185
183
 
186
184
  deleteNamespace(data) {
187
- winston.debug("[OPENAI SERVICE] kb endpoint: ", kb_endpoint_dev);
185
+ winston.debug("[OPENAI SERVICE] kb endpoint: " + kb_endpoint_dev);
188
186
 
189
187
  return new Promise((resolve, reject) => {
190
188
 
@@ -709,31 +709,7 @@ class RequestService {
709
709
  winston.verbose("Performance Request created in millis: " + endDate - startDate);
710
710
 
711
711
  requestEvent.emit('request.create.simple', savedRequest);
712
-
713
- // let q = Project.findOne({ _id: request.id_project, status: 100 });
714
- // if (cacheEnabler.project) {
715
- // q.cache(cacheUtil.longTTL, "projects:id:" + request.id_project) //project_cache
716
- // winston.debug('project cache enabled for /project detail');
717
- // }
718
- // q.exec(async function (err, p) {
719
- // if (err) {
720
- // winston.error('Error getting project ', err);
721
- // }
722
- // if (!p) {
723
- // winston.warn('Project not found ');
724
- // }
725
- // //TODO REMOVE settings from project
726
- // let payload = {
727
- // project: p,
728
- // request: request
729
- // }
730
-
731
- // });
732
712
  requestEvent.emit('request.create.quote', payload);;
733
- // if (result === false) {
734
- // winston.info("Requests limits reached for project " + p._id)
735
- // // return false in the second phase
736
- // }
737
713
 
738
714
  return resolve(savedRequest);
739
715