@tiledesk/tiledesk-server 2.5.1 → 2.5.3

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,14 @@
5
5
  🚀 IN PRODUCTION 🚀
6
6
  (https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77)
7
7
 
8
+ # 2.5.3
9
+ - Updated whatsapp-connector to 0.1.64
10
+
11
+ # 2.5.2
12
+ - Updated messenger-connector to 0.1.18
13
+ - Bug fix: kbs createdAt wrongly generated
14
+ - Added advanced search for kbs
15
+
8
16
  # 2.5.1
9
17
  - Bug fix: reset busy status for agents when smart assignment is enabled
10
18
  - Added possibility to delete chat21 conversation
@@ -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.1",
4
+ "version": "2.5.3",
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.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
48
  "@tiledesk/tiledesk-tybot-connector": "^0.2.56",
49
- "@tiledesk/tiledesk-whatsapp-connector": "^0.1.63",
49
+ "@tiledesk/tiledesk-whatsapp-connector": "^0.1.64",
50
50
  "@tiledesk/tiledesk-whatsapp-jobworker": "^0.0.7",
51
51
  "@tiledesk/tiledesk-chatbot-templates": "^0.1.2",
52
52
  "@tiledesk/tiledesk-client": "^0.10.10",
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) => {
@@ -195,7 +195,7 @@ router.post('/', [passport.authenticate(['basic', 'jwt'], { session: false }), v
195
195
  uuid_user: uuidv4(),
196
196
  // role: RoleConstants.USER,
197
197
  // - Create project_user endpoint by agent (Ticketing) now is with Guest Role
198
- role: RoleConstants.GUEST,
198
+ role: RoleConstants.GUEST,
199
199
  user_available: false,
200
200
  tags: req.body.tags,
201
201
  createdBy: req.user.id,
@@ -228,6 +228,11 @@ router.put('/', [passport.authenticate(['basic', 'jwt'], { session: false }), va
228
228
  if (req.body.max_assigned_chat!=undefined) {
229
229
  update.max_assigned_chat = req.body.max_assigned_chat;
230
230
  }
231
+
232
+ if (req.body.number_assigned_requests!=undefined) {
233
+ update.number_assigned_requests = req.body.number_assigned_requests;
234
+ }
235
+
231
236
  if (req.body.attributes!=undefined) {
232
237
  update.attributes = req.body.attributes;
233
238
  }
@@ -287,6 +292,10 @@ router.put('/:project_userid', [passport.authenticate(['basic', 'jwt'], { sessio
287
292
  update.max_assigned_chat = req.body.max_assigned_chat;
288
293
  }
289
294
 
295
+ if (req.body.number_assigned_requests!=undefined) {
296
+ update.number_assigned_requests = req.body.number_assigned_requests;
297
+ }
298
+
290
299
  if (req.body.attributes!=undefined) {
291
300
  update.attributes = req.body.attributes;
292
301
  }
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";