Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
CUSTOMER_NAME,
} from '../constants';
import {withMetrics} from '@webex/cc-ui-logging';
import {isSecondaryAgent} from '@webex/cc-store';

const CallControlCADComponent: React.FC<CallControlComponentProps> = (props) => {
const {
Expand Down Expand Up @@ -63,7 +64,14 @@ const CallControlCADComponent: React.FC<CallControlComponentProps> = (props) =>
const isTelephony = mediaChannel === MediaChannelType.TELEPHONY;
const participantsCount = conferenceParticipants?.length || 1;
const participantsLabel = participantsCount === 1 ? 'Participant' : 'Participants';
const shouldShowParticipantsList = (conferenceParticipants?.length || 0) > 1;
const interactionState = currentTask?.data?.interaction?.state;
const isConferenceActive =
controls?.main?.exitConference?.isVisible ||
currentTask?.data?.isConferenceInProgress === true ||
interactionState === 'conference';
const isConsultOnlyAgent = isSecondaryAgent(currentTask);
const shouldShowParticipantsList =
isConferenceActive && !isConsultOnlyAgent && (conferenceParticipants?.length ?? 0) > 0;

const customerName = currentTask?.data?.interaction?.callAssociatedDetails?.customerName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,19 @@ describe('CallControlCADComponent', () => {
});

describe('conference participants list visibility', () => {
it('shows participants list when there are more than two participants total', () => {
it('shows participants list when conference is active and other agents are present', () => {
const screen = render(
<CallControlCADComponent
{...defaultProps}
controls={createEnabledMainTaskUIControls({exitConference: {isVisible: true, isEnabled: true}})}
conferenceParticipants={[{id: 'agent-2', name: 'Agent Two', pType: 'Agent'}]}
/>
);

expect(screen.getByTestId('call-control:participants-trigger')).toBeInTheDocument();
});

it('hides participants list when exitConference is not visible and conference is not in progress', () => {
const screen = render(
<CallControlCADComponent
{...defaultProps}
Expand All @@ -393,15 +405,73 @@ describe('CallControlCADComponent', () => {
/>
);

expect(screen.queryByTestId('call-control:participants-trigger')).not.toBeInTheDocument();
});

it('shows participants list during nested consult when interaction state is conference', () => {
const conferenceTask = {
...defaultProps.currentTask,
data: {
...defaultProps.currentTask.data,
isConferenceInProgress: false,
interaction: {
...defaultProps.currentTask.data.interaction,
state: 'conference',
},
},
};

const screen = render(
<CallControlCADComponent
{...defaultProps}
currentTask={conferenceTask}
controls={createEnabledMainTaskUIControls({exitConference: {isVisible: false, isEnabled: false}})}
conferenceParticipants={[{id: 'agent-2', name: 'Agent Two', pType: 'Agent'}]}
/>
);

expect(screen.getByTestId('call-control:participants-trigger')).toBeInTheDocument();
});

it('hides participants list when two or fewer participants are present in total', () => {
it('hides participants list for consult-only secondary agents even when participants exist', () => {
const consultTask = {
...defaultProps.currentTask,
data: {
...defaultProps.currentTask.data,
isConferenceInProgress: false,
interaction: {
...defaultProps.currentTask.data.interaction,
state: 'consult',
interactionId: 'child-interaction-id',
callProcessingDetails: {
relationshipType: 'consult',
parentInteractionId: 'parent-interaction-id',
},
},
},
};

const screen = render(
<CallControlCADComponent
{...defaultProps}
currentTask={consultTask}
controls={createEnabledMainTaskUIControls({exitConference: {isVisible: true, isEnabled: true}})}
conferenceParticipants={[{id: 'agent-2', name: 'Agent Two', pType: 'Agent'}]}
conferenceParticipants={[
{id: 'agent-2', name: 'Agent Two', pType: 'Agent'},
{id: 'agent-3', name: 'Agent Three', pType: 'Agent'},
]}
/>
);

expect(screen.queryByTestId('call-control:participants-trigger')).not.toBeInTheDocument();
});

it('hides participants list when conference is active but no other agents are present', () => {
const screen = render(
<CallControlCADComponent
{...defaultProps}
controls={createEnabledMainTaskUIControls({exitConference: {isVisible: true, isEnabled: true}})}
conferenceParticipants={[]}
/>
);

Expand Down
65 changes: 56 additions & 9 deletions packages/contact-center/store/src/task-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ export const isIncomingTask = (task: ITask, agentId: string): boolean => {
* @returns {boolean} True if this is a secondary agent (consulted party)
*/
export function isSecondaryAgent(task: ITask): boolean {
const interaction = task.data.interaction;
const interaction = task?.data?.interaction;
const callProcessingDetails = interaction?.callProcessingDetails;

if (!callProcessingDetails) {
return false;
}

return (
!!interaction.callProcessingDetails &&
interaction.callProcessingDetails.relationshipType === RELATIONSHIP_TYPE_CONSULT &&
interaction.callProcessingDetails.parentInteractionId &&
interaction.callProcessingDetails.parentInteractionId !== interaction.interactionId
callProcessingDetails.relationshipType === RELATIONSHIP_TYPE_CONSULT &&
Boolean(callProcessingDetails.parentInteractionId) &&
callProcessingDetails.parentInteractionId !== interaction?.interactionId
);
}

Expand All @@ -41,9 +45,41 @@ export function isSecondaryAgent(task: ITask): boolean {
* This is specifically for telephony consultations to external numbers/entry points.
*/
export function isSecondaryEpDnAgent(task: ITask): boolean {
return task.data.interaction.mediaType === MEDIA_TYPE_TELEPHONY_LOWER && isSecondaryAgent(task);
return task?.data?.interaction?.mediaType === MEDIA_TYPE_TELEPHONY_LOWER && isSecondaryAgent(task);
}

const isMainCallMedia = (mType: string | undefined): boolean => mType === 'mainCall' || mType === 'main';

/**
* Resolves the main-call media leg for conference participant lookup.
* During nested consult, task.data.interactionId can point at the consult leg;
* conference participants remain on the mainCall media entry.
*/
const getMainCallMediaEntry = (task: ITask) => {
const media = task?.data?.interaction?.media;
if (!media) {
return undefined;
}

const mainCallMediaId = findMediaResourceId(task, 'mainCall');
if (mainCallMediaId && media[mainCallMediaId]) {
return media[mainCallMediaId];
}

const typedMainCallMedia = Object.values(media).find((entry) => isMainCallMedia(entry.mType));
if (typedMainCallMedia) {
return typedMainCallMedia;
}

// Legacy payloads map interactionId directly to main-call media and may omit mType.
const interactionMedia = task.data.interactionId ? media[task.data.interactionId] : undefined;
if (interactionMedia && interactionMedia.mType !== 'consult') {
return interactionMedia;
}

return undefined;
};

/**
* Retrieves the list of active conference participants excluding the current agent
* Filters out customers, supervisors, VVAs, and participants who have left
Expand All @@ -55,13 +91,24 @@ export function isSecondaryEpDnAgent(task: ITask): boolean {
export const getConferenceParticipants = (task: ITask, agentId: string): Participant[] => {
const participantsList: Participant[] = [];

// Early return if required data is missing
if (!task?.data?.interaction?.media || !task?.data?.interactionId) {
if (!task?.data?.interaction?.media) {
return participantsList;
}

const mediaMainCall = task.data.interaction.media?.[task.data.interactionId];
// Consult-only child tasks (EP-DN) inherit parent data but are not conference members.
if (isSecondaryAgent(task)) {
return participantsList;
}

const mediaMainCall = getMainCallMediaEntry(task);
const participantsInMainCall = new Set(mediaMainCall?.participants ?? []);

// Nested consult during conference: consulted agent inherits parent interaction state
// and mainCall media, but is only joined on the consult leg — not a conference member.
if (agentId && !participantsInMainCall.has(agentId)) {
return participantsList;
}

const participants = task.data.interaction.participants ?? {};

if (participantsInMainCall.size > 0 && participants) {
Expand Down
106 changes: 106 additions & 0 deletions packages/contact-center/store/tests/task-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,112 @@ describe('getConferenceParticipants', () => {
name: 'agent2',
});
});

it('should resolve mainCall media by mType when interactionId points to consult leg', () => {
const mainCallMediaId = '4da1b819-f461-444b-b817-0c983f235cde';
const consultMediaId = '8d18e6c0-4377-4431-8b9d-ed22cdde94cb';

const task = createMockTask({
interactionId: consultMediaId,
interaction: createPartialInteraction({
state: 'conference',
media: {
[mainCallMediaId]: {
mType: 'mainCall',
mediaResourceId: mainCallMediaId,
participants: ['agent1', 'agent2', 'customer1'],
},
[consultMediaId]: {
mType: 'consult',
mediaResourceId: consultMediaId,
participants: ['agent1', 'agent3'],
},
},
participants: {
agent1: {id: 'agent1', pType: 'Agent', name: 'Agent One', hasLeft: false},
agent2: {id: 'agent2', pType: 'Agent', name: 'Agent Two', hasLeft: false},
agent3: {id: 'agent3', pType: 'Agent', name: 'Agent Three', hasLeft: false},
customer1: {id: 'customer1', pType: 'Customer', name: 'Customer One', hasLeft: false},
},
}),
});

const result = getConferenceParticipants(task, currentAgentId);

expect(result).toEqual([
{
id: 'agent2',
pType: 'Agent',
name: 'Agent Two',
},
]);
});

it('should return empty array for consult-only secondary agents not in conference', () => {
const task = createMockTask({
interactionId: 'child-interaction',
interaction: createPartialInteraction({
state: 'consult',
interactionId: 'child-interaction',
callProcessingDetails: {
relationshipType: 'consult',
parentInteractionId: 'parent-interaction',
},
media: {
main: {
mType: 'mainCall',
mediaResourceId: 'main',
participants: ['agent3', 'agent1', 'agent2'],
},
},
participants: {
agent1: {id: 'agent1', pType: 'Agent', name: 'Agent One', hasLeft: false},
agent2: {id: 'agent2', pType: 'Agent', name: 'Agent Two', hasLeft: false},
agent3: {id: 'agent3', pType: 'Agent', name: 'Agent Three', hasLeft: false},
},
}),
});

expect(getConferenceParticipants(task, 'agent3')).toEqual([]);
});

it('should return empty array for agent-name consulted agent during conference nested consult', () => {
const mainCallMediaId = 'b3629886-1f6b-4de9-b037-8f09667abac8';
const consultMediaId = '10bd2a1e-fc74-4c2c-af61-4f82de268cf7';

const task = createMockTask({
interactionId: consultMediaId,
interaction: createPartialInteraction({
state: 'conference',
interactionId: mainCallMediaId,
media: {
[mainCallMediaId]: {
mType: 'mainCall',
mediaResourceId: mainCallMediaId,
participants: ['customer1', 'agent1', 'agent2', 'dn1'],
},
[consultMediaId]: {
mType: 'consult',
mediaResourceId: consultMediaId,
participants: ['agent3', 'agent1'],
},
},
participants: {
agent1: {id: 'agent1', pType: 'Agent', name: 'Agent One', hasLeft: false, isConsulted: false},
agent2: {id: 'agent2', pType: 'Agent', name: 'Agent Two', hasLeft: false, isConsulted: false},
agent3: {id: 'agent3', pType: 'Agent', name: 'Agent Three', hasLeft: false, isConsulted: true},
customer1: {id: 'customer1', pType: 'Customer', name: 'Customer', hasLeft: false},
dn1: {id: 'dn1', pType: 'DN', name: 'DN', hasLeft: false},
},
}),
});

expect(getConferenceParticipants(task, 'agent3')).toEqual([]);
expect(getConferenceParticipants(task, 'agent1')).toEqual([
{id: 'agent2', pType: 'Agent', name: 'Agent Two'},
{id: 'dn1', pType: 'DN', name: 'DN'},
]);
});
});

describe('findHoldTimestamp', () => {
Expand Down
Loading
Loading