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] (#623)
  • Loading branch information
GPaoloni authored Jun 13, 2024
1 parent 65fe7b8 commit 3bad85a
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 @@ -208,7 +208,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 @@ -222,7 +222,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 @@ -269,7 +269,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 3bad85a

Please sign in to comment.