Skip to content

Instantly share code, notes, and snippets.

@choppen5
Last active September 23, 2020 17:06
Show Gist options
  • Save choppen5/a276a0977f6ad26f48c320e5933baf1b to your computer and use it in GitHub Desktop.
Save choppen5/a276a0977f6ad26f48c320e5933baf1b to your computer and use it in GitHub Desktop.
//uses async function so we can... await
exports.handler = async function(context, event, callback) {
const client = context.getTwilioClient();
const taskSid = event.taskSid;
const rejectedWorkerSid = event.workerSid;
const workspaceSid = context.WORKSPACESID; //WS....
console.log("workspaceSid", workspaceSid);
const response = new Twilio.Response();
response.appendHeader('Access-Control-Allow-Origin', '*');
response.appendHeader('Access-Control-Allow-Methods', 'OPTIONS GET');
response.appendHeader('Content-Type', 'application/json');
response.appendHeader('Access-Control-Allow-Headers', 'Content-Type');
console.log(`fetching taskSid ${taskSid}`);
let originalTask = await client.taskrouter
.workspaces(workspaceSid)
.tasks(taskSid)
.fetch();
let newAttributes = JSON.parse(originalTask.attributes);
newAttributes['rejectedWorkerSid'] = rejectedWorkerSid;
await client.taskrouter
.workspaces(workspaceSid)
.tasks(taskSid)
.update({
attributes: JSON.stringify(newAttributes),
});
console.log(`updated task sid`);
callback(null, response)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment