diff --git a/controllers/helpers/taskrouter-helper.js b/controllers/helpers/taskrouter-helper.js index 50681cc..2cc7ec0 100644 --- a/controllers/helpers/taskrouter-helper.js +++ b/controllers/helpers/taskrouter-helper.js @@ -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 @@ -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) => { @@ -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, diff --git a/package.json b/package.json index 57b22f8..8ad21c4 100755 --- a/package.json +++ b/package.json @@ -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": [ { @@ -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": {