@tiledesk/tiledesk-server 2.19.14 → 2.19.16

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/CHANGELOG.md CHANGED
@@ -5,6 +5,13 @@
5
5
  🚀 IN PRODUCTION 🚀
6
6
  (https://www.npmjs.com/package/@tiledesk/tiledesk-server/v/2.3.77)
7
7
 
8
+ # 2.19.16
9
+ - Queued /kb/scrape/single via scheduleScrape instead of sync startScrape
10
+ - Improved guest closure event handling in activity monitoring
11
+
12
+ # 2.19.15
13
+ - Fixed bug on updating cells in a table row
14
+
8
15
  # 2.19.14
9
16
  - Improved Activities management
10
17
 
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.19.14",
4
+ "version": "2.19.16",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
@@ -103,6 +103,49 @@ function userIdFromEntity(entity) {
103
103
  return null;
104
104
  }
105
105
 
106
+ // Human agents assigned to a request target (e.g. REQUEST_CLOSE when a guest closes).
107
+ // Without this, involvedUserIds would only contain closed_by / actor and miss the assignee,
108
+ // so ?agent_id= filters would not return the activity for the assigned operator.
109
+ function agentIdsFromRequestTarget(target) {
110
+ if (!target || !target.object) {
111
+ return [];
112
+ }
113
+ var ids = [];
114
+ var seen = {};
115
+ function addId(raw) {
116
+ if (raw == null) {
117
+ return;
118
+ }
119
+ var id = String(raw);
120
+ if (!id || id.indexOf('bot_') === 0 || seen[id]) {
121
+ return;
122
+ }
123
+ seen[id] = true;
124
+ ids.push(id);
125
+ }
126
+
127
+ var participantsAgents = target.object.participantsAgents;
128
+ if (Array.isArray(participantsAgents)) {
129
+ for (var i = 0; i < participantsAgents.length; i++) {
130
+ addId(participantsAgents[i]);
131
+ }
132
+ }
133
+
134
+ // Fallback when only the populated virtual is present on the serialized request
135
+ var participatingAgents = target.object.participatingAgents;
136
+ if (Array.isArray(participatingAgents)) {
137
+ for (var j = 0; j < participatingAgents.length; j++) {
138
+ var agent = participatingAgents[j];
139
+ if (!agent) {
140
+ continue;
141
+ }
142
+ addId(agent._id || agent.id || agent);
143
+ }
144
+ }
145
+
146
+ return ids;
147
+ }
148
+
106
149
  function computeInvolvedUserIds(doc) {
107
150
  var ids = new Set();
108
151
  if (doc.actor && doc.actor.type === 'user' && doc.actor.id) {
@@ -116,6 +159,9 @@ function computeInvolvedUserIds(doc) {
116
159
  if (relatedUserId) {
117
160
  ids.add(relatedUserId);
118
161
  }
162
+ agentIdsFromRequestTarget(doc.target).forEach(function (id) {
163
+ ids.add(id);
164
+ });
119
165
  return Array.from(ids);
120
166
  }
121
167
 
@@ -147,7 +193,8 @@ var ActivitySchema = new Schema({
147
193
  type: RelatedActivitySchema,
148
194
  required: false
149
195
  },
150
- // Denormalized list of user ids involved in the activity (actor, target user, related user).
196
+ // Denormalized list of user ids involved in the activity
197
+ // (actor, target user, related user, and request participantsAgents when target is a request).
151
198
  // Auto-filled by the pre-save hook below. Indexed for efficient "activities of a user" queries.
152
199
  involvedUserIds: {
153
200
  type: [String],
@@ -86,7 +86,7 @@ router.get('/', async (req, res) => {
86
86
  }
87
87
 
88
88
  if (req.query.agent_id) {
89
- // involvedUserIds covers actor, target user and related user for new records.
89
+ // involvedUserIds covers actor, target user, related user and request participantsAgents.
90
90
  // The other two clauses keep backward compatibility with legacy records.
91
91
  query["$or"] = [
92
92
  { "involvedUserIds": req.query.agent_id },
package/routes/kb.js CHANGED
@@ -270,18 +270,14 @@ router.post('/scrape/single', async (req, res) => {
270
270
  winston.verbose("/scrape/single json: ", json);
271
271
 
272
272
  json.id_project = project_id;
273
+ json.webhook = apiUrl + '/webhook/kb/status?token=' + KB_WEBHOOK_TOKEN;
273
274
 
274
275
  if (process.env.NODE_ENV === "test") {
275
- res.status(200).send({ success: true, message: "Skip indexing in test environment", data: json })
276
+ return res.status(200).send({ success: true, message: "Skip indexing in test environment", data: json })
276
277
  }
277
278
 
278
- aiManager.startScrape(json).then((response) => {
279
- winston.verbose("startScrape response: ", response);
280
- res.status(200).send(response);
281
- }).catch((err) => {
282
- winston.error("startScrape err: ", err);
283
- res.status(500).send({ success: false, error: err });
284
- })
279
+ aiManager.scheduleScrape([json], namespace.hybrid);
280
+ return res.status(200).send({ success: true, message: "Content queued for reindexing" });
285
281
 
286
282
  }
287
283
  })
@@ -224,7 +224,7 @@ function validateRowData(data, schema) {
224
224
  const col = schema[j];
225
225
  if (!Object.prototype.hasOwnProperty.call(data, col.name)) continue;
226
226
  const raw = data[col.name];
227
- if (raw === null || raw === undefined) continue;
227
+ if (raw === undefined) continue;
228
228
  result[col.name] = coerceValue(raw, col);
229
229
  }
230
230
  return result;