# Call Transcripts Feature Investigation

**Date:** January 30, 2026  
**Investigator:** Architect Agent  
**Request:** Michael wants to know:
1. Where are call transcripts viewable in the app?
2. Does the AI do a summary of calls?
3. Does the AI update lead intel from call transcripts?

---

## Executive Summary

| Feature | Status | Notes |
|---------|--------|-------|
| Transcript Storage | ✅ EXISTS | Stored in `communications.metadata.transcript` |
| AI Call Summary | ✅ EXISTS | Full GPT-4o analysis with key points, sentiment, buying signals |
| Lead Intel Update | ✅ EXISTS | Auto-updates dossier, score, status from transcript |
| **Transcript Viewing UI** | ❌ MISSING | Can only play recording - no text view of past transcripts |

**Key Gap:** Transcripts are captured and analyzed by AI, but there's **no UI to view past call transcripts**. Users can only play back recordings - the actual transcript text is hidden in metadata.

---

## Detailed Findings

### 1. Where Are Call Transcripts Viewable?

**Answer: Limited visibility - only during call logging, not after**

#### Where Transcripts ARE Visible:
| Location | What's Shown | File |
|----------|--------------|------|
| CallOutcomeSheet | Auto-populated notes from transcript | `admin/src/components/CallOutcomeSheet.jsx:98-100` |
| PostCallSummarySheet | AI summary of transcript | `admin/src/components/PostCallSummarySheet.jsx` |
| LiveCopilot | Real-time transcription during call | `admin/src/components/LiveCopilot.jsx` |

#### Where Transcripts ARE NOT Visible:
| Location | What's Shown Instead | Gap |
|----------|---------------------|-----|
| Lead Profile - History | Only `ai_summary.summary` OR `outcome` | No transcript text |
| Lead Profile - Recording | Play button only | Audio, not text |
| Dossier | `call_summaries` (key points) | Not the full transcript |

#### Storage Locations:
```
communications.metadata = {
  transcript: "Full call transcript text...",  // ← NOT displayed
  ai_summary: {
    summary: "Brief summary...",  // ← Displayed in history
    key_points: [...],
    sentiment: "positive",
    ...
  },
  recording_url: "https://...",  // ← Used for playback button
}

lead_dossier.call_summaries = [
  { date, duration, outcome, key_points, next_steps, mood }  // ← NOT displayed
]
```

---

### 2. Does AI Do a Summary of Calls?

**Answer: ✅ YES - Fully implemented and comprehensive**

#### Summary Generation Flow:
```
Call Ends
    ↓
CallContext.jsx → generateAutoSummary()
    ↓
POST /api/ai/post-call-summary
    ↓
generatePostCallSummary() in src/services/ai.js:97-151
    ↓
Returns JSON with:
  - summary (2-3 sentences)
  - key_points (array)
  - sentiment (positive/neutral/negative)
  - sentiment_score (0-1)
  - outcome (interested/callback/not_now/converted/lost)
  - objections_raised (array)
  - buying_signals (array with phrase, signal_type, timestamp)
  - buying_signal_score (0-100)
  - next_step (recommended action)
  - follow_up_date
  - score_adjustment (-20 to +30)
  - status_recommendation
  - coaching_note
```

#### Code Location:
- **Backend:** `src/services/ai.js` lines 97-151
- **Frontend trigger:** `admin/src/context/CallContext.jsx` lines 170-195
- **Manual UI:** `admin/src/components/PostCallSummarySheet.jsx`

---

### 3. Does AI Update Lead Intel from Call Transcripts?

**Answer: ✅ YES - Multiple automatic updates occur**

#### 3.1 Auto-Research from Transcript
**Location:** `src/routes/calls.js:247-260`
```javascript
// Triggered when transcript >= 50 chars
if (transcript && transcript.length >= 50) {
  perplexityService.autoResearchFromTranscript(leadId, transcript)
}
```

**What it does:** (`src/services/perplexity.js:387-480`)
- Extracts company names mentioned
- Researches companies via Perplexity
- Extracts intel nuggets (project details, needs, constraints)
- Stores as lead notes with `[Auto-Extracted Intel]` tag

