Skip to content

Commit

Permalink
chore: bug fix - duplicate contact created when transfer rejected on …
Browse files Browse the repository at this point in the history
…a queue [CHI-2803] (#622)
  • Loading branch information
GPaoloni authored Jun 13, 2024
1 parent 50ba9f6 commit 370acb7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions functions/taskrouterListeners/transfersListener.private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export const handleEvent = async (context: Context<EnvVars>, event: EventFields)
reason: 'task transferred into queue',
});

console.log('Finished handling chat queue transfer.');
console.log('Finished handling chat queue transfer initiated.');
return;
}

Expand All @@ -225,7 +225,7 @@ export const handleEvent = async (context: Context<EnvVars>, 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();
Expand Down Expand Up @@ -272,7 +272,7 @@ export const handleEvent = async (context: Context<EnvVars>, event: EventFields)
reason: 'task transferred rejected',
});

console.log('Finished handling chat transfer rejected.');
console.log('Finished handling chat transfer to worker rejected.');
return;
}

Expand Down
22 changes: 11 additions & 11 deletions functions/transferChatStart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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) {
Expand Down

0 comments on commit 370acb7

Please sign in to comment.