@@ -853,73 +853,17 @@ export function DemoCallProvider({ children, initialAgentId }: { children: React
853853 return ( ) => window . removeEventListener ( 'beforeunload' , handleBeforeUnload ) ;
854854 } , [ currentCall ?. id , currentCall ?. status , cachedToken ] ) ;
855855
856- // Helper to find caller name from various sources
856+ // Helper to find caller name — extracted fields only, no regex.
857+ // Actual name extraction from the transcript is handled by Groq tool call in summarizeCall.
857858 const findCallerName = ( call : CallSession ) : string => {
858- // First try extracted fields (most reliable)
859859 const nameField = call . extractedFields . find ( f =>
860860 f . id === 'name' ||
861861 f . label . toLowerCase ( ) . includes ( 'name' ) ||
862862 f . label . toLowerCase ( ) . includes ( 'caller' )
863863 ) ;
864864 if ( nameField ?. value && nameField . value . trim ( ) && nameField . value !== 'Unknown Caller' ) {
865- console . log ( '✅ Found caller name from extracted fields:' , nameField . value ) ;
866865 return nameField . value . trim ( ) ;
867866 }
868-
869- // Common words to filter out as false positives
870- const commonWords = [ 'hello' , 'hi' , 'hey' , 'yes' , 'no' , 'okay' , 'sure' , 'thanks' , 'thank' , 'you' , 'the' , 'a' , 'an' , 'how' , 'can' , 'help' , 'may' , 'please' , 'need' , 'want' , 'have' , 'for' , 'reaching' , 'out' , 'your' , 'this' , 'that' , 'with' , 'about' , 'today' , 'there' , 'got' , 'it' ] ;
871-
872- // Try to find name in messages where user introduced themselves
873- const userMessages = call . messages . filter ( m => m . speaker === 'user' ) ;
874- for ( const msg of userMessages ) {
875- // Common patterns: "My name is X", "I'm X", "This is X", "I am X", "Hi, I'm X", "Hello, this is X"
876- const patterns = [
877- / (?: m y n a m e i s | i ' ? m | t h i s i s | i a m | c a l l m e | h i , ? \s * i ' ? m | h e l l o , ? \s * t h i s i s ) \s + ( [ A - Z ] [ a - z ] + (?: \s + [ A - Z ] [ a - z ] + ) ? ) / i,
878- / ^ ( [ A - Z ] [ a - z ] + (?: \s + [ A - Z ] [ a - z ] + ) ? ) \s + (?: h e r e | c a l l i n g | s p e a k i n g ) / i,
879- / (?: h i | h e l l o ) , ? \s * ( [ A - Z ] [ a - z ] + ) / i,
880- // Pattern for just stating name directly like "Animesh Mishra" or "Animesh Mishra 9650848339"
881- / ^ ( [ A - Z ] [ a - z ] + \s + [ A - Z ] [ a - z ] + ) (?: \s + \d + ) ? $ / i,
882- // Pattern for "im Animesh" or "its Animesh"
883- / (?: i m | i t s | i t ' s ) \s + ( [ A - Z ] [ a - z ] + (?: \s + [ A - Z ] [ a - z ] + ) ? ) / i,
884- ] ;
885-
886- for ( const pattern of patterns ) {
887- const match = msg . text . match ( pattern ) ;
888- if ( match ?. [ 1 ] ) {
889- const name = match [ 1 ] . trim ( ) ;
890- // Filter out common false positives
891- if ( ! commonWords . includes ( name . toLowerCase ( ) ) && name . length > 2 ) {
892- console . log ( '✅ Found caller name from message pattern:' , name ) ;
893- return name ;
894- }
895- }
896- }
897- }
898-
899- // Try agent messages that might reference the caller's name
900- const agentMessages = call . messages . filter ( m => m . speaker === 'agent' ) ;
901- for ( const msg of agentMessages ) {
902- const patterns = [
903- / (?: h i | h e l l o ) , ? \s + ( [ A - Z ] [ a - z ] + (?: \s + [ A - Z ] [ a - z ] + ) ? ) / i,
904- / (?: t h a n k s | t h a n k y o u ) , ? \s + ( [ A - Z ] [ a - z ] + ) / i,
905- // Pattern for "Mr./Ms./Mrs. X" - common in formal responses
906- / (?: M r \. ? | M s \. ? | M r s \. ? ) \s + ( [ A - Z ] [ a - z ] + ) / i,
907- // Pattern for "Hello, Mr. Mishra" style
908- / (?: h e l l o | h i ) , ? \s + (?: M r \. ? | M s \. ? | M r s \. ? ) \s + ( [ A - Z ] [ a - z ] + ) / i,
909- ] ;
910- for ( const pattern of patterns ) {
911- const match = msg . text . match ( pattern ) ;
912- if ( match ?. [ 1 ] ) {
913- const name = match [ 1 ] . trim ( ) ;
914- if ( ! commonWords . includes ( name . toLowerCase ( ) ) && name . length > 2 ) {
915- console . log ( '✅ Found caller name from agent message:' , name ) ;
916- return name ;
917- }
918- }
919- }
920- }
921-
922- console . log ( '⚠️ Could not find caller name, using "Unknown Caller"' ) ;
923867 return 'Unknown Caller' ;
924868 } ;
925869
@@ -1056,7 +1000,8 @@ export function DemoCallProvider({ children, initialAgentId }: { children: React
10561000 finalSummary = summaryResponse . summary ;
10571001 tags = summaryResponse . tags ;
10581002
1059- if ( summaryResponse . callerName && callerName === 'Unknown Caller' ) {
1003+ // Always prefer the AI-extracted name (Groq tool call result)
1004+ if ( summaryResponse . callerName && summaryResponse . callerName !== 'Unknown Caller' ) {
10601005 callerName = summaryResponse . callerName ;
10611006 }
10621007 console . log ( '✅ AI summary generated successfully' ) ;
@@ -1070,10 +1015,6 @@ export function DemoCallProvider({ children, initialAgentId }: { children: React
10701015 } ;
10711016 }
10721017
1073- if ( callerName === 'Unknown Caller' ) {
1074- callerName = findCallerName ( endedCall ) ;
1075- }
1076-
10771018 // Create the final history item with real summary
10781019 const finalHistoryItem : CallHistoryItem = {
10791020 id : historyId ,
0 commit comments