-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlist-workflows.js
31 lines (28 loc) · 1.02 KB
/
list-workflows.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
exports.handler = function(context, event, callback) {
let response = new Twilio.Response()
let jwt = require('jsonwebtoken');
response.appendHeader('Access-Control-Allow-Origin', '*');
response.appendHeader('Access-Control-Allow-Methods', 'OPTIONS POST');
response.appendHeader('Content-Type', 'application/json');
response.appendHeader('Access-Control-Allow-Headers', 'Content-Type');
const token = event.token
const client = context.getTwilioClient()
let myWorkflows = []
jwt.verify(token, context.AUTH_TOKEN, function(err, decoded) {
if (err) {
response.appendHeader('Status', 401)
callback(null, response)
} else {
response.appendHeader('Status', 200)
client.taskrouter
.workspaces(context.TWILIO_WORKSPACE_SID)
.workflows.each((workflow) => {
myWorkflows.push(workflow)
if(myWorkflows.length > 2) {
response.setBody({workflow: myWorkflows})
callback(null, response)
}
});
}
})
};