-
Notifications
You must be signed in to change notification settings - Fork 62
feat(call-control): enhance agent name display logic in multi-agent conferences #585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bhabalan
wants to merge
3
commits into
webex:next
Choose a base branch
from
bhabalan:CAI-7461-consult-name-fixes
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -302,7 +302,7 @@ export const useCallControl = (props: useCallControlProps) => { | |
| // Consult timer labels and timestamps | ||
| const [consultTimerLabel, setConsultTimerLabel] = useState<string>(TIMER_LABEL_CONSULTING); | ||
| const [consultTimerTimestamp, setConsultTimerTimestamp] = useState<number>(0); | ||
| const [lastTargetType, setLastTargetType] = useState<'agent' | 'queue'>('agent'); | ||
| const [lastTargetType, setLastTargetType] = useState<'agent' | 'queue' | 'entryPoint' | 'dialNumber'>('agent'); | ||
| const [conferenceParticipants, setConferenceParticipants] = useState<Participant[]>([]); | ||
|
|
||
| // Use custom hook for hold timer management | ||
|
|
@@ -322,21 +322,111 @@ export const useCallControl = (props: useCallControlProps) => { | |
| const {interaction} = currentTask.data; | ||
| const myAgentId = store.cc.agentConfig?.agentId; | ||
|
|
||
| // Find all agent participants except the current agent | ||
| const otherAgents = Object.values(interaction.participants || {}).filter( | ||
| (participant): participant is Participant => | ||
| (participant as Participant).pType === 'Agent' && (participant as Participant).id !== myAgentId | ||
| ); | ||
| // For Entry Point or Dial Number consults, check if destination agent has joined | ||
| if (lastTargetType === 'entryPoint' || lastTargetType === 'dialNumber') { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add enum or constant-based TargetType to avoid string duplication |
||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const consultDestinationAgentName = (interaction as any).callProcessingDetails?.consultDestinationAgentName; | ||
|
|
||
| if (consultDestinationAgentName) { | ||
| // Destination agent has joined, show their name | ||
| setConsultAgentName(consultDestinationAgentName); | ||
| logger.info(`${lastTargetType} consult answered - showing agent name: ${consultDestinationAgentName}`, { | ||
| module: 'widget-cc-task#helper.ts', | ||
| method: 'useCallControl#extractConsultingAgent', | ||
| }); | ||
| } else { | ||
| // Still ringing - find the EP/DN participant in the consult media | ||
| const consultMediaResourceId = findMediaResourceId(currentTask, 'consult'); | ||
|
|
||
| if (consultMediaResourceId && interaction.media?.[consultMediaResourceId]) { | ||
| const consultMedia = interaction.media[consultMediaResourceId]; | ||
| // Find the participant in consult media who is not the current agent | ||
| const consultParticipantId = consultMedia.participants?.find( | ||
| (participantId: string) => participantId !== myAgentId | ||
| ); | ||
|
|
||
| if (consultParticipantId && interaction.participants[consultParticipantId]) { | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const participant = interaction.participants[consultParticipantId] as any; | ||
| const phoneNumber = participant.dn || participant.id; | ||
|
|
||
| if (phoneNumber && phoneNumber !== consultAgentName) { | ||
| setConsultAgentName(phoneNumber); | ||
| logger.info(`${lastTargetType} consult ringing - showing phone number: ${phoneNumber}`, { | ||
| module: 'widget-cc-task#helper.ts', | ||
| method: 'useCallControl#extractConsultingAgent', | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| // Pick the first other agent (should only be one in a consult) | ||
| const foundAgent = otherAgents.length > 0 ? {id: otherAgents[0].id, name: otherAgents[0].name} : null; | ||
| // For regular agent consults, find the agent in the consult media | ||
| const consultMediaResourceId = findMediaResourceId(currentTask, 'consult'); | ||
|
|
||
| if (foundAgent) { | ||
| setConsultAgentName(foundAgent.name); | ||
| logger.info(`Consulting agent detected: ${foundAgent.name} ${foundAgent.id}`, { | ||
| module: 'widget-cc-task#helper.ts', | ||
| method: 'useCallControl#extractConsultingAgent', | ||
| if (consultMediaResourceId && interaction.media?.[consultMediaResourceId]) { | ||
| const consultMedia = interaction.media[consultMediaResourceId]; | ||
| // Find the agent participant in consult media who is not the current agent | ||
| const consultParticipantId = consultMedia.participants?.find((participantId: string) => { | ||
| const participant = interaction.participants[participantId]; | ||
| return participant && participant.id !== myAgentId && participant.pType === 'Agent'; | ||
| }); | ||
|
|
||
| if (consultParticipantId && interaction.participants[consultParticipantId]) { | ||
| const consultAgent = interaction.participants[consultParticipantId]; | ||
| setConsultAgentName(consultAgent.name || consultAgent.id); | ||
| logger.info(`Consulting agent detected: ${consultAgent.name} ${consultAgent.id}`, { | ||
| module: 'widget-cc-task#helper.ts', | ||
| method: 'useCallControl#extractConsultingAgent', | ||
| }); | ||
| } | ||
| } else { | ||
| // Fallback: Use old logic if consult media not found | ||
| const otherAgents = Object.values(interaction.participants || {}).filter( | ||
| (participant): participant is Participant => | ||
| (participant as Participant).pType === 'Agent' && (participant as Participant).id !== myAgentId | ||
| ); | ||
|
|
||
| // In a conference with multiple agents, find the agent currently being consulted | ||
| // Priority: 1) consultState="consulting" 2) most recent consultTimestamp | ||
| let foundAgent: {id: string; name: string} | null = null; | ||
|
|
||
| if (otherAgents.length > 0) { | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const consultingAgent = otherAgents.find((agent: any) => agent.consultState === 'consulting'); | ||
|
|
||
| if (consultingAgent) { | ||
| foundAgent = { | ||
| id: consultingAgent.id, | ||
| name: consultingAgent.name, | ||
| }; | ||
| } else { | ||
| // Fallback: Find agent with most recent consultTimestamp | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const agentWithMostRecentTimestamp = otherAgents.reduce((latest: any, current: any) => { | ||
| const currentTimestamp = current.consultTimestamp || current.joinTimestamp || 0; | ||
| const latestTimestamp = latest ? latest.consultTimestamp || latest.joinTimestamp || 0 : 0; | ||
| return currentTimestamp > latestTimestamp ? current : latest; | ||
| }, null); | ||
|
|
||
| if (agentWithMostRecentTimestamp) { | ||
| foundAgent = { | ||
| id: agentWithMostRecentTimestamp.id, | ||
| name: agentWithMostRecentTimestamp.name, | ||
| }; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (foundAgent) { | ||
| setConsultAgentName(foundAgent.name); | ||
| logger.info(`Consulting agent detected (fallback): ${foundAgent.name} ${foundAgent.id}`, { | ||
| module: 'widget-cc-task#helper.ts', | ||
| method: 'useCallControl#extractConsultingAgent', | ||
| }); | ||
| } | ||
| } | ||
| } catch (error) { | ||
| console.log('error', error); | ||
|
|
@@ -345,7 +435,7 @@ export const useCallControl = (props: useCallControlProps) => { | |
| method: 'extractConsultingAgent', | ||
| }); | ||
| } | ||
| }, [currentTask, logger]); | ||
| }, [currentTask, logger, lastTargetType, consultAgentName, setConsultAgentName]); | ||
|
|
||
| // Extract main call timestamp whenever currentTask changes | ||
| useEffect(() => { | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please replace the inline union type
useState<'agent' | 'queue' | 'entryPoint' | 'dialNumber'>
with a shared enum or constant-based TargetType to avoid string duplication, improve type safety, and make future refactors safer.