From ff372705a3bd9fc652acc44c8590489bf147f1c4 Mon Sep 17 00:00:00 2001 From: Stephen Hand Date: Tue, 11 Jun 2024 12:25:20 +0100 Subject: [PATCH] Enable channel janitor for survey events on conversations tasks being cancelled --- .../taskrouterListeners/janitorListener.private.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/functions/taskrouterListeners/janitorListener.private.ts b/functions/taskrouterListeners/janitorListener.private.ts index d8a29594..637ec52b 100644 --- a/functions/taskrouterListeners/janitorListener.private.ts +++ b/functions/taskrouterListeners/janitorListener.private.ts @@ -156,13 +156,22 @@ export const handleEvent = async (context: Context, event: EventFields) } = event; // The janitor is only be executed for chat based tasks - if (taskChannelUniqueName !== 'chat') return; + if (!['chat', 'survey'].includes(taskChannelUniqueName)) return; console.log(`===== Executing JanitorListener for event: ${eventType} =====`); const taskAttributes = JSON.parse(taskAttributesString || '{}'); const { channelSid, conversationSid } = taskAttributes; + if (taskChannelUniqueName === 'survey' && (!conversationSid || 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.', + eventType, + conversationSid, + ); + return; + } + if (isCleanupBotCapture(eventType, taskAttributes)) { await wait(3000); // wait 3 seconds just in case some bot message is pending