From 43ee8180abc902a74ebeb541770b933312d4a93b Mon Sep 17 00:00:00 2001 From: Stephen Hand Date: Tue, 11 Jun 2024 15:04:56 +0100 Subject: [PATCH] Enable channel janitor for survey events on all tasks being cancelled --- .../taskrouterListeners/janitorListener.private.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/functions/taskrouterListeners/janitorListener.private.ts b/functions/taskrouterListeners/janitorListener.private.ts index 637ec52b..fb611998 100644 --- a/functions/taskrouterListeners/janitorListener.private.ts +++ b/functions/taskrouterListeners/janitorListener.private.ts @@ -160,18 +160,17 @@ export const handleEvent = async (context: Context, event: EventFields) console.log(`===== Executing JanitorListener for event: ${eventType} =====`); - const taskAttributes = JSON.parse(taskAttributesString || '{}'); - const { channelSid, conversationSid } = taskAttributes; - - if (taskChannelUniqueName === 'survey' && (!conversationSid || eventType !== TASK_CANCELED)) { + if (taskChannelUniqueName === 'survey' && eventType !== TASK_CANCELED) { console.log( - 'Survey tasks are only handled by the channel janitor if they are cancelled events for conversations tasks - skipping this one.', + 'Survey tasks are only handled by the channel janitor on task cancelled events skipping this one.', eventType, - conversationSid, ); return; } + const taskAttributes = JSON.parse(taskAttributesString || '{}'); + const { channelSid, conversationSid } = taskAttributes; + if (isCleanupBotCapture(eventType, taskAttributes)) { await wait(3000); // wait 3 seconds just in case some bot message is pending