This system provides multi-language email notifications for booking events using Supabase Edge Functions.
bookingsystem-dbtrigger/
├── bookingnotifications.ts # Main Edge Function
├── language-utils.ts # Language detection and template utilities
├── templates/
│ ├── english.ts # English email templates
│ ├── french.ts # French email templates
│ └── dutch.ts # Dutch email templates
├── email_triggers.sql # Database triggers
└── README.md # This file
-
Language Source: The system reads the
languageattribute from the booking record passed by the database trigger. -
Language Detection: The
detectLanguage()function inlanguage-utils.tsprocesses the language code:- Handles various formats (e.g., 'en', 'en-US', 'fr-FR', 'nl-NL')
- Defaults to English if no language is specified
- Maps language codes to supported languages:
en*→ Englishfr*→ Frenchnl*ordu*→ Dutch
-
Template Selection: Based on the detected language, the appropriate template is loaded and used for email generation.
- English (
en) - Default - French (
fr) - Dutch (
nl)
Each language template supports two types of notifications:
Sent when a new booking is created (triggered by database INSERT).
Sent when a booking is approved (triggered by database UPDATE when approved_at changes from NULL).
Each language template exports an EmailTemplate interface with:
interface EmailTemplate {
newBooking: {
subject: (title: string) => string;
body: (record: any, formattedStartDate: string, formattedStartTime: string, formattedEndTime: string) => string;
};
confirmedBooking: {
subject: (title: string) => string;
body: (record: any, formattedStartDate: string, formattedStartTime: string, formattedEndTime: string) => string;
};
}The system automatically:
- Receives booking data from the database trigger
- Extracts the
languagefield from the booking record - Detects the appropriate language template
- Generates localized email content
- Sends the email to the office manager and CCs the booking creator
To add support for a new language:
- Create a new template file in
/templates/(e.g.,spanish.ts) - Implement the
EmailTemplateinterface with translated content - Update
language-utils.tsto include the new language mapping - Add the language to the
SupportedLanguagetype
The system requires these environment variables:
EMAIL_HOST- SMTP server hostnameEMAIL_PORT- SMTP server port (default: 587)EMAIL_USER- SMTP usernameEMAIL_PASS- SMTP passwordOFFICE_MANAGER_EMAIL- Recipient email for notificationsTRIGGER_AUTH- Authentication token for webhook security
- Fulfill email credentials