A simple API endpoint that receives transcript text, emails it to configured recipients, and saves it to a Supabase database.
The API sends emails directly to:
- Send transcript content via email to multiple recipients
- Save all transcripts to Supabase database for persistence
- Automatic timestamping of submissions
- HTML and plain text email formats
- Input validation and error handling
- Email delivery confirmation
- Database storage with error handling (email delivery continues even if database fails)
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 and saved to database", "recipients": ["sunny@getlightswitch.com", "monica@getlightswitch.com"], "timestamp": "2024-01-01T12:00:00.000Z" }
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 structure (see Database Storage section)
- Configure environment variable
SUPABASE_SERVICE_KEY
(optional - falls back to hardcoded key) - Test the API with a sample message
- Check recipient inboxes to confirm delivery
- Verify database entries in Supabase dashboard
All transcripts are automatically saved to a Supabase database in the transcripts
table with the following information:
- 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)
The database table structure:
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() );
The API uses the following Supabase configuration:
- Project ID: ffilnpatwtlzjrfbmvxk
- Service Role Key: Configured via environment variable
SUPABASE_SERVICE_KEY
If the database save fails, the email delivery will still succeed. The API prioritizes email delivery over database storage to ensure critical notifications are not missed.
- 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