Skip to content

Commit

Permalink
attempt to end client call
Browse files Browse the repository at this point in the history
  • Loading branch information
mythilytm committed Nov 11, 2024
1 parent df0f090 commit a10501b
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions functions/completeTaskAssignment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,33 @@ const closeTaskAssignment = async (
.tasks(event.taskSid)
.fetch();

console.log(`>>> Task Before: ${task.sid} attributes: ${JSON.stringify(task.attributes)}`);
const attributes = JSON.parse(task.attributes);
const callSid = attributes?.call_sid;

await task.update({ attributes: event.finalTaskAttributes });
const callBefore = await client.calls(callSid).fetch();

const completedTask = await task.update({ assignmentStatus: 'completed' });
console.log(
`>>> Task Before: ${task.sid} attributes: ${JSON.stringify(task.attributes)}`,
{ callSid },
`Call status After: ${callBefore}`,
);

// await task.update({ attributes: event.finalTaskAttributes });

const completedTask = await task.update({
assignmentStatus: 'completed',
attributes: event.finalTaskAttributes,
});

if (callSid) await client.calls(callSid).update({ status: 'completed' });

const callAfter = await client.calls(callSid).fetch();

console.log(
`>>> Task After completing: ${completedTask.sid} attributes: ${JSON.stringify(completedTask.attributes)}`,
`>>> Task After completing: ${completedTask.sid} attributes: ${JSON.stringify(
completedTask.attributes,
)}`,
`Call status After: ${callAfter}`,
);

return { type: 'success', completedTask } as const;
Expand Down

0 comments on commit a10501b

Please sign in to comment.