From df0f090c9332373dd36c412c76efecde6c2c45c8 Mon Sep 17 00:00:00 2001 From: mythilytm Date: Fri, 8 Nov 2024 18:54:11 -0500 Subject: [PATCH 1/7] debug statements --- functions/completeTaskAssignment.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/functions/completeTaskAssignment.ts b/functions/completeTaskAssignment.ts index 2c8f64cf..d145e2a6 100644 --- a/functions/completeTaskAssignment.ts +++ b/functions/completeTaskAssignment.ts @@ -71,10 +71,16 @@ const closeTaskAssignment = async ( .tasks(event.taskSid) .fetch(); + console.log(`>>> Task Before: ${task.sid} attributes: ${JSON.stringify(task.attributes)}`); + await task.update({ attributes: event.finalTaskAttributes }); const completedTask = await task.update({ assignmentStatus: 'completed' }); + console.log( + `>>> Task After completing: ${completedTask.sid} attributes: ${JSON.stringify(completedTask.attributes)}`, + ); + return { type: 'success', completedTask } as const; } catch (err) { return { @@ -131,6 +137,8 @@ export const handler = TokenValidator( finalTaskAttributes: JSON.stringify({}), }); + console.log('>>> closeTaskAssignment Result:', result); + resolve(success(result)); } catch (err: any) { resolve(error500(err)); From a10501bbd947eed54f06efbe9d63dfea2541f5fe Mon Sep 17 00:00:00 2001 From: mythilytm Date: Mon, 11 Nov 2024 13:26:46 -0500 Subject: [PATCH 2/7] attempt to end client call --- functions/completeTaskAssignment.ts | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/functions/completeTaskAssignment.ts b/functions/completeTaskAssignment.ts index d145e2a6..df31ad8d 100644 --- a/functions/completeTaskAssignment.ts +++ b/functions/completeTaskAssignment.ts @@ -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; From 6268b619bba4eecb6f65024f52eef32740d1bfa6 Mon Sep 17 00:00:00 2001 From: mythilytm Date: Mon, 11 Nov 2024 13:46:47 -0500 Subject: [PATCH 3/7] Task completion for voice and chat tasks --- functions/completeTaskAssignment.ts | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/functions/completeTaskAssignment.ts b/functions/completeTaskAssignment.ts index df31ad8d..9f54d107 100644 --- a/functions/completeTaskAssignment.ts +++ b/functions/completeTaskAssignment.ts @@ -70,36 +70,18 @@ const closeTaskAssignment = async ( .workspaces(context.TWILIO_WORKSPACE_SID) .tasks(event.taskSid) .fetch(); - const attributes = JSON.parse(task.attributes); const callSid = attributes?.call_sid; - const callBefore = await client.calls(callSid).fetch(); - - console.log( - `>>> Task Before: ${task.sid} attributes: ${JSON.stringify(task.attributes)}`, - { callSid }, - `Call status After: ${callBefore}`, - ); - - // 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 const completedTask = await task.update({ assignmentStatus: 'completed', attributes: event.finalTaskAttributes, }); + // Ends the call for the client for voice 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, - )}`, - `Call status After: ${callAfter}`, - ); - return { type: 'success', completedTask } as const; } catch (err) { return { From 48e749850da848dda9ca0d18a13681dc5da7b95a Mon Sep 17 00:00:00 2001 From: mythilytm Date: Mon, 11 Nov 2024 13:59:19 -0500 Subject: [PATCH 4/7] Task completion for voice and chat tasks --- functions/completeTaskAssignment.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/functions/completeTaskAssignment.ts b/functions/completeTaskAssignment.ts index 9f54d107..9d72f487 100644 --- a/functions/completeTaskAssignment.ts +++ b/functions/completeTaskAssignment.ts @@ -138,8 +138,6 @@ export const handler = TokenValidator( finalTaskAttributes: JSON.stringify({}), }); - console.log('>>> closeTaskAssignment Result:', result); - resolve(success(result)); } catch (err: any) { resolve(error500(err)); From 9f4175d63f3b31606303f1637704800641e27f1d Mon Sep 17 00:00:00 2001 From: mythilytm Date: Thu, 14 Nov 2024 11:59:09 -0500 Subject: [PATCH 5/7] try wrapping instead of completing task --- functions/completeTaskAssignment.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/functions/completeTaskAssignment.ts b/functions/completeTaskAssignment.ts index 9d72f487..e012e3d3 100644 --- a/functions/completeTaskAssignment.ts +++ b/functions/completeTaskAssignment.ts @@ -72,17 +72,21 @@ const closeTaskAssignment = async ( .fetch(); const attributes = JSON.parse(task.attributes); const callSid = attributes?.call_sid; + // const conversationSid = attributes?.conversation_sid; // Ends the task for the worker and client for chat tasks, and only for the worker for voice tasks - const completedTask = await task.update({ - assignmentStatus: 'completed', + const wrappingTask = await task.update({ + assignmentStatus: 'wrapping', attributes: event.finalTaskAttributes, }); - - // Ends the call for the client for voice + 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' }); - return { type: 'success', completedTask } as const; + return { type: 'success', completedTask: wrappingTask } as const; } catch (err) { return { type: 'error', From 4ebb6004bca48babf95d6ff2c7d295ed9ee5425d Mon Sep 17 00:00:00 2001 From: mythilytm Date: Thu, 14 Nov 2024 13:17:52 -0500 Subject: [PATCH 6/7] try wrapping and completing task --- functions/completeTaskAssignment.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/functions/completeTaskAssignment.ts b/functions/completeTaskAssignment.ts index e012e3d3..8e4dcbb6 100644 --- a/functions/completeTaskAssignment.ts +++ b/functions/completeTaskAssignment.ts @@ -25,6 +25,7 @@ import { success, functionValidator as TokenValidator, } from '@tech-matters/serverless-helpers'; +import { set } from 'lodash'; type EnvVars = { TWILIO_WORKSPACE_SID: string; @@ -75,7 +76,7 @@ const closeTaskAssignment = async ( // const conversationSid = attributes?.conversation_sid; // Ends the task for the worker and client for chat tasks, and only for the worker for voice tasks - const wrappingTask = await task.update({ + await task.update({ assignmentStatus: 'wrapping', attributes: event.finalTaskAttributes, }); @@ -85,8 +86,13 @@ const closeTaskAssignment = async ( .fetch(); console.log(`Task ${aftertask} with attributes ${aftertask.attributes} has been completed`); if (callSid) await client.calls(callSid).update({ status: 'completed' }); - - return { type: 'success', completedTask: wrappingTask } as const; + setTimeout(() => { + console.log('This will be executed in 10sec'); + }, 10000); + const completedTask = await task.update({ + assignmentStatus: 'completed', + }); + return { type: 'success', completedTask } as const; } catch (err) { return { type: 'error', From 4ef31d0b7c2f472ebf2f841c96842aa8a600a79f Mon Sep 17 00:00:00 2001 From: mythilytm Date: Thu, 14 Nov 2024 13:26:16 -0500 Subject: [PATCH 7/7] try wrapping and completing task with settimeout --- functions/completeTaskAssignment.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/functions/completeTaskAssignment.ts b/functions/completeTaskAssignment.ts index 8e4dcbb6..3b12bb97 100644 --- a/functions/completeTaskAssignment.ts +++ b/functions/completeTaskAssignment.ts @@ -80,18 +80,22 @@ const closeTaskAssignment = async ( assignmentStatus: 'wrapping', attributes: event.finalTaskAttributes, }); + 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' }); - setTimeout(() => { - console.log('This will be executed in 10sec'); - }, 10000); + + // 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) { return {