Skip to content

Commit

Permalink
added context, removed async from package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Damm committed Jul 21, 2020
1 parent f7e1647 commit 492aa9c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 29 deletions.
37 changes: 14 additions & 23 deletions controllers/helpers/taskrouter-helper.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
const twilio = require('twilio');
const context = require('../../context');

const TaskRouterCapability = twilio.jwt.taskrouter.TaskRouterCapability;

const client = twilio(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN);

module.exports.createTask = function (workflowSid, attributes) {
attributes = attributes || {};
module.exports.createTask = async (attributes = {}) => {
const configuration = context.get().configuration;

const data = {
workflowSid: workflowSid,
const payload = {
workflowSid: configuration.twilio.workflowSid,
attributes: JSON.stringify(attributes),
timeout: 3600,
taskChannel: 'voice'
};

return client.taskrouter.workspaces(process.env.TWILIO_WORKSPACE_SID).tasks.create(data);
return client.taskrouter.workspaces(process.env.TWILIO_WORKSPACE_SID).tasks.create(payload);
};

module.exports.findWorker = function (friendlyName) {
module.exports.findWorker = (friendlyName) => {
const filter = { friendlyName: friendlyName };

return client.taskrouter
Expand All @@ -26,22 +27,12 @@ module.exports.findWorker = function (friendlyName) {
.then((workers) => workers[0]);
};

module.exports.getOngoingTasks = function (name) {
return new Promise(function (resolve, reject) {
let query = {};
query.assignmentStatus = 'pending,assigned,reserved';
query.evaluateTaskAttributes = "name='" + name + "'";

client.taskrouter
.workspaces(process.env.TWILIO_WORKSPACE_SID)
.tasks.list(query)
.then((tasks) => {
return resolve(tasks);
})
.catch((error) => {
return reject(error);
});
});
module.exports.getOngoingTasks = (name) => {
let query = {};
query.assignmentStatus = 'pending,assigned,reserved';
query.evaluateTaskAttributes = "name='" + name + "'";

return client.taskrouter.workspaces(process.env.TWILIO_WORKSPACE_SID).tasks.list(query);
};

const buildWorkspacePolicy = (options) => {
Expand All @@ -62,7 +53,7 @@ const buildWorkspacePolicy = (options) => {
});
};

module.exports.createWorkerCapabilityToken = function (sid) {
module.exports.createWorkerCapabilityToken = (sid) => {
const workerCapability = new TaskRouterCapability({
accountSid: process.env.TWILIO_ACCOUNT_SID,
authToken: process.env.TWILIO_AUTH_TOKEN,
Expand Down
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "twilio-contact-center",
"description": "A simple omni channel contact center using Twilio WebRTC Client, Video, SMS, Chat and Taskrouter",
"version": "1.12.0",
"version": "1.13.0",
"author": "Matthias Damm",
"contributors": [
{
Expand All @@ -24,22 +24,21 @@
"WebRTC",
"NodeJS",
"node",
"heroku",
"contact center",
"contact centre"
],
"dependencies": {
"async": "^2.6.3",
"@google-cloud/datastore": "^5.0.6",
"body-parser": "^1.19.0",
"compression": "^1.7.3",
"express": "^4.17.1",
"express-session": "^1.17.0",
"pg": "^7.17.0",
"twilio": "^3.39.1"
"express-session": "^1.17.1",
"pg": "^7.18.2",
"twilio": "^3.43.1"
},
"devDependencies": {
"babel-eslint": "^10.1.0",
"dotenv": "^8.2.0",
"eslint": "^6.8.0"
},
"engines": {
Expand Down

0 comments on commit 492aa9c

Please sign in to comment.