-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API keys instead of AccountSid/AuthToken#
- Loading branch information
Matthias Damm
committed
Feb 14, 2020
1 parent
9bdf628
commit 8d3f977
Showing
1 changed file
with
33 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,38 @@ | ||
const twilio = require('twilio') | ||
|
||
const client = twilio( | ||
process.env.TWILIO_ACCOUNT_SID, | ||
process.env.TWILIO_AUTH_TOKEN) | ||
|
||
module.exports.getWorkspace = function (req, res) { | ||
|
||
client.taskrouter.workspaces(process.env.TWILIO_WORKSPACE_SID).fetch() | ||
.then(workspace => { | ||
let payload = { | ||
const twilio = require('twilio'); | ||
|
||
const client = twilio(process.env.TWILIO_API_KEY_SID, process.env.TWILIO_API_KEY_SECRET, { | ||
accountSid: process.env.TWILIO_ACCOUNT_SID | ||
}); | ||
|
||
module.exports.getWorkspace = function(req, res) { | ||
client.taskrouter | ||
.workspaces(process.env.TWILIO_WORKSPACE_SID) | ||
.fetch() | ||
.then((workspace) => { | ||
const payload = { | ||
sid: workspace.sid, | ||
friendlyName: workspace.friendlyName | ||
} | ||
}; | ||
|
||
res.status(200).json(payload) | ||
}).catch(error => { | ||
res.status(500).send(res.convertErrorToJSON(error)) | ||
res.status(200).json(payload); | ||
}) | ||
|
||
} | ||
|
||
module.exports.getActivities = function (req, res) { | ||
|
||
client.taskrouter.workspaces(process.env.TWILIO_WORKSPACE_SID).activities.list() | ||
.then(activities => { | ||
let payload =[] | ||
|
||
for (let i = 0; i < activities.length; i++) { | ||
const activity = { | ||
sid: activities[i].sid, | ||
friendlyName: activities[i].friendlyName, | ||
} | ||
|
||
payload.push(activity) | ||
} | ||
|
||
res.status(200).json(payload) | ||
}).catch(error => { | ||
res.status(500).send(res.convertErrorToJSON(error)) | ||
.catch((error) => { | ||
res.status(500).send(res.convertErrorToJSON(error)); | ||
}); | ||
}; | ||
|
||
module.exports.getActivities = function(req, res) { | ||
client.taskrouter | ||
.workspaces(process.env.TWILIO_WORKSPACE_SID) | ||
.activities.list() | ||
.then((activities) => { | ||
const payload = activities.map((activity) => { | ||
return { sid: activity.sid, friendlyName: activity.friendlyName }; | ||
}); | ||
|
||
res.status(200).json(payload); | ||
}) | ||
|
||
} | ||
.catch((error) => { | ||
res.status(500).send(res.convertErrorToJSON(error)); | ||
}); | ||
}; |