Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Love Code
Added: Dec 19, 2018 2:56 AM
Views: 18
Tags: no tags
Twilio Function to update Task status in Flex TaskRouter
  1. exports.handler = function(context, event, callback) {
  2.    
  3.     const client = context.getTwilioClient();
  4.     const response = new Twilio.Response();
  5.     const workSpaceSid = 'your  TR workspace SID'
  6.     const taskSid = event.taskSid;
  7.     console.log('task Sid is ' + taskSid);
  8.    
  9.     response.appendHeader('Access-Control-Allow-Origin', '*');
  10.     response.appendHeader('Access-Control-Allow-Methods', 'OPTIONS POST');
  11.     response.appendHeader('Content-Type', 'application/json');
  12.     response.appendHeader('Access-Control-Allow-Headers', 'Content-Type');
  13.    
  14.     client.taskrouter.workspaces(workSpaceSid)
  15.                  .tasks(taskSid)
  16.                  .update({
  17.                     assignmentStatus: 'canceled',
  18.                     reason: 'sent to non-flex agent'
  19.                   }, function(err, result) {
  20.                       callback();
  21.                   });
  22. };