@tiledesk/tiledesk-server 2.5.0 → 2.5.2

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-chat21-app",
3
3
  "description": "The Tiledesk Chat21 module",
4
- "version": "1.1.7",
4
+ "version": "1.1.8",
5
5
  "private": false,
6
6
  "author": "Andrea Leo - Frontiere21 SRL",
7
7
  "license": "AGPL-3.0",
@@ -11,7 +11,7 @@
11
11
  "url": "https://github.com/Tiledesk/tiledesk-server"
12
12
  },
13
13
  "dependencies": {
14
- "@chat21/chat21-node-sdk": "^1.1.7",
14
+ "@chat21/chat21-node-sdk": "^1.1.8",
15
15
  "winston": "^3.3.3",
16
16
  "firebase-admin": "^9.5.0"
17
17
  },
package/deploy.sh CHANGED
@@ -1,5 +1,5 @@
1
1
  git pull
2
- npm version minor
2
+ npm version patch
3
3
  version=`node -e 'console.log(require("./package.json").version)'`
4
4
  echo "version $version"
5
5
 
@@ -464,12 +464,12 @@ if (enableGoogleSignin==true) {
464
464
  },
465
465
  function(issuer, profile, cb) {
466
466
 
467
- winston.info("issuer: "+issuer)
468
- winston.info("profile", profile)
467
+ winston.debug("issuer: "+issuer)
468
+ winston.debug("profile", profile)
469
469
  // winston.info("cb", cb)
470
470
 
471
471
  var email = profile.emails[0].value;
472
- winston.info("email: "+email)
472
+ winston.debug("email: "+email)
473
473
 
474
474
  var query = {providerId : issuer, subject: profile.id};
475
475
  winston.debug("query", query)
@@ -31,19 +31,12 @@ var KBSchema = new Schema({
31
31
  type: String,
32
32
  required: false
33
33
  },
34
- createdAt: {
35
- type: Date,
36
- default: Date.now,
37
- },
38
- updatedAt: {
39
- type: Date,
40
- default: Date.now
41
- },
42
34
  status: {
43
35
  type: Number,
44
- required: false,
45
- default: -1
36
+ required: false
46
37
  }
38
+ }, {
39
+ timestamps: true
47
40
  })
48
41
 
49
42
  var KBSettingSchema = new Schema({
@@ -64,9 +57,11 @@ var KBSettingSchema = new Schema({
64
57
  type: Number,
65
58
  default: 1000
66
59
  },
67
- kbs: [ KBSchema ]
60
+ kbs: [KBSchema]
68
61
  });
69
62
 
63
+ KBSchema.index({ createdAt: -1, updatedAt: -1 })
64
+
70
65
 
71
66
  //module.exports = mongoose.model('KBSettings', KBSettingSchema);
72
67
  const KBSettings = mongoose.model('KBSettings', KBSettingSchema);
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.5.0",
4
+ "version": "2.5.2",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
@@ -37,15 +37,15 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@tiledesk/tiledesk-apps": "^1.0.17",
40
- "@tiledesk/tiledesk-chat21-app": "^1.1.7",
40
+ "@tiledesk/tiledesk-chat21-app": "^1.1.8",
41
41
  "@tiledesk/tiledesk-chatbot-util": "^0.8.33",
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.17",
45
+ "@tiledesk/tiledesk-messenger-connector": "^0.1.18",
46
46
  "@tiledesk/tiledesk-rasa-connector": "^1.0.10",
47
47
  "@tiledesk/tiledesk-telegram-connector": "^0.1.10",
48
- "@tiledesk/tiledesk-tybot-connector": "^0.2.54",
48
+ "@tiledesk/tiledesk-tybot-connector": "^0.2.56",
49
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",
@@ -150,6 +150,16 @@ function startWorker() {
150
150
  winston.info("Data queue", oka)
151
151
  });
152
152
 
