@@ -1354,14 +1354,25 @@ async function handleEscalationButton(
13541354 actor : string ,
13551355 _baseUrl : string ,
13561356) : Promise < unknown > {
1357+ // Button custom_id format: esc_{action}_{companyId}_{escalationId}
1358+ // Legacy format (pre-fix): esc_{action}_{escalationId}
1359+ // CompanyId is a UUID (contains hyphens), escalationId starts with "esc_".
1360+ // We split on "_" to get the action, then look for a UUID-shaped segment.
13571361 const parts = customId . split ( "_" ) ;
13581362 const action = parts [ 1 ] ;
1359- const escalationId = parts . slice ( 2 ) . join ( "_" ) ;
1363+ const remaining = parts . slice ( 2 ) . join ( "_" ) ;
13601364
1361- ctx . logger . info ( "Escalation button clicked" , { escalationId, action, actor } ) ;
1365+ // Try to extract embedded companyId: UUID pattern before the escalation ID
1366+ const uuidEscMatch = remaining . match (
1367+ / ^ ( [ 0 - 9 a - f ] { 8 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 12 } ) _ ( e s c _ .+ ) $ / i,
1368+ ) ;
1369+ const embeddedCompanyId = uuidEscMatch ? uuidEscMatch [ 1 ] : null ;
1370+ const escalationId = uuidEscMatch ? uuidEscMatch [ 2 ] : remaining ;
1371+
1372+ ctx . logger . info ( "Escalation button clicked" , { escalationId, action, actor, embeddedCompanyId } ) ;
13621373
1363- const resolvedCompanyId = await resolveCompanyId ( ctx ) ;
1364- const record = await getEscalation ( ctx , escalationId , resolvedCompanyId ) as {
1374+ const companyIdForLookup = embeddedCompanyId ?? await resolveCompanyId ( ctx ) ;
1375+ const record = await getEscalation ( ctx , escalationId , companyIdForLookup ) as {
13651376 escalationId : string ; companyId : string ; agentName : string ;
13661377 reason : string ; suggestedReply ?: string ; status : string ;
13671378 } | null ;
0 commit comments