├── README.md ├── accept.js ├── assignment.js ├── create-task.js ├── enqueue-call.js └── incoming-call.js /README.md: -------------------------------------------------------------------------------- 1 | # How to Build a Basic Call Center with TaskRouter and Twilio Functions 2 | 3 | This is the code repo for a YouTube video showing how to build a basic call center using [TaskRouter](https://twilio.com/taskrouter) and [Twilio Functions](https://twilio.com/functions). Each JavaScript file should be created as a function inside of [Twilio Functions](https://twilio.com/functions). See the [video](https://youtu.be/c_ZlQNitLgE) for details. 4 | 5 | [![How to Build a Basic Call Center with TaskRouter and Twilio Functions](https://www.dropbox.com/s/tpz1yqku3f4lecf/githubtaskrouter.001.jpeg?dl=1)](http://www.youtube.com/watch?v=XMg5ytgyn1E) 6 | 7 | 8 | If you have any questions or run into a problem, please feel free to file an issue. 9 | 10 | Thanks! 11 | 12 | ## Meta 13 | 14 | * No warranty expressed or implied. Software is as is. 15 | * [MIT License](http://www.opensource.org/licenses/mit-license.html) 16 | * Made with ♥ by [Twilio](http://twilio.com) Philly 17 | -------------------------------------------------------------------------------- /accept.js: -------------------------------------------------------------------------------- 1 | exports.handler = function(context, event, callback) { 2 | const client = context.getTwilioClient(); 3 | 4 | client.taskrouter.v1 5 | .workspaces(context.WORKSPACE_SID) 6 | .tasks("** your task SID **") 7 | .reservations("** your reservation SID **") 8 | .update({ 9 | reservationStatus: 'accepted' 10 | }).then((reservation) => { 11 | callback(null, `${reservation.workerName} has accepted the reservation.`); 12 | }); 13 | }; 14 | -------------------------------------------------------------------------------- /assignment.js: -------------------------------------------------------------------------------- 1 | exports.handler = function(context, event, callback) { 2 | console.log(event.ReservationSid); 3 | callback(null, { 4 | 'instruction':'dequeue', 5 | 'post_work_activity_sid':'** your activity SID **', 6 | 'from':'** your call center Twilio phone number **' 7 | }); 8 | }; 9 | -------------------------------------------------------------------------------- /create-task.js: -------------------------------------------------------------------------------- 1 | exports.handler = function(context, event, callback) { 2 | const client = context.getTwilioClient(); 3 | 4 | client.taskrouter.v1 5 | .workspaces(context.WORKSPACE_SID) 6 | .tasks 7 | .create({ 8 | workflowSid: context.WORKFLOW_SID, 9 | attributes: '{"selected_language":"es"}' 10 | }).then(task => { 11 | callback(null, `Created task with SID: ${task.sid}`); 12 | }); 13 | }; 14 | -------------------------------------------------------------------------------- /enqueue-call.js: -------------------------------------------------------------------------------- 1 | exports.handler = function(context, event, callback) { 2 | let twiml = new Twilio.twiml.VoiceResponse(); 3 | 4 | const digit = event.Digits; 5 | 6 | let language = 'en'; 7 | if(digit == '1') { 8 | language = 'es' 9 | } 10 | 11 | twiml.enqueueTask({ 12 | workflowSid: context.WORKFLOW_SID 13 | }).task({}, `{"selected_language":"${language}"}`); 14 | 15 | callback(null, twiml); 16 | }; 17 | -------------------------------------------------------------------------------- /incoming-call.js: -------------------------------------------------------------------------------- 1 | exports.handler = function(context, event, callback) { 2 | let twiml = new Twilio.twiml.VoiceResponse(); 3 | 4 | const gather = twiml.gather({ 5 | numDigits: 1, 6 | timeout: 5, 7 | action: '/enqueue-call' 8 | }); 9 | 10 | gather.say({ 11 | language: 'es' 12 | }, 'Para Español oprime el uno.'); 13 | 14 | gather.say({ 15 | language: 'en' 16 | }, 'For English, please hold or press two.'); 17 | 18 | callback(null, twiml); 19 | }; 20 | --------------------------------------------------------------------------------