153
+ ch.bindQueue(_ok.queue, exchange, "request_participants_join", {}, function(err3, oka) {
154
+ winston.info("Queue bind: "+_ok.queue+ " err: "+err3+ " key: request_participants_join");
155
+ winston.info("Data queue", oka)
156
+ });
157
+
158
+ ch.bindQueue(_ok.queue, exchange, "request_participants_leave", {}, function(err3, oka) {
159
+ winston.info("Queue bind: "+_ok.queue+ " err: "+err3+ " key: request_participants_leave");
160
+ winston.info("Data queue", oka)
161
+ });
162
+
153
163
  ch.bindQueue(_ok.queue, exchange, "request_update", {}, function(err3, oka) {
154
164
  winston.info("Queue bind: "+_ok.queue+ " err: "+err3+ " key: request_update");
155
165
  winston.info("Data queue", oka)
@@ -230,6 +240,19 @@ function work(msg, cb) {
230
240
  // requestEvent.emit('request.update.queue', msg.content);
231
241
  requestEvent.emit('request.update.preflight.queue', JSON.parse(message_string));
232
242
  }
243
+
244
+ if (topic === 'request_participants_join') {
245
+ winston.debug("reconnect here topic:" + topic);
246
+ // requestEvent.emit('request.update.queue', msg.content);
247
+ requestEvent.emit('request.participants.join.queue', JSON.parse(message_string));
248
+ }
249
+
250
+
251
+ if (topic === 'request_participants_leave') {
252
+ winston.debug("reconnect here topic:" + topic);
253
+ // requestEvent.emit('request.update.queue', msg.content);
254
+ requestEvent.emit('request.participants.leave.queue', JSON.parse(message_string));
255
+ }
233
256
 
234
257
  if (topic === 'request_participants_update') {
235
258
  winston.debug("reconnect here topic:" + topic);
@@ -312,8 +335,19 @@ function listen() {
312
335
  });
313
336
  });
314
337
 
338
+ requestEvent.on('request.participants.join', function(request) {
339
+ setImmediate(() => {
340
+ publish(exchange, "request_participants_join", Buffer.from(JSON.stringify(request)));
341
+ winston.debug("reconnect participants.join published")
342
+ });
343
+ });
315
344
 
316
-
345
+ requestEvent.on('request.participants.leave', function(request) {
346
+ setImmediate(() => {
347
+ publish(exchange, "request_participants_leave", Buffer.from(JSON.stringify(request)));
348
+ winston.debug("reconnect participants.leave published")
349
+ });
350
+ });
317
351
 