#### 3.2 Lead Dossier Update
**Location:** `src/routes/calls.js:308-357`
```javascript
// Updates lead_dossier with call summary
await supabase.from('lead_dossier').upsert({
  lead_id: leadId,
  call_summaries: [...currentSummaries, newSummary],
  current_status: {
    stage: leadUpdates.status,
    temperature: outcome === 'interested' ? 'hot' : 'warm',
    last_contact: new Date(),
    next_action: aiSummary?.next_step,
    follow_up_date: followUpAt
  }
});
```

#### 3.3 Lead Score & Status Update
**Location:** `src/routes/calls.js:164-172`
```javascript
// Apply AI-recommended score adjustment
if (aiSummary?.score_adjustment) {
  const newScore = Math.max(0, Math.min(100, lead.score + aiSummary.score_adjustment));
  leadUpdates.score = newScore;
}

// Apply AI-recommended status
if (!leadUpdates.status && aiSummary?.status_recommendation) {
  leadUpdates.status = aiSummary.status_recommendation;
}
```

#### 3.4 AI Call Scoring
**Location:** `src/routes/calls.js:262-274`
```javascript
// Score call quality (fire and forget)
const callScore = await scoreCall(comm, transcript);
if (callScore) {
  await saveCallScore(comm.id, leadId, userId, callScore, outcome, durationSeconds);
}
```

---

## What's Missing

### 1. Transcript Viewer UI (HIGH PRIORITY)
**Problem:** Users cannot view past call transcripts - they're stored but hidden.

**Current state:**
- Lead Profile shows "Last Contact" with summary only
- History section shows 5 items with summary/outcome only
- Recording button plays audio but doesn't show text

**Impact:** 
- Sales reps can't review what was said in previous calls
- Managers can't audit call quality by reading transcripts
- Context is lost when different reps handle the same lead

### 2. Dossier Call Summaries Not Displayed
**Problem:** `lead_dossier.call_summaries` is populated but not shown in UI.

**Current state:**
- `BusinessIntelCard.jsx` shows business intel from dossier
- `IntelSummaryCard.jsx` shows company/person research
- **No card for call_summaries**

### 3. No Dedicated Call History View
**Problem:** Only 5 recent communications shown, no expandable history.

---

## Recommendations

### Option A: Quick Fix (1-2 hours)
Add transcript toggle to existing communication history:
- Add "Show Transcript" expandable section to each call item
- Display `comm.metadata.transcript` when expanded

### Option B: Full Feature (4-6 hours)
Create dedicated "Call History" tab on Lead Profile:
- List all calls with date, duration, outcome
- Expandable transcript + AI summary for each
- Search/filter by keyword
- Display dossier call_summaries

### Option C: Comprehensive (8-12 hours)
Full call review system:
- Dedicated `/leads/:id/calls` page
- Transcript with audio sync (play and read)
- Keyword highlighting
- Manager notes/feedback
- Call quality scores display

---

## Files Involved

### Backend
| File | Transcript Role |
|------|-----------------|
| `src/routes/calls.js` | Stores transcript, triggers AI analysis, updates dossier |
| `src/services/ai.js` | Generates summary, extracts intel |
| `src/services/perplexity.js` | Auto-researches from transcript content |
| `src/routes/dossier.js` | Stores/retrieves call summaries |

### Frontend
| File | Current Role | Missing |
|------|--------------|---------|
| `LeadProfile.jsx` | Shows summary in history | Transcript display |
| `CallOutcomeSheet.jsx` | Pre-populates from transcript | - |
| `PostCallSummarySheet.jsx` | Displays AI summary | - |
| `BusinessIntelCard.jsx` | Shows business intel | Call summaries from dossier |

### Database
| Table | Column | Contains |
|-------|--------|----------|
| `communications` | `metadata->transcript` | Full transcript text |
| `communications` | `metadata->ai_summary` | AI analysis |
| `communications` | `metadata->recording_url` | Twilio recording URL |
| `lead_dossier` | `call_summaries` | Key points per call (not displayed) |

---

## Conclusion

The call transcripts feature is **80% complete**:
- ✅ Transcription (Deepgram/Web Speech API)
- ✅ Storage (communications.metadata.transcript)
- ✅ AI summarization (comprehensive)
- ✅ Intel extraction (auto-research, dossier updates)
- ✅ Score/status updates (automatic)
- ❌ **Viewing past transcripts** (UI missing)
- ❌ **Dossier call summaries** (not displayed)

**Recommended next step:** Option A (Quick Fix) - add expandable transcript viewer to Lead Profile history section.
