A comprehensive API endpoint that receives transcript text, emails it to configured recipients, saves it to a database, generates an AI summary, and stores the summary in a final reports table.
The API sends emails directly to:
- Send transcript content via email to multiple recipients
- Save all transcripts to Supabase database for persistence
- Generate AI-powered summaries using OpenAI GPT-4o-mini
- Save summaries to final reports table
- Automatic timestamping of submissions
- HTML and plain text email formats
- Input validation and error handling
- Email delivery confirmation
- Robust error handling (each step continues even if previous steps fail)
The email recipients are configured in the code:
const EMAIL_RECIPIENTS = [
"sunny@getlightswitch.com",
"monica@getlightswitch.com"
];
Submit transcript content via email to all configured recipients and save to database.
Request Body:
{ "text": "Your transcript content here" }
Response:
{ "success": true, "message": "Message sent successfully to 2 recipients, saved to database, and processed with AI summary", "recipients": ["sunny@getlightswitch.com", "monica@getlightswitch.com"], "timestamp": "2024-01-01T12:00:00.000Z" }
When a transcript is submitted, the API performs the following steps in sequence:
- Email Delivery - Sends the transcript to configured recipients
- Transcript Storage - Saves the original transcript to the
transcripts
table - AI Summarization - Uses OpenAI GPT-4o-mini to generate a professional summary
- Final Report Storage - Saves the AI-generated summary to the
final_reports
table
Each step is designed to continue even if previous steps fail, ensuring maximum reliability.
Each email includes:
- Subject: "Text Submission - [timestamp]"
- HTML version: Formatted with styling and structure
- Plain text version: Simple text format
- Timestamp: When the submission was received
- Content: The submitted transcript text (preserves formatting)
curl -X POST https://your-val-url/api/submit \ -H "Content-Type: application/json" \ -d '{"text": "This is my transcript content"}'
The API returns appropriate HTTP status codes:
- 200: Success (email sent and saved to database)
- 400: Bad request (missing or invalid text)
- 500: Server error (email delivery failed)
All error responses include an error
field with a descriptive message.
- Update email recipients in the code (replace the example emails)
- Set up Supabase database with the required table structures (see Database Storage section)
- Configure environment variables (optional - falls back to hardcoded keys):
SUPABASE_SERVICE_KEY
OPENAI_API_KEY
- Test the API with a sample message
- Check recipient inboxes to confirm delivery
- Verify database entries in both Supabase tables
- Review AI-generated summaries in the final_reports table
The API uses two Supabase tables for data storage:
All original transcripts are saved to the transcripts
table:
- Body: The submitted transcript text content
- Email: Placeholder email field (set to 'transcript@api.submission')
- ID: UUID primary key (automatically generated)
- Created At: Timestamp of submission (automatically set by database)
- Updated At: Timestamp of last update (automatically set by database)
CREATE TABLE transcripts ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), email TEXT NOT NULL, body TEXT, created_at TIMESTAMPTZ DEFAULT NOW(), updated_at TIMESTAMPTZ DEFAULT NOW() );
AI-generated summaries are saved to the final_reports
table:
- Body: The AI-generated summary of the transcript
- OpenAI Thread ID: Unique identifier for the summary process
- ID: UUID primary key (automatically generated)
- Created At: Timestamp of summary creation (automatically set by database)
- Updated At: Timestamp of last update (automatically set by database)
CREATE TABLE final_reports ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), openai_thread_id TEXT NOT NULL, body TEXT NOT NULL, created_at TIMESTAMPTZ DEFAULT NOW(), updated_at TIMESTAMPTZ DEFAULT NOW() );
The API uses OpenAI's GPT-4o-mini model to generate professional summaries of transcripts. The AI is prompted to:
- Focus on key points and decisions made
- Identify action items and important details
- Maintain a professional and well-structured format
- Provide clear and concise summaries
- Model: GPT-4o-mini
- Max Tokens: 1000
- Temperature: 0.3 (for consistent, focused summaries)
- API Key: Configured via environment variable
OPENAI_API_KEY
The API uses the following configurations:
- Supabase Project ID: ffilnpatwtlzjrfbmvxk
- Supabase Service Role Key: Configured via environment variable
SUPABASE_SERVICE_KEY
- OpenAI API Key: Configured via environment variable
OPENAI_API_KEY
The API is designed with robust error handling:
- If email delivery fails, the entire request fails (emails are critical)
- If transcript database save fails, email delivery still succeeds
- If AI summarization fails, email delivery and transcript saving still succeed
- If final report save fails, all previous steps still succeed
This ensures that critical notifications (emails) are never missed, while optional features (AI processing) don't block the core functionality.
- Emails are sent using Val Town's built-in email service
- All configured recipients receive the same message simultaneously
- Delivery is typically instant
- Failed deliveries will return a 500 error