Skip to content

Commit

Permalink
Try 'parking' an interaction for post surveys
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenhand committed Jun 10, 2024
1 parent 6f030f1 commit e20cb0c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion functions/channelCapture/channelCaptureHandlers.private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ const createStudioFlowTrigger = async (
controlTask: TaskInstance,
) => {
// Canceling tasks triggers janitor (see functions/taskrouterListeners/janitorListener.private.ts), so we remove this one since is not needed
controlTask.remove();
await controlTask.remove();
const { isConversation } = capturedChannelAttributes;

if (isConversation) {
Expand Down
25 changes: 22 additions & 3 deletions functions/postSurveyInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,26 @@ export const postSurveyInitHandler = async (
context: Context<EnvVars>,
event: Omit<Body, 'request'>,
) => {
const { channelSid, conversationSid, taskSid, taskLanguage } = event;
const { channelSid, conversationSid, taskSid, taskLanguage, channelType } = event;
const client = context.getTwilioClient();
const task = await client.taskrouter
.workspaces(context.TWILIO_WORKSPACE_SID)
.tasks(taskSid)
.fetch();
const { flexInteractionSid, flexInteractionChannelSid } = JSON.parse(task.attributes);
const interactionParticipantContext = client.flexApi.v1
.interaction(flexInteractionSid)
.channels(flexInteractionChannelSid).participants;
const interactionAgentParticipants = (await interactionParticipantContext.list()).filter(
(p) => p.type === 'agent',
);

// Should only be 1, but just in case
await Promise.all(
interactionAgentParticipants.map((p) =>
interactionParticipantContext(p.sid).update({ status: 'wrapup' }),
),
);

const triggerMessage = await getTriggerMessage(event, context);

Expand All @@ -109,7 +128,7 @@ export const postSurveyInitHandler = async (
language: taskLanguage, // if there's a task language, attach it to the post survey task
}),
controlTaskTTL: 3600,
channelType: '',
channelType,
} as const;
if (conversationSid) {
return channelCaptureHandlers.handleChannelCapture(context, {
Expand Down Expand Up @@ -140,7 +159,7 @@ export const handler = TokenValidator(
try {
const { channelSid, taskSid, taskLanguage, conversationSid } = event;

if (!channelSid && !conversationSid) return resolve(error400('channelSid'));
if (!channelSid && !conversationSid) return resolve(error400('channelSid / conversationSid'));
if (!taskSid) return resolve(error400('taskSid'));
if (!taskLanguage) return resolve(error400('taskLanguage'));

Expand Down

0 comments on commit e20cb0c

Please sign in to comment.