FeaturesTemplatesShowcaseTownie
AI
BlogDocsPricing
Log inSign up
sunnyatlightswitch

sunnyatlightswitch

send-transcripts

Public
Like
send-transcripts
Home
Code
2
README.md
H
main.tsx
Branches
1
Pull requests
Remixes
History
Environment variables
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
Code
/
Search
main.tsx
https://sunnyatlightswitch--4c08aba44e4811f0928876b3cceeab13.web.val.run
README.md

Transcript Submission API with AI Summarization and Customer Notifications

A comprehensive API endpoint that receives transcript text, emails it to configured recipients, saves it to a database, generates an AI summary, stores the summary in a final reports table, and sends a notification email to the customer with their report link.

Recipients

The API sends emails directly to:

  • sunny@getlightswitch.com
  • monica@getlightswitch.com

Features

  • 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
  • Generate secure access tokens for each report
  • Send customer notification emails with report links using Resend
  • 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)

Configuration

The email recipients are configured in the code:

const EMAIL_RECIPIENTS = [ "sunny@getlightswitch.com", "monica@getlightswitch.com" ];

API Endpoint

POST /api/submit

Submit transcript content via email to all configured recipients and save to database.

Request Body:

{ "text": "Your transcript content here", "email": "user@example.com" }

Response:

{ "success": true, "message": "Message sent successfully to 2 recipients, saved to database, processed with AI summary, and customer notification sent", "recipients": ["sunny@getlightswitch.com", "monica@getlightswitch.com"], "timestamp": "2024-01-01T12:00:00.000Z", "email": "user@example.com" }

Processing Workflow

When a transcript is submitted, the API performs the following steps in sequence:

  1. Email Delivery - Sends the transcript to configured recipients
  2. Transcript Storage - Saves the original transcript to the transcripts table
  3. AI Summarization - Uses OpenAI GPT-4o-mini to generate a professional summary
  4. Final Report Storage - Saves the AI-generated summary to the final_reports table
  5. Token Generation - Creates a secure access token in the pricing_wizard_report_tokens table
  6. Customer Notification - Sends an email to the customer with their report link using Resend

Each step is designed to continue even if previous steps fail, ensuring maximum reliability.

Email Format

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
  • Submitter Email: The email address provided in the submission
  • Content: The submitted transcript text (preserves formatting)

Usage Example

Send transcript using curl:

curl -X POST https://your-val-url/api/submit \ -H "Content-Type: application/json" \ -d '{"text": "This is my transcript content", "email": "user@example.com"}'

Error Handling

The API returns appropriate HTTP status codes:

  • 200: Success (email sent and saved to database)
  • 400: Bad request (missing or invalid text/email)
  • 500: Server error (email delivery failed)

All error responses include an error field with a descriptive message.

Setup Instructions

  1. Update email recipients in the code (replace the example emails)
  2. Set up Supabase database with the required table structures (see Database Storage section)
  3. Configure environment variables (optional - falls back to hardcoded keys):
    • SUPABASE_SERVICE_KEY
    • OPENAI_API_KEY
    • RESEND_API_KEY
  4. Test the API with a sample message
  5. Check recipient inboxes to confirm delivery
  6. Verify database entries in both Supabase tables
  7. Review AI-generated summaries in the final_reports table
  8. Confirm customer notification emails are being sent via Resend

Database Storage

The API uses three Supabase tables for data storage:

Transcripts Table

All original transcripts are saved to the transcripts table:

  • Body: The submitted transcript text content
  • Email: The email address provided in the 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() );

Final Reports Table

AI-generated summaries are saved to the final_reports table:

  • Body: The AI-generated summary of the transcript
  • Email: The email address of the person who submitted the original transcript
  • OpenAI Thread ID: Unique identifier from OpenAI for the completion request
  • 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(), email TEXT NOT NULL, openai_thread_id TEXT NOT NULL, body TEXT NOT NULL, created_at TIMESTAMPTZ DEFAULT NOW(), updated_at TIMESTAMPTZ DEFAULT NOW() );

Pricing Wizard Report Tokens Table

Secure access tokens for each final report are saved to the pricing_wizard_report_tokens table:

  • Final Report ID: Foreign key reference to the final_reports table
  • Token: Cryptographically secure 64-character random token
  • Expires At: Expiration timestamp (set to 2 weeks from creation)
  • ID: UUID primary key (automatically generated)
  • Created At: Timestamp of token creation (automatically set by database)
  • Updated At: Timestamp of last update (automatically set by database)
CREATE TABLE pricing_wizard_report_tokens ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), final_report_id UUID NOT NULL REFERENCES final_reports(id), token TEXT NOT NULL, expires_at TIMESTAMPTZ NOT NULL, created_at TIMESTAMPTZ DEFAULT NOW(), updated_at TIMESTAMPTZ DEFAULT NOW() );

AI Summarization

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

Each AI-generated summary is associated with:

  • The original submitter's email address
  • The unique OpenAI completion ID for traceability

AI Configuration

  • Model: GPT-4o-mini
  • Max Tokens: 1000
  • Temperature: 0.3 (for consistent, focused summaries)
  • API Key: Configured via environment variable OPENAI_API_KEY
  • Completion Tracking: Each summary includes the OpenAI completion ID for audit purposes

Database Configuration

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

Error Handling

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
  • If token generation fails, all previous steps still succeed
  • If customer notification fails, all previous steps still succeed

This ensures that critical notifications (emails) are never missed, while optional features (AI processing, token generation, and customer notifications) don't block the core functionality.

Token Security

The API generates cryptographically secure access tokens for each final report:

  • Token Length: 64 characters
  • Character Set: Alphanumeric (A-Z, a-z, 0-9) for maximum entropy
  • Generation Method: Uses crypto.getRandomValues() for cryptographic security
  • Expiration: Tokens expire exactly 2 weeks (14 days) from creation
  • Uniqueness: Each token is statistically guaranteed to be unique

Email 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

Customer Notifications

After processing is complete, customers receive a professional notification email via Resend containing:

  • Professional Design: Clean, responsive HTML email template
  • Report Link: Direct link to their pricing report (/pricing-wizard-report?token=<TOKEN>)
  • Report Preview: Overview of what's included in their personalized report
  • Security Notice: Information about the 2-week expiration period
  • Branding: Sent from Lightswitch <hello@transactional.getlightswitch.ai>

Customer Email Features:

  • HTML and Text Versions: Ensures compatibility across all email clients
  • Responsive Design: Optimized for desktop and mobile viewing
  • Clear Call-to-Action: Prominent button to access the report
  • Professional Styling: Consistent with modern email design standards
  • Security Information: Clear expiration notice for transparency

Resend Configuration:

  • API Key: Configured via environment variable RESEND_API_KEY
  • From Address: Lightswitch <hello@transactional.getlightswitch.ai>
  • Delivery: Typically instant with high deliverability rates
  • Error Handling: Failures are logged but don't block the core workflow
HTTP
  • main.tsx
    sunnyatlightswitch--4c…13.web.val.run
Code
README.md
H
main.tsx
FeaturesVersion controlCode intelligenceCLI
Use cases
TeamsAI agentsSlackGTM
ExploreDocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareersBrandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.