• Townie
    AI
  • Blog
  • Docs
  • Pricing
Log inSign up
project logo

lightweight

findings

Remix of lightweight/findings-base
Public
Like
findings
Home
Code
7
_townie
7
backend
8
frontend
1
shared
1
.vtignore
deno.json
H
main.tsx
Branches
2
Pull requests
Remixes
History
Environment variables
8
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
/
backend
/
emails
/
README.md
Code
/
backend
/
emails
/
README.md
Search
8/28/2025
README.md

Emails

Email trigger handlers for processing incoming emails.

Files

  • pdf-attachments.ts - Processes emails with PDF attachments and uploads them to Notion database pages

Architecture

Email handlers follow the same separation of concerns as other parts of the application:

  • Email Handlers: Extract data from email objects and call controllers
  • Controllers: Business logic for processing email data
  • Services: Pure API calls to external systems (Notion, etc.)

PDF Attachments Handler

The pdf-attachments.ts handler:

  1. Deduplication Check: Uses precise time difference comparison to prevent duplicate processing
  2. Receives emails with PDF attachments
  3. Creates child pages in the Notion database specified by FINDINGS_TRANSCRIPTS_DB_ID
  4. Uploads each PDF to its own page using Notion's 3-step file upload API
  5. Continues processing even if individual uploads fail
  6. Returns detailed results for monitoring

Duplicate Email Protection

The handler implements idempotency using precise time difference comparison:

  • Hash Generation: from + subject (no time component)
  • Storage: Blob storage with key findings--transcripts--email--{hash}
  • Window: Same sender + subject within 3 minutes = duplicate
  • Precision: Exact time difference calculation (not epoch blocks)
  • Behavior: Duplicates are logged with time difference and skipped
  • Updates: Legitimate emails (>3 minutes apart) update the stored timestamp

This prevents duplicate Notion records when email providers retry delivery while allowing legitimate re-sends after 3 minutes.

Page Properties

Each PDF attachment creates a page with:

  • Name: Extracted interviewee name from filename (content in parentheses)
  • Filename: Complete original filename from email attachment
  • PDF: Uploaded file using Notion's file upload API
  • Status: Upload progress tracking

Status Progression

  • "Uploading...": Initial status when page is created
  • "Uploaded": File successfully uploaded and attached to page
  • "Upload error": File upload failed (page still exists for retry)

Filename Processing

The handler extracts interviewee names using pattern matching:

  • Pattern: (Name) - Content inside first parentheses becomes the page title
  • Example: "Interview (John Doe) - 2025_01_01.pdf" → Name: "John Doe"
  • Fallback: If no parentheses found, uses filename without extension

Environment Variables

  • FINDINGS_TRANSCRIPTS_DB_ID - Notion database ID where pages will be created
  • NOTION_API_KEY - Notion API key for authentication

Process Flow

  1. Email Reception: Handler receives email with attachments
  2. PDF Filtering: Only processes PDF attachments (by extension or MIME type)
  3. Page Creation: Creates a new page in the target database for each PDF
  4. File Upload: Uses Notion's 3-step upload process:
    • Create upload object
    • Upload file contents
    • Attach file to page
  5. Status Updates: Updates page status based on upload success/failure
  6. Error Handling: Continues processing even if individual steps fail
  7. Response: Returns detailed processing results
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.