Last active
September 23, 2020 17:06
-
-
Save choppen5/a276a0977f6ad26f48c320e5933baf1b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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