-
Notifications
You must be signed in to change notification settings - Fork 4
/
workerStatus.js
52 lines (52 loc) · 1.91 KB
/
workerStatus.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Documentation:
// https://www.twilio.com/docs/taskrouter/api/workspace
// https://www.twilio.com/docs/taskrouter/api/activity
// https://www.twilio.com/docs/taskrouter/api/worker
//
console.log("+++ Start.");
const ACCOUNT_SID = process.env.TR_ACCOUNT_SID;
const ACCOUNT_AUTH_TOKEN = process.env.TR_AUTH_TOKEN;
const client = require('twilio')(ACCOUNT_SID, ACCOUNT_AUTH_TOKEN);
const workspaceSid = process.env.WORKSPACE_SID;
var arrayActivities = [];
client.taskrouter.v1
.workspaces(workspaceSid).activities.list()
.then((activities) => {
// console.log("++ Load workspace activies.");
activities.forEach((activity) => {
// console.log("+ SID: " + activity.sid + " : " + activity.friendlyName);
arrayActivities.push([activity.sid, activity.friendlyName]);
});
workerList();
});
function workerList() {
client.taskrouter.v1
.workspaces(workspaceSid).workers.list()
.then((workers) => {
console.log("++ List worker activity status.");
workers.forEach((worker) => {
workerInfo(worker.sid);
});
});
}
function workerInfo(workerSid) {
client.taskrouter.v1
.workspaces(workspaceSid).workers(workerSid).fetch()
.then(worker => {
var theActivity = "";
for (i = 0; i < arrayActivities.length; i++) {
if (arrayActivities[i][0] === worker.activitySid) {
theActivity = arrayActivities[i][1];
}
}
if (theActivity === "") {
theActivity = worker.activitySid;
}
console.log("+ " + worker.sid
+ " : " + worker.friendlyName
+ " : " + theActivity
);
});
}
//
// eof