Skip to main content

AI Functions

summarize-sales-call

Uses Claude AI (Anthropic) to analyze sales call transcripts and extract structured intelligence. This function is the core AI component of the sales pipeline.

Endpoint

POST /summarize-sales-call

Input

interface SummarizeRequest {
callId: string; // UUID of the sales_calls record
}

Flow

Claude API Call

const response = await fetch('https://api.anthropic.com/v1/messages', {
method: 'POST',
headers: {
'x-api-key': Deno.env.get('ANTHROPIC_API_KEY')!,
'anthropic-version': '2023-06-01',
'content-type': 'application/json',
},
body: JSON.stringify({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
system: SYSTEM_PROMPT,
messages: [
{ role: 'user', content: transcript }
],
}),
});

System Prompt

The system prompt instructs Claude to analyze the transcript as a sales call for a legal recruitment intelligence company, and return a structured JSON response:

You are analyzing a sales call transcript for 1 Hour Recruitment,
a market intelligence company serving legal search firms.

Analyze the transcript and return a JSON object with these fields:
- disposition: one of (no_answer, voicemail, gatekeeper, connected,
conversation, meeting_booked, not_interested)
- key_points: array of 3-5 bullet points summarizing the conversation
- sentiment: positive, neutral, or negative
- action_items: array of recommended next steps
- engagement_assessment: brief assessment of prospect engagement
- conversation_quality: brief assessment of conversation quality
- interest_level: high, medium, low, or none
- objections: array of objections raised (empty if none)
- buying_signals: array of positive indicators (empty if none)

Return ONLY valid JSON. No markdown, no explanation.

Output Schema

The ai_summary JSONB stored on sales_calls:

interface AISummary {
disposition: string;
key_points: string[];
sentiment: 'positive' | 'neutral' | 'negative';
action_items: string[];
engagement_assessment: string;
conversation_quality: string;
interest_level: 'high' | 'medium' | 'low' | 'none';
objections: string[];
buying_signals: string[];
}

Auto-Updates to Prospect

After summarization, the function updates the linked sales_prospects record:

AI OutputProspect Update
interest_level: "high" + buying_signals presentengagement_level = 'interested' or 'in_conversation'
disposition: "meeting_booked"engagement_level = 'in_conversation'
disposition: "not_interested"engagement_level unchanged (manual decision)
action_items with date mentionsnext_follow_up_at set to inferred date

Trigger Conditions

This function is triggered in two ways:

  1. Automatic -- The ghl-sales-webhook function invokes it when a call transcript exceeds 100 characters.
  2. Manual -- A user clicks the "Summarize" button in the UI (SummarizeCallButton.tsx), or pastes a transcript via PasteTranscriptDialog.tsx.
Transcript Length Threshold

Transcripts shorter than 100 characters are not summarized automatically. These are typically voicemails, wrong numbers, or very brief interactions where AI analysis would not add value.

Required Secret

SecretValue
ANTHROPIC_API_KEYAnthropic API key (set via supabase secrets set)

Error Handling

  • If Claude returns invalid JSON, the function logs the error and stores a fallback summary
  • If the API call fails (rate limit, network), the function returns an error without updating the record
  • The function is idempotent -- calling it again overwrites the previous ai_summary

Cost

Each summarization call costs approximately $0.003-$0.01 depending on transcript length (using Claude Sonnet pricing).