Replace hardcoded notification messages with a flexible template system that allows users to customize notification content per event type, with provider-specific formatting support.
notification_templatesCREATE TABLE notification_templates (
id INTEGER PRIMARY KEY,
event_type VARCHAR(50) NOT NULL, -- print_start, print_complete, etc.
name VARCHAR(100) NOT NULL, -- User-friendly name
title_template TEXT NOT NULL, -- Template for notification title
body_template TEXT NOT NULL, -- Template for notification body
is_default BOOLEAN DEFAULT 0, -- System default (non-deletable)
created_at DATETIME,
updated_at DATETIME
);
Event Types:
print_startprint_completeprint_failedprint_stoppedprint_progressprinter_offlineprinter_errorfilament_lowmaintenance_duetest (for test notifications)Variables use {variable_name} syntax (Python format strings).
| Event | Variables |
|---|---|
print_start |
{printer}, {filename}, {estimated_time} |
print_complete |
{printer}, {filename}, {duration}, {filament_grams} |
print_failed |
{printer}, {filename}, {duration}, {reason} |
print_stopped |
{printer}, {filename}, {duration} |
print_progress |
{printer}, {filename}, {progress}, {remaining_time} |
printer_offline |
{printer} |
printer_error |
{printer}, {error_type}, {error_detail} |
filament_low |
{printer}, {slot}, {remaining_percent}, {color} |
maintenance_due |
{printer}, {items} (formatted list) |
test |
{app_name} |
{timestamp} - Current date/time{app_name} - "BambuTrack"Pre-seeded templates for each event (marked is_default=True):
print_start:
title: "Print Started"
body: "{printer}: {filename}\nEstimated: {estimated_time}"
print_complete:
title: "Print Completed"
body: "{printer}: {filename}\nTime: {duration}\nFilament: {filament_grams}g"
print_failed:
title: "Print Failed"
body: "{printer}: {filename}\nTime: {duration}\nReason: {reason}"
print_stopped:
title: "Print Stopped"
body: "{printer}: {filename}\nTime: {duration}"
print_progress:
title: "Print {progress}% Complete"
body: "{printer}: {filename}\nRemaining: {remaining_time}"
printer_offline:
title: "Printer Offline"
body: "{printer} has disconnected"
printer_error:
title: "Printer Error: {error_type}"
body: "{printer}\n{error_detail}"
filament_low:
title: "Filament Low"
body: "{printer}: Slot {slot} at {remaining_percent}%"
maintenance_due:
title: "Maintenance Due"
body: "{printer}:\n{items}"
test:
title: "BambuTrack Test"
body: "This is a test notification. If you see this, notifications are working!"
The template system supports provider-specific formatting via a simple approach:
*bold*)The notification service will:
Create model backend/app/models/notification_template.py
Create schemas backend/app/schemas/notification_template.py
Add migration in backend/app/core/database.py
Create API routes backend/app/api/routes/notification_templates.py
GET /api/v1/notification-templates - List all templatesGET /api/v1/notification-templates/{id} - Get single templatePUT /api/v1/notification-templates/{id} - Update templatePOST /api/v1/notification-templates/{id}/reset - Reset to defaultGET /api/v1/notification-templates/variables - List available variables per eventPOST /api/v1/notification-templates/preview - Preview template with sample dataUpdate notification service backend/app/services/notification_service.py
Register routes in backend/app/main.py
Add API client methods frontend/src/api/client.ts
Create template editor component frontend/src/components/NotificationTemplateEditor.tsx
Update SettingsPage frontend/src/pages/SettingsPage.tsx
+--------------------------------------------------+
| Message Templates |
| Customize notification messages for each event |
+--------------------------------------------------+
| |
| +----------------+ +----------------+ |
| | Print Started | | Print Complete | ... |
| | "Print Started"| | "Print Compl..." | |
| | [Edit] | | [Edit] | |
| +----------------+ +----------------+ |
| |
+--------------------------------------------------+
+--------------------------------------------------+
| Edit Template: Print Complete [X] |
+--------------------------------------------------+
| Title: |
| [Print Completed_________________________] |
| |
| Body: |
| +----------------------------------------------+ |
| | {printer}: {filename} | |
| | Time: {duration} | |
| | Filament: {filament_grams}g | |
| +----------------------------------------------+ |
| |
| Available Variables: |
| [+printer] [+filename] [+duration] [+filament] |
| |
| Preview: |
| +----------------------------------------------+ |
| | Title: Print Completed | |
| | Body: Bambu X1C: Benchy.3mf | |
| | Time: 1h 23m | |
| | Filament: 15.2g | |
| +----------------------------------------------+ |
| |
| [Reset to Default] [Cancel] [Save] |
+--------------------------------------------------+
| File | Action |
|---|---|
backend/app/models/notification_template.py |
Create |
backend/app/schemas/notification_template.py |
Create |
backend/app/api/routes/notification_templates.py |
Create |
backend/app/core/database.py |
Modify (add migration + seeding) |
backend/app/models/__init__.py |
Modify (export new model) |
backend/app/services/notification_service.py |
Modify (use templates) |
backend/app/main.py |
Modify (register routes) |
frontend/src/api/client.ts |
Modify (add API methods + types) |
frontend/src/components/NotificationTemplateEditor.tsx |
Create |
frontend/src/pages/SettingsPage.tsx |
Modify (add templates section) |
notification_language setting can be removed later (templates replace i18n)