@tiledesk/tiledesk-tybot-connector 0.2.94 → 0.2.95
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
package/package.json
CHANGED
|
@@ -74,25 +74,13 @@ class DirIfOnlineAgentsV2 {
|
|
|
74
74
|
|
|
75
75
|
let agents;
|
|
76
76
|
if (selectedOption === "currentDep") {
|
|
77
|
-
console.log("(DirIfOnlineAgents) currentDep");
|
|
78
|
-
// let departmentId;
|
|
77
|
+
if (this.log) {console.log("(DirIfOnlineAgents) currentDep"); }
|
|
79
78
|
let departmentId = await this.chatbot.getParameter("department_id");
|
|
80
|
-
console.log("this.context.departmentId:", departmentId);
|
|
81
|
-
|
|
82
|
-
// if (this.context.tdcache) {
|
|
83
|
-
// let attributes =
|
|
84
|
-
// await TiledeskChatbot.allParametersStatic(
|
|
85
|
-
// this.context.tdcache, this.context.requestId
|
|
86
|
-
// );
|
|
87
|
-
// if (this.log) {console.log("Attributes:::", JSON.stringify(attributes))}
|
|
88
|
-
// departmentId = attributes["department_id"];
|
|
89
|
-
// if (this.log) {console.log("Attributes.departmentId:::", departmentId)}
|
|
90
|
-
// }
|
|
79
|
+
if (this.log) {console.log("this.context.departmentId:", departmentId);}
|
|
91
80
|
|
|
92
81
|
if (departmentId) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
agents = await this.getDepartmentAvailableAgents(departmentId);
|
|
82
|
+
if (this.log) {console.log("(DirIfOnlineAgents) agents = await this.getProjectAvailableAgents(", departmentId, ", true);"); }
|
|
83
|
+
agents = await this.getProjectAvailableAgents(departmentId, true);
|
|
96
84
|
if (this.log) {console.log("(DirIfOnlineAgents) agents:", agents); }
|
|
97
85
|
} else {
|
|
98
86
|
console.error("(DirIfOnlineAgents) no departmentId found in attributes");
|
|
@@ -113,12 +101,14 @@ class DirIfOnlineAgentsV2 {
|
|
|
113
101
|
}
|
|
114
102
|
else if (selectedOption === "selectedDep") {
|
|
115
103
|
if (this.log) {console.log("(DirIfOnlineAgents) selectedOption === selectedDep", action.selectedDepartmentId); }
|
|
116
|
-
agents = await this.
|
|
104
|
+
if (this.log) {console.log("(DirIfOnlineAgents) agents = await this.getProjectAvailableAgents(", action.selectedDepartmentId, ", true);"); }
|
|
105
|
+
|
|
106
|
+
agents = await this.getProjectAvailableAgents(action.selectedDepartmentId, true);
|
|
117
107
|
if (this.log) {console.log("(DirIfOnlineAgents) agents:", agents); }
|
|
118
108
|
}
|
|
119
109
|
else { // if (checkAll) => go project-wide
|
|
120
|
-
if (this.log) {console.log("(DirIfOnlineAgents) selectedOption === all"); }
|
|
121
|
-
agents = await this.getProjectAvailableAgents(true);
|
|
110
|
+
if (this.log) {console.log("(DirIfOnlineAgents) selectedOption === all | getProjectAvailableAgents(null, true)"); }
|
|
111
|
+
agents = await this.getProjectAvailableAgents(null, true);
|
|
122
112
|
if (this.log) {console.log("(DirIfOnlineAgents) agents:", agents); }
|
|
123
113
|
}
|
|
124
114
|
|
|
@@ -152,8 +142,7 @@ class DirIfOnlineAgentsV2 {
|
|
|
152
142
|
} else {
|
|
153
143
|
if (falseIntent) {
|
|
154
144
|
let intentDirective = DirIntent.intentDirectiveFor(falseIntent, falseIntentAttributes);
|
|
155
|
-
if (this.log) {console.log("!agents (!openHours) => falseIntent");}
|
|
156
|
-
console.log("!agents (!openHours) => falseIntent BECAUSE CLOSED"); //PROD
|
|
145
|
+
if (this.log) { console.log("!agents (!openHours) => falseIntent"); }
|
|
157
146
|
this.intentDir.execute(intentDirective, () => {
|
|
158
147
|
callback();
|
|
159
148
|
});
|
|
@@ -184,9 +173,12 @@ class DirIfOnlineAgentsV2 {
|
|
|
184
173
|
});
|
|
185
174
|
}
|
|
186
175
|
|
|
187
|
-
async getProjectAvailableAgents(raw, callback) {
|
|
176
|
+
async getProjectAvailableAgents(departmentId, raw, callback) {
|
|
188
177
|
return new Promise( (resolve, reject) => {
|
|
189
|
-
|
|
178
|
+
let URL = `${this.context.TILEDESK_APIURL}/projects/${this.context.projectId}/users/availables?raw=${raw}`
|
|
179
|
+
if (departmentId) {
|
|
180
|
+
URL = URL + `&department=${departmentId}`
|
|
181
|
+
}
|
|
190
182
|
const HTTPREQUEST = {
|
|
191
183
|
url: URL,
|
|
192
184
|
headers: {
|
|
@@ -216,112 +208,99 @@ class DirIfOnlineAgentsV2 {
|
|
|
216
208
|
|
|
217
209
|
}
|
|
218
210
|
|
|
219
|
-
// async
|
|
211
|
+
// async getDepartmentAvailableAgents(depId) {
|
|
220
212
|
// return new Promise( (resolve, reject) => {
|
|
221
|
-
// this.tdclient.
|
|
222
|
-
// if (
|
|
223
|
-
// reject(
|
|
213
|
+
// this.tdclient.getDepartment(depId, async (error, dep) => {
|
|
214
|
+
// if (error) {
|
|
215
|
+
// reject(error);
|
|
224
216
|
// }
|
|
225
217
|
// else {
|
|
226
|
-
//
|
|
218
|
+
// if (this.log) {console.log("(DirIfOnlineAgents) got department:", JSON.stringify(dep)); }
|
|
219
|
+
// const groupId = dep.id_group;
|
|
220
|
+
// if (this.log) {console.log("(DirIfOnlineAgents) department.groupId:", groupId); }
|
|
221
|
+
// try {
|
|
222
|
+
// if (groupId) {
|
|
223
|
+
// const group = await this.getGroup(groupId);
|
|
224
|
+
// if (this.log) { console.log("(DirIfOnlineAgents) got group info:", group); }
|
|
225
|
+
// if (group) {
|
|
226
|
+
// if (group.members) {
|
|
227
|
+
// if (this.log) { console.log("(DirIfOnlineAgents) group members ids:", group.members);}
|
|
228
|
+
// // let group_members = await getTeammates(group.members);
|
|
229
|
+
// // console.log("group members details:", group_members);
|
|
230
|
+
// let all_teammates = await this.getAllTeammates();
|
|
231
|
+
// if (this.log) { console.log("(DirIfOnlineAgents) all teammates:", all_teammates); }
|
|
232
|
+
// if (all_teammates && all_teammates.length > 0){
|
|
233
|
+
// // [
|
|
234
|
+
// // {
|
|
235
|
+
// // "user_available": false,
|
|
236
|
+
// // ...
|
|
237
|
+
// // "id_user": {
|
|
238
|
+
// // "status": 100,
|
|
239
|
+
// // "email": "michele@tiledesk.com",
|
|
240
|
+
// // "firstname": "Michele",
|
|
241
|
+
// // "lastname": "Pomposo",
|
|
242
|
+
// // ...
|
|
243
|
+
// // },
|
|
244
|
+
// // "role": "admin",
|
|
245
|
+
// // "tags": [],
|
|
246
|
+
// // "presence": {
|
|
247
|
+
// // "status": "offline",
|
|
248
|
+
// // "changedAt": "2023-11-16T12:37:31.990Z"
|
|
249
|
+
// // },
|
|
250
|
+
// // "isBusy": false
|
|
251
|
+
// // }, ... ]
|
|
252
|
+
// // filter on availability
|
|
253
|
+
// console.log("(DirIfOnlineAgents) filtering available agents for group:", groupId);
|
|
254
|
+
// let available_agents = [];
|
|
255
|
+
// all_teammates.forEach((agent) => {
|
|
256
|
+
// if (this.log) { console.log("Checking teammate:", agent.id_user._id, "(", agent.id_user.email ,") Available:", agent.user_available, ") with members:",group.members ); }
|
|
257
|
+
// if (agent.user_available === true && group.members.includes(agent.id_user._id)) {
|
|
258
|
+
// console.log("Adding teammate:", agent.id_user._id);
|
|
259
|
+
// available_agents.push(agent);
|
|
260
|
+
// }
|
|
261
|
+
// });
|
|
262
|
+
// if (this.log) { console.log("(DirIfOnlineAgents) available agents in group:", available_agents); }
|
|
263
|
+
// resolve(available_agents);
|
|
264
|
+
// }
|
|
265
|
+
// }
|
|
266
|
+
// else {
|
|
267
|
+
// this.chatbot.addParameter("flowError", "(If online Agents) Empty group:" + groupId);
|
|
268
|
+
// resolve([]);
|
|
269
|
+
// }
|
|
270
|
+
// }
|
|
271
|
+
// else {
|
|
272
|
+
// this.chatbot.addParameter("flowError", "(If online Agents) Error: no group for groupId:" + groupId);
|
|
273
|
+
// resolve([]);
|
|
274
|
+
// }
|
|
275
|
+
// }
|
|
276
|
+
// else {
|
|
277
|
+
// // no group => assigned to all teammates
|
|
278
|
+
// const agents = await this.getProjectAvailableAgents(true);
|
|
279
|
+
// resolve(agents);
|
|
280
|
+
// }
|
|
281
|
+
// }
|
|
282
|
+
// catch(error) {
|
|
283
|
+
// console.error("(DirIfOnlineAgents) Error:", error);
|
|
284
|
+
// reject(error);
|
|
285
|
+
// }
|
|
227
286
|
// }
|
|
228
287
|
// });
|
|
229
|
-
// })
|
|
288
|
+
// });
|
|
230
289
|
// }
|
|
231
290
|
|
|
232
|
-
async getDepartmentAvailableAgents(depId) {
|
|
233
|
-
return new Promise( (resolve, reject) => {
|
|
234
|
-
this.tdclient.getDepartment(depId, async (error, dep) => {
|
|
235
|
-
if (error) {
|
|
236
|
-
reject(error);
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
-
if (this.log) {console.log("(DirIfOnlineAgents) got department:", JSON.stringify(dep)); }
|
|
240
|
-
const groupId = dep.id_group;
|
|
241
|
-
if (this.log) {console.log("(DirIfOnlineAgents) department.groupId:", groupId); }
|
|
242
|
-
try {
|
|
243
|
-
if (groupId) {
|
|
244
|
-
const group = await this.getGroup(groupId);
|
|
245
|
-
if (this.log) { console.log("(DirIfOnlineAgents) got group info:", group); }
|
|
246
|
-
if (group) {
|
|
247
|
-
if (group.members) {
|
|
248
|
-
if (this.log) { console.log("(DirIfOnlineAgents) group members ids:", group.members);}
|
|
249
|
-
// let group_members = await getTeammates(group.members);
|
|
250
|
-
// console.log("group members details:", group_members);
|
|
251
|
-
let all_teammates = await this.getAllTeammates();
|
|
252
|
-
if (this.log) { console.log("(DirIfOnlineAgents) all teammates:", all_teammates); }
|
|
253
|
-
if (all_teammates && all_teammates.length > 0){
|
|
254
|
-
// [
|
|
255
|
-
// {
|
|
256
|
-
// "user_available": false,
|
|
257
|
-
// ...
|
|
258
|
-
// "id_user": {
|
|
259
|
-
// "status": 100,
|
|
260
|
-
// "email": "michele@tiledesk.com",
|
|
261
|
-
// "firstname": "Michele",
|
|
262
|
-
// "lastname": "Pomposo",
|
|
263
|
-
// ...
|
|
264
|
-
// },
|
|
265
|
-
// "role": "admin",
|
|
266
|
-
// "tags": [],
|
|
267
|
-
// "presence": {
|
|
268
|
-
// "status": "offline",
|
|
269
|
-
// "changedAt": "2023-11-16T12:37:31.990Z"
|
|
270
|
-
// },
|
|
271
|
-
// "isBusy": false
|
|
272
|
-
// }, ... ]
|
|
273
|
-
// filter on availability
|
|
274
|
-
console.log("(DirIfOnlineAgents) filtering available agents for group:", groupId);
|
|
275
|
-
let available_agents = [];
|
|
276
|
-
all_teammates.forEach((agent) => {
|
|
277
|
-
if (this.log) { console.log("Checking teammate:", agent.id_user._id, "(", agent.id_user.email ,") Available:", agent.user_available, ") with members:",group.members ); }
|
|
278
|
-
if (agent.user_available === true && group.members.includes(agent.id_user._id)) {
|
|
279
|
-
console.log("Adding teammate:", agent.id_user._id);
|
|
280
|
-
available_agents.push(agent);
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
if (this.log) { console.log("(DirIfOnlineAgents) available agents in group:", available_agents); }
|
|
284
|
-
resolve(available_agents);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
this.chatbot.addParameter("flowError", "(If online Agents) Empty group:" + groupId);
|
|
289
|
-
resolve([]);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
else {
|
|
293
|
-
this.chatbot.addParameter("flowError", "(If online Agents) Error: no group for groupId:" + groupId);
|
|
294
|
-
resolve([]);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
else {
|
|
298
|
-
// no group => assigned to all teammates
|
|
299
|
-
const agents = await this.getProjectAvailableAgents(true);
|
|
300
|
-
resolve(agents);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
catch(error) {
|
|
304
|
-
console.error("(DirIfOnlineAgents) Error:", error);
|
|
305
|
-
reject(error);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
|
|
312
291
|
// async getGroup(groupId, callback) {
|
|
313
292
|
// return new Promise ( (resolve, reject) => {
|
|
314
|
-
// const URL = `${this.
|
|
293
|
+
// const URL = `${this.context.TILEDESK_APIURL}/${this.context.projectId}/groups/${groupId}`
|
|
315
294
|
// const HTTPREQUEST = {
|
|
316
295
|
// url: URL,
|
|
317
296
|
// headers: {
|
|
318
297
|
// 'Content-Type' : 'application/json',
|
|
319
|
-
// 'Authorization': this.context.token
|
|
298
|
+
// 'Authorization': this.fixToken(this.context.token)
|
|
320
299
|
// },
|
|
321
300
|
// method: 'GET',
|
|
322
301
|
// httpsOptions: this.httpsOptions
|
|
323
302
|
// };
|
|
324
|
-
//
|
|
303
|
+
// this.#myrequest(
|
|
325
304
|
// HTTPREQUEST,
|
|
326
305
|
// function(err, resbody) {
|
|
327
306
|
// if (err) {
|
|
@@ -331,6 +310,20 @@ class DirIfOnlineAgentsV2 {
|
|
|
331
310
|
// }
|
|
332
311
|
// }
|
|
333
312
|
// else {
|
|
313
|
+
// // {
|
|
314
|
+
// // "members": [
|
|
315
|
+
// // "62b317986993970035f0697e",
|
|
316
|
+
// // "5aaa99024c3b110014b478f0"
|
|
317
|
+
// // ],
|
|
318
|
+
// // "_id": "65ddec23fd8dc3003295cdd7",
|
|
319
|
+
// // "name": "Sales",
|
|
320
|
+
// // "trashed": false,
|
|
321
|
+
// // "id_project": "65203e12f8c0cf002cf4110b",
|
|
322
|
+
// // "createdBy": "5e09d16d4d36110017506d7f",
|
|
323
|
+
// // "createdAt": "2024-02-27T14:05:23.373Z",
|
|
324
|
+
// // "updatedAt": "2024-02-27T14:05:29.137Z",
|
|
325
|
+
// // "__v": 0
|
|
326
|
+
// // }
|
|
334
327
|
// resolve(resbody);
|
|
335
328
|
// if (callback) {
|
|
336
329
|
// callback(null, resbody);
|
|
@@ -341,97 +334,51 @@ class DirIfOnlineAgentsV2 {
|
|
|
341
334
|
// });
|
|
342
335
|
// }
|
|
343
336
|
|
|
344
|
-
async
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
async getAllTeammates(members, callback) {
|
|
391
|
-
return new Promise ( (resolve, reject) => {
|
|
392
|
-
const URL = `${this.context.TILEDESK_APIURL}/${this.context.projectId}/project_users`
|
|
393
|
-
const HTTPREQUEST = {
|
|
394
|
-
url: URL,
|
|
395
|
-
headers: {
|
|
396
|
-
'Content-Type' : 'application/json',
|
|
397
|
-
'Authorization': this.fixToken(this.context.token)
|
|
398
|
-
},
|
|
399
|
-
method: 'GET',
|
|
400
|
-
httpsOptions: this.httpsOptions
|
|
401
|
-
};
|
|
402
|
-
this.#myrequest(
|
|
403
|
-
HTTPREQUEST,
|
|
404
|
-
function(err, resbody) {
|
|
405
|
-
if (err) {
|
|
406
|
-
reject(err);
|
|
407
|
-
if (callback) {
|
|
408
|
-
callback(err);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
else {
|
|
412
|
-
// {
|
|
413
|
-
// "members": [
|
|
414
|
-
// "62b317986993970035f0697e",
|
|
415
|
-
// "5aaa99024c3b110014b478f0"
|
|
416
|
-
// ],
|
|
417
|
-
// "_id": "65ddec23fd8dc3003295cdd7",
|
|
418
|
-
// "name": "Sales",
|
|
419
|
-
// "trashed": false,
|
|
420
|
-
// "id_project": "65203e12f8c0cf002cf4110b",
|
|
421
|
-
// "createdBy": "5e09d16d4d36110017506d7f",
|
|
422
|
-
// "createdAt": "2024-02-27T14:05:23.373Z",
|
|
423
|
-
// "updatedAt": "2024-02-27T14:05:29.137Z",
|
|
424
|
-
// "__v": 0
|
|
425
|
-
// }
|
|
426
|
-
resolve(resbody);
|
|
427
|
-
if (callback) {
|
|
428
|
-
callback(null, resbody);
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
}, this.log
|
|
432
|
-
);
|
|
433
|
-
});
|
|
434
|
-
}
|
|
337
|
+
// async getAllTeammates(members, callback) {
|
|
338
|
+
// return new Promise ( (resolve, reject) => {
|
|
339
|
+
// const URL = `${this.context.TILEDESK_APIURL}/${this.context.projectId}/project_users`
|
|
340
|
+
// const HTTPREQUEST = {
|
|
341
|
+
// url: URL,
|
|
342
|
+
// headers: {
|
|
343
|
+
// 'Content-Type' : 'application/json',
|
|
344
|
+
// 'Authorization': this.fixToken(this.context.token)
|
|
345
|
+
// },
|
|
346
|
+
// method: 'GET',
|
|
347
|
+
// httpsOptions: this.httpsOptions
|
|
348
|
+
// };
|
|
349
|
+
// this.#myrequest(
|
|
350
|
+
// HTTPREQUEST,
|
|
351
|
+
// function(err, resbody) {
|
|
352
|
+
// if (err) {
|
|
353
|
+
// reject(err);
|
|
354
|
+
// if (callback) {
|
|
355
|
+
// callback(err);
|
|
356
|
+
// }
|
|
357
|
+
// }
|
|
358
|
+
// else {
|
|
359
|
+
// // {
|
|
360
|
+
// // "members": [
|
|
361
|
+
// // "62b317986993970035f0697e",
|
|
362
|
+
// // "5aaa99024c3b110014b478f0"
|
|
363
|
+
// // ],
|
|
364
|
+
// // "_id": "65ddec23fd8dc3003295cdd7",
|
|
365
|
+
// // "name": "Sales",
|
|
366
|
+
// // "trashed": false,
|
|
367
|
+
// // "id_project": "65203e12f8c0cf002cf4110b",
|
|
368
|
+
// // "createdBy": "5e09d16d4d36110017506d7f",
|
|
369
|
+
// // "createdAt": "2024-02-27T14:05:23.373Z",
|
|
370
|
+
// // "updatedAt": "2024-02-27T14:05:29.137Z",
|
|
371
|
+
// // "__v": 0
|
|
372
|
+
// // }
|
|
373
|
+
// resolve(resbody);
|
|
374
|
+
// if (callback) {
|
|
375
|
+
// callback(null, resbody);
|
|
376
|
+
// }
|
|
377
|
+
// }
|
|
378
|
+
// }, this.log
|
|
379
|
+
// );
|
|
380
|
+
// });
|
|
381
|
+
// }
|
|
435
382
|
|
|
436
383
|
#myrequest(options, callback) {
|
|
437
384
|
if (this.log) {
|