Skip to content

Commit

Permalink
Logging
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenhand committed Sep 17, 2024
1 parent 804b17e commit c8ef305
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
18 changes: 16 additions & 2 deletions functions/taskrouterListeners/janitorListener.private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,24 @@ const isHandledByOtherListener = async (
].path) as ChannelCaptureHandlers;

if (channelCaptureHandlers.isChatCaptureControlTask(taskAttributes)) {
console.debug('isHandledByOtherListener? - Yes, isChatCaptureControl');
return true;
}

const transferHelpers = require(Runtime.getFunctions()['transfer/helpers']
.path) as TransferHelpers;

return !(await transferHelpers.hasTaskControl(client, workspaceSid, taskSid, taskAttributes));
const res = !(await transferHelpers.hasTaskControl(
client,
workspaceSid,
taskSid,
taskAttributes,
));
if (res) {
console.debug('isHandledByOtherListener? - Yes, does not have task control', taskAttributes);
} else {
console.debug('isHandledByOtherListener? - No, not handled by other listener');
}
return res;
};

const isCleanupCustomChannel = async (
Expand Down Expand Up @@ -127,15 +138,18 @@ const isDeactivateConversationOrchestration = async (
isChatCaptureControl?: boolean;
} & ChatTransferTaskAttributes,
) => {
console.debug('isDeactivateConversationOrchestration?');
if (
![TASK_WRAPUP, TASK_COMPLETED, TASK_DELETED, TASK_SYSTEM_DELETED, TASK_CANCELED].includes(
eventType,
)
) {
console.debug('isDeactivateConversationOrchestration? - No, wrong event type:', eventType);
return false;
}

if (await isHandledByOtherListener(client, workspaceSid, taskSid, taskAttributes)) {
console.debug('isDeactivateConversationOrchestration? - No, handled by other listener');
return false;
}

Expand Down
9 changes: 8 additions & 1 deletion functions/transfer/helpers.private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,17 @@ export const hasTaskControl = async (
taskAttributes: ChatTransferTaskAttributes,
) => {
if (!hasTransferStarted(taskAttributes)) {
console.debug('hasTaskControl? Yes - Transfer has not started');
return true;
}
const task = await client.taskrouter.v1.workspaces.get(workspaceSid).tasks.get(taskSid).fetch();
return taskAttributes.transferMeta?.sidWithTaskControl === task.sid;
const res = taskAttributes.transferMeta?.sidWithTaskControl === task.sid;
console.debug(
`hasTaskControl? ${res ? 'Yes' : 'No'} - ${task.sid} (task.sid) === ${
taskAttributes.transferMeta?.sidWithTaskControl
} (taskAttributes.transferMeta?.sidWithTaskControl)`,
);
return res;
};

export type TransferHelpers = {
Expand Down

0 comments on commit c8ef305

Please sign in to comment.