-
Notifications
You must be signed in to change notification settings - Fork 2
/
initialize-sync.js
46 lines (43 loc) · 1.39 KB
/
initialize-sync.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
exports.handler = function(context, event, callback) {
const response = new Twilio.Response();
response.appendHeader('Access-Control-Allow-Origin', '*');
response.appendHeader('Access-Control-Allow-Methods', 'GET');
response.appendHeader('Content-Type', 'application/json');
response.appendHeader('Access-Control-Allow-Headers', 'Content-Type');
const client = context.getTwilioClient();
const service = client.sync.services(context.TWILIO_SYNC_SERVICE_SID);
service.syncMaps
.create({
uniqueName: 'current_workers',
})
.then(response => {
console.log(response);
client.taskrouter.v1
.workspaces(context.TWILIO_WORKSPACE_SID)
.workers
.list()
.then((workers) => {
workers.forEach((worker) => {
console.log(worker.sid)
service.syncMaps('current_workers')
.syncMapItems.create({
key: worker.sid,
data: {
name: worker.FriendlyName,
activity: worker.Activity,
}
}).then(function(response) {
console.log(response);
}).catch(function(error) {
console.log(error);
});
});
});
})
.catch(error => {
console.log(error);
});
const body = { status: "ok" }
response.setBody(body)
callback(null, response)
}