Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment wrapping and completing task assignment for chat tasks #722

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
25 changes: 23 additions & 2 deletions functions/completeTaskAssignment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
success,
functionValidator as TokenValidator,
} from '@tech-matters/serverless-helpers';
import { set } from 'lodash';

Check failure on line 28 in functions/completeTaskAssignment.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'set' is defined but never used

type EnvVars = {
TWILIO_WORKSPACE_SID: string;
Expand Down Expand Up @@ -70,10 +71,30 @@
.workspaces(context.TWILIO_WORKSPACE_SID)
.tasks(event.taskSid)
.fetch();
const attributes = JSON.parse(task.attributes);
const callSid = attributes?.call_sid;
// const conversationSid = attributes?.conversation_sid;

await task.update({ attributes: event.finalTaskAttributes });
// Ends the task for the worker and client for chat tasks, and only for the worker for voice tasks
await task.update({
assignmentStatus: 'wrapping',
attributes: event.finalTaskAttributes,
});

const completedTask = await task.update({ assignmentStatus: 'completed' });
const aftertask = await client.taskrouter
.workspaces(context.TWILIO_WORKSPACE_SID)
.tasks(event.taskSid)
.fetch();
console.log(`Task ${aftertask} with attributes ${aftertask.attributes} has been completed`);

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

// eslint-disable-next-line no-promise-executor-return
await new Promise((resolve) => setTimeout(resolve, 10000)); // Wait for 10 seconds

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

return { type: 'success', completedTask } as const;
} catch (err) {
Expand Down
Loading