Skip to content

Commit

Permalink
Enable channel janitor for survey events on conversations tasks being…
Browse files Browse the repository at this point in the history
… cancelled
  • Loading branch information
stephenhand committed Jun 11, 2024
1 parent 3c13f86 commit ff37270
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion functions/taskrouterListeners/janitorListener.private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,22 @@ export const handleEvent = async (context: Context<EnvVars>, 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

Expand Down

0 comments on commit ff37270

Please sign in to comment.