318
352
  requestEvent.on('request.participants.update', function(request) {
319
353
  setImmediate(() => {
@@ -41,13 +41,14 @@ class Listener {
41
41
 
42
42
 
43
43
  updateProjectUser(id_user, id_project, operation) {
44
- winston.debug("Route queue updateProjectUser start");
44
+ winston.debug("Route queue updateProjectUser start operation: " +operation+ "id_user "+ id_user + " id_project " + id_project );
45
45
  return Project_user
46
46
  .findOneAndUpdate({id_user: id_user, id_project: id_project}, {$inc : {'number_assigned_requests' : operation}}, {new: true, upsert:false}, function(err, updatedPU) {
47
47
  if (err) {
48
48
  return winston.error(err);
49
49
  }
50
50
  winston.debug("Route queue number_assigned_requests +1 :" + updatedPU.id);
51
+ winston.debug("Route queue number_assigned_requests +1 :" + updatedPU.id);
51
52
 
52
53
  updatedPU.populate({path:'id_user', select:{'firstname':1, 'lastname':1}},function (err, updatedProject_userPopulated){
53
54
 
@@ -77,7 +78,10 @@ class Listener {
77
78
  if (request.participatingAgents.length>0) {
78
79
  request.participatingAgents.forEach(user => {
79
80
  winston.debug("request.participatingAgents user",user); //it is a user and not a project_user
80
- this.updateProjectUser(user.id, request.id_project, operation);
81
+ var userid = user.id || user._id;
82
+ winston.debug("updateParticipatingProjectUsers userid: "+userid);
83
+
84
+ this.updateProjectUser(userid, request.id_project, operation);
81
85
  });
82
86
  }
83
87
  }
package/routes/kb.js CHANGED
@@ -8,16 +8,103 @@ const openaiService = require('../services/openaiService');
8
8
  router.get('/', async (req, res) => {
9
9
 
10
10
  let project_id = req.projectid;
11
+ let status;
12
+ let limit = 200;
13
+ let page = 0;
14
+ let direction = -1;
15
+ let sortField = "updatedAt";
16
+ let text;
17
+
18
+ let query = {};
19
+ query["id_project"] = project_id;
20
+
21
+ if (req.query.status) {
22
+ status = parseInt(req.query.status);
23
+ query["status"] = status;
24
+ winston.debug("Get kb status: " + status)
25
+ }
26
+ if (req.query.limit) {
27
+ limit = parseInt(req.query.limit);
28
+ winston.debug("Get kb limit: " + limit)
29
+ }
30
+
31
+ if (req.query.page) {
32
+ page = parseInt(req.query.page);
33
+ winston.debug("Get kb page: " + page)
34
+ }
35
+
36
+ let skip = page * limit;
37
+ winston.debug("Get kb skip page: " + skip);
38
+
39
+ if (req.query.direction) {
40
+ direction = parseInt(req.query.direction)
41
+ winston.debug("Get kb direction: " + direction)
42
+ }
43
+
44
+ if (req.query.sortField) {
45
+ sortField = req.query.sortField;
46
+ winston.debug("Get kb sortField: " + sortField)
47
+ }
48
+
49
+ if (req.query.search) {
50
+ text = req.query.search;
51
+ query['source'] = new RegExp(text);
52
+ winston.debug("Get kb text: " + text);
53
+ }
54
+
55
+ let sortQuery = {};
56
+ sortQuery[sortField] = direction;
57
+ winston.debug("Get kb sortQuery: " + sortQuery);
58
+
59
+ KB.countDocuments(query, (err, kbs_count) => {
60
+ if (err) {
61
+ winston.error("Find all kbs error: ", err);
62
+ }
63
+ winston.debug("KBs count: ", kbs_count);
64
+
65
+ KB.find(query)
66
+ .skip(skip)
67
+ .limit(limit)
68
+ .sort(sortQuery)
69
+ .exec((err, kbs) => {
70
+ if (err) {
71
+ winston.error("Find all kbs error: ", err);
72
+ return res.status(500).send({ success: false, error: err });
73
+ }
74
+
75
+ winston.debug("KBs found: ", kbs);
76
+
77
+ let response = {
78
+ count: kbs_count,
79
+ query: {},
80
+ kbs: kbs
81
+ }
82
+ if (status) {
83
+ response.query.status = status;
84
+ }
85
+ if (limit) {
86
+ response.query.limit = limit;
87
+ }
88
+ if (status) {
89
+ response.query.page = page;
90
+ }
91
+ if (sortField) {
92
+ response.query.sortField = sortField;
93
+ }
94
+ if (direction) {
95
+ response.query.direction = direction;
96
+ }
97
+ if (text) {
98
+ response.query.search = text;
99
+ }
100
+
101
+
102
+ return res.status(200).send(response);
103
+ })
104
+
105
+ })
11
106
 
12
- KB.find({ id_project: project_id }, (err, kbs) => {
13
- if (err) {
14
- winston.error("Find all kbs error: ", err);
15
- return res.status(500).send({ success: false, error: err });
16
- }
17
107
 
18
- winston.debug("KBs found: ", kbs);
19
- return res.status(200).send(kbs);
20
- })
21
108
  })
22
109
 
23
110
  router.get('/:kb_id', async (req, res) => {
@@ -46,7 +133,8 @@ router.post('/', async (req, res) => {
46
133
  type: body.type,
47
134
  source: body.source,
48
135
  content: body.content,
49
- namespace: body.namespace
136
+ namespace: body.namespace,
137
+ status: -1
50
138
  }
51
139
  if (!new_kb.namespace) {
52
140
  new_kb.namespace = project_id;
@@ -101,7 +189,6 @@ router.put('/:kb_id', async (req, res) => {
101
189
  update.status = req.body.status;
102
190
  }
103
191
 
104
- update.updatedAt = new Date();
105
192
  winston.debug("kb update: ", update);
106
193
 
107
194
  KB.findByIdAndUpdate(kb_id, update, { new: true }, (err, savedKb) => {
package/routes/request.js CHANGED
@@ -802,7 +802,7 @@ router.delete('/:requestid', function (req, res) {
802
802
  });
803
803
 
804
804
 
805
- Request.remove({ request_id: req.params.requestid }, function (err, request) {
805
+ Request.findOneAndDelete({ request_id: req.params.requestid }, function (err, request) {
806
806
  if (err) {
807
807
  winston.error('--- > ERROR ', err);
808
808
  return res.status(500).send({ success: false, msg: 'Error deleting object.' });
@@ -819,6 +819,24 @@ router.delete('/:requestid', function (req, res) {
819
819
  res.json(request);
820
820
 
821
821
  });
822
+
823
+ // Request.remove({ request_id: req.params.requestid }, function (err, request) {
824
+ // if (err) {
825
+ // winston.error('--- > ERROR ', err);
826
+ // return res.status(500).send({ success: false, msg: 'Error deleting object.' });
827
+ // }
828
+
829
+ // if (!request) {
830
+ // return res.status(404).send({ success: false, msg: 'Object not found.' });
831
+ // }
832
+
833
+ // winston.verbose('Request deleted with request_id: ' + req.params.requestid);
834
+
835
+ // requestEvent.emit('request.delete', request);
836
+
837
+ // res.json(request);
838
+
839
+ // });
822
840
  });
823
841
 
824
842
 
package/test/kbRoute.js CHANGED
@@ -73,6 +73,98 @@ describe('KbRoute', () => {
73
73
 
74
74
  });
75
75
 
76
+ it('getWithQueries', (done) => {
77
+
78
+ var email = "test-signup-" + Date.now() + "@email.com";
79
+ var pwd = "pwd";
80
+
81
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
82
+ projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
83
+
84
+ let kb1 = {
85
+ name: "example_name1",
86
+ type: "url",
87
+ source: "https://www.exampleurl1.com",
88
+ content: ""
89
+ }
90
+
91
+ let kb2 = {
92
+ name: "example_name2",
93
+ type: "text",
94
+ source: "example_name2",
95
+ content: "example content"
96
+ }
97
+
98
+ let kb3 = {
99
+ name: "example_name3",
100
+ type: "url",
101
+ source: "https://www.exampleurl3.com",
102
+ content: ""
103
+ }
104
+
105
+ chai.request(server)
106
+ .post('/' + savedProject._id + "/kb")
107
+ .auth(email, pwd)
108
+ .send(kb1)
109
+ .end((err, res) => {
110
+ if (log) { console.log("create kb res.body: ", res.body); }
111
+ res.should.have.status(200);
112
+
113
+ setTimeout(() => {
114
+ chai.request(server)
115
+ .post('/' + savedProject._id + "/kb")
116
+ .auth(email, pwd)
117
+ .send(kb2)
118
+ .end((err, res) => {
119
+ if (log) { console.log("create kb res.body: ", res.body); }
120
+ res.should.have.status(200);
121
+
122
+ setTimeout(() => {
123
+ chai.request(server)
124
+ .post('/' + savedProject._id + "/kb")
125
+ .auth(email, pwd)
126
+ .send(kb3)
127
+ .end((err, res) => {
128
+ if (log) { console.log("create kb res.body: ", res.body); }
129
+ res.should.have.status(200);
130
+
131
+ let query = "?status=-1&limit=5&page=0&direction=-1&sortField=updatedAt&search=example";
132
+ //let query = "";
133
+ console.log("query: ", query);
134
+
135
+ chai.request(server)
136
+ .get('/' + savedProject._id + "/kb" + query)
137
+ .auth(email, pwd)
138
+ .end((err, res) => {
139
+ console.log("getall res.body: ", res.body);
140
+ res.should.have.status(200);
141
+ res.body.should.be.a('object');
142
+ res.body.kbs.should.be.a('array');
143
+ expect(res.body.kbs.length).to.equal(3);
144
+ expect(res.body.count).to.equal(3);
145
+ res.body.query.should.be.a('object');
146
+ expect(res.body.query.status).to.equal(-1);
147
+ expect(res.body.query.limit).to.equal(5);
148
+ expect(res.body.query.page).to.equal(0);
149
+ expect(res.body.query.direction).to.equal(-1);
150
+ expect(res.body.query.sortField).to.equal("updatedAt");
151
+ expect(res.body.query.search).to.equal("example");
152
+
153
+ done();
154
+
155
+ })
156
+
157
+ })
158
+ }, 1000)
159
+ })
160
+ }, 1000)
161
+
162
+
163
+ })
164
+ })
165
+ })
166
+ }).timeout(20000)
167
+
76
168
  it('scrapeSingle', (done) => {
77
169
 
78
170
  var email = "test-signup-" + Date.now() + "@email.com";