From 370acb7ed7703093957f8d76e123d75d4b831480 Mon Sep 17 00:00:00 2001 From: Gianfranco Date: Thu, 13 Jun 2024 15:54:56 -0300 Subject: [PATCH] chore: bug fix - duplicate contact created when transfer rejected on a queue [CHI-2803] (#622) --- .../transfersListener.private.ts | 6 ++--- functions/transferChatStart.ts | 22 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/functions/taskrouterListeners/transfersListener.private.ts b/functions/taskrouterListeners/transfersListener.private.ts index dce2fdbd..b8db144e 100644 --- a/functions/taskrouterListeners/transfersListener.private.ts +++ b/functions/taskrouterListeners/transfersListener.private.ts @@ -211,7 +211,7 @@ export const handleEvent = async (context: Context, event: EventFields) reason: 'task transferred into queue', }); - console.log('Finished handling chat queue transfer.'); + console.log('Finished handling chat queue transfer initiated.'); return; } @@ -225,7 +225,7 @@ export const handleEvent = async (context: Context, event: EventFields) * 3) Cancel rejected task */ if (isChatTransferToWorkerRejected(eventType, taskChannelUniqueName, taskAttributes)) { - console.log('Handling chat transfer rejected...'); + console.log('Handling chat transfer to worker rejected...'); const { originalTask: originalTaskSid } = taskAttributes.transferMeta; const client = context.getTwilioClient(); @@ -272,7 +272,7 @@ export const handleEvent = async (context: Context, event: EventFields) reason: 'task transferred rejected', }); - console.log('Finished handling chat transfer rejected.'); + console.log('Finished handling chat transfer to worker rejected.'); return; } diff --git a/functions/transferChatStart.ts b/functions/transferChatStart.ts index a540f8a7..2512bb14 100644 --- a/functions/transferChatStart.ts +++ b/functions/transferChatStart.ts @@ -225,7 +225,15 @@ export const handler = TokenValidator( transferTargetType, }; - // create New task + // Edit channel attributes so that original task won't cause issues with the transferred one + await setDummyChannel(context, { + mode, + ignoreAgent, + targetSid, + taskSid, + }); + + // Create New task const newTask = await client.taskrouter .workspaces(context.TWILIO_WORKSPACE_SID) .tasks.create({ @@ -235,16 +243,8 @@ export const handler = TokenValidator( priority: 100, }); - // Final actions that might not happen (conditions specified inside of each) - await Promise.all([ - increaseChatCapacity(context, validationResult), - setDummyChannel(context, { - mode, - ignoreAgent, - targetSid, - taskSid, - }), - ]); + // Increse the chat capacity for the target worker (if needed) + await increaseChatCapacity(context, validationResult); resolve(success({ taskSid: newTask.sid })); } catch (err: any) {