Overview
GitaChat’s daily verse feature delivers a personalized verse from the Bhagavad Gita every day. The intelligent selection algorithm ensures you receive verses you haven’t seen before, providing a structured way to gradually explore all 700 verses.How Daily Verse Works
Smart Selection
Algorithm prioritizes verses you haven’t seen yet
Web Access
Fetch your daily verse through the API anytime
Email Delivery
Subscribe to receive verses via email at 8 AM in your timezone
Daily Caching
Same verse throughout the day for consistent reflection
Daily Verse API
Get Daily Verse
Fetch the verse of the day for the authenticated user. Endpoint:GET /api/daily
Authentication: Required (Clerk)
Rate Limit: 10 requests per minute per client
Query Parameters (Optional):
tz: Timezone (e.g., “America/New_York”, “Asia/Kolkata”). Defaults to “UTC”
chapter: Chapter number (1-18)verse: Verse numbertranslation: English translation of the versesummarized_commentary: AI-generated explanationcached: Boolean indicating if this was retrieved from cache (true) or newly generated (false)
Email Subscription API
Check Subscription Status
Check if the user is subscribed to daily verse emails. Endpoint:GET /api/email-subscription
Authentication: Required (Clerk)
Rate Limit: 10 requests per minute per client
Response:
Subscribe to Daily Emails
Sign up to receive daily verse emails at 8 AM in your timezone. Endpoint:POST /api/email-subscription
Authentication: Required (Clerk)
Rate Limit: 10 requests per minute per client
Request Body:
- Must be a valid IANA timezone identifier
- Examples: “America/Los_Angeles”, “Europe/London”, “Asia/Tokyo”
- Defaults to “UTC” if not provided
- Uses Clerk to retrieve user’s primary email address
- Generates unique unsubscribe token for each user
- Upserts subscription (creates new or reactivates existing)
- Sets
is_activeto true and recordssubscribed_attimestamp
Unsubscribe from Daily Emails
Stop receiving daily verse emails. Endpoint:DELETE /api/email-subscription
Authentication: Required (Clerk)
Rate Limit: 10 requests per minute per client
Success Response (200):
is_active to false without deleting the subscription record.
Daily Verse Selection Algorithm
The intelligent verse selection algorithm ensures a varied and complete exploration of the Bhagavad Gita:Selection Process
- Check Cache: Look for today’s cached verse (based on timezone)
- Return Cache: If found, return immediately (ensures consistency)
- Fetch History: Retrieve all verses you’ve previously seen
- Filter Unseen: Identify verses you haven’t encountered yet
- Random Selection: Pick randomly from unseen verses
- Fallback: If all verses seen, pick randomly from all verses
- Fetch Details: Get translation and commentary from backend
- Cache Result: Store in database for the rest of the day
- Gradual Coverage: You’ll eventually see all 700 verses
- No Repetition: Prioritizes new verses until you’ve seen them all
- Fair Distribution: Random selection ensures variety
- Consistent Experience: Same verse all day for focused reflection
Email Delivery System
The email delivery is handled by a cron job that runs hourly. Endpoint:POST /api/daily-email
Authentication: CRON_SECRET bearer token (not for public use)
Delivery Process
Timezone Detection
Identifies timezones where it’s currently 8 AM
Subscriber Query
Fetches active subscribers in those timezones
Verse Generation
Generates personalized daily verse for each user
Email Sending
Sends formatted emails via Resend service
Email Content
Each daily verse email includes:- Subject Line: Customized for the verse
- Verse Text: Full Sanskrit verse and translation
- Commentary: Summarized explanation of the teaching
- Chapter Reference: Chapter and verse number
- Unsubscribe Link: Easy one-click unsubscribe
Supported Timezones
The system supports 30+ major timezones worldwide: Americas: Honolulu, Anchorage, Los Angeles, Denver, Chicago, New York, Toronto, Vancouver, Phoenix, Sao Paulo Europe: London, Paris, Berlin, Moscow, Amsterdam, Rome, Madrid, Stockholm, Reykjavik Asia: Dubai, Kolkata, Bangkok, Singapore, Tokyo, Shanghai, Hong Kong, Seoul Oceania: Sydney, Melbourne, AucklandData Storage
Daily Verse Cache Table
| Column | Type | Description |
|---|---|---|
user_id | String | Clerk user identifier |
date | Date | Date string (YYYY-MM-DD) in user’s timezone |
chapter | Integer | Chapter number |
verse | Integer | Verse number |
translation | Text | Verse translation |
summarized_commentary | Text | Commentary |
matched_theme | Text | Theme that matched (nullable) |
user_id + date ensures one verse per day per user.
Email Subscribers Table
| Column | Type | Description |
|---|---|---|
user_id | String | Clerk user identifier (unique) |
email | String | User’s email address |
timezone | String | IANA timezone identifier |
unsubscribe_token | UUID | Unique token for unsubscribe link |
is_active | Boolean | Whether subscription is active |
subscribed_at | Timestamp | When user subscribed |
last_email_sent_at | Timestamp | Last email delivery time |
Implementation Files
/api/daily/route.ts
Web API for fetching daily verse on demand
/api/email-subscription/route.ts
Subscription management (GET, POST, DELETE)
/api/daily-email/route.ts
Cron job handler for automated email delivery
Backend /api/verse
Fetches verse translation and commentary
Rate Limiting
Different rate limits for different operations:| Endpoint | Rate Limit | Purpose |
|---|---|---|
| GET /api/daily | 10 req/min | Normal daily verse fetching |
| GET /api/email-subscription | 10 req/min | Check subscription status |
| POST /api/email-subscription | 10 req/min | Subscribe to emails |
| DELETE /api/email-subscription | 10 req/min | Unsubscribe from emails |
Error Handling
Common error scenarios:| Error | Status | Description |
|---|---|---|
| Unauthorized | 401 | User not logged in |
| No email found | 400 | User has no email address (subscription only) |
| Invalid timezone | 400 | Timezone not recognized |
| Too many requests | 429 | Rate limit exceeded |
| Database not configured | 503 | Supabase connection unavailable |
| Failed to fetch verse | 500 | Backend verse API error |
Best Practices
Daily Verse Tips
- Set Your Timezone: Ensure accurate delivery time for emails
- Consistent Reflection: Access your daily verse at the same time each day
- Add Notes: Write reflections on your daily verse
- Bookmark Favorites: Save daily verses that resonate deeply
- Check Once: The verse is cached, so it’s the same all day—take time to reflect
Privacy & Unsubscribe
Easy Unsubscribe
Every email includes a one-click unsubscribe link
Data Control
Unsubscribing sets is_active to false, preserving preferences
Email Privacy
Your email is only used for daily verse delivery
Token Security
Unsubscribe tokens are unique UUIDs per user
Integration with History
The daily verse selection algorithm uses your search history to ensure variety:- Queries
query_historytable for all verses you’ve searched - Creates a “seen verses” set from your history
- Filters these out when selecting today’s verse
- Ensures you see fresh content you haven’t explored before
Cron Job Monitoring
The daily email cron job returns detailed metrics:sent: Number of emails successfully deliveredtotal: Total number of subscribers in target timezonestimezones: List of timezones where it’s currently 8 AMerrors: Array of error messages (only present if errors occurred)