A simple API endpoint that receives text, emails it directly to configured recipients, and saves it to a Supabase database.
The API sends emails directly to:
- Send text 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)
All transcripts are automatically saved to a Supabase database with the following information:
- Content: The submitted text
- Created At: Timestamp of submission
- Email Recipients: List of recipients who received the email
The database table structure:
CREATE TABLE transcripts ( id SERIAL PRIMARY KEY, content TEXT NOT NULL, created_at TIMESTAMPTZ NOT NULL, email_recipients TEXT[] NOT NULL );
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.
Send text content via email to all configured recipients.
Request Body:
{ "text": "Your text content here" }
Response:
{ "success": true, "message": "Text emailed successfully to 2 recipients and saved to database", "recipients": ["sunny@getlightswitch.com", "monica@getlightswitch.com"], "timestamp": "2024-01-01T12:00:00.000Z" }
Get email service status and recipient information.
Response:
{ "message": "Email service is active", "recipients": ["sunny@getlightswitch.com", "monica@getlightswitch.com"], "info": "POST to this endpoint to send text via email" }
Each email includes:
- Subject: "New 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 text (preserves formatting)
curl -X POST https://your-val-url/api/text \ -H "Content-Type: application/json" \ -d '{"text": "Hello, this is my message!"}'
curl https://your-val-url/api/text
The API returns appropriate HTTP status codes:
- 200: Success (email sent)
- 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)
- Test the API with a sample message
- Check recipient inboxes to confirm delivery
- 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