mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 14:25:02 +00:00
Email Template Manager Plugin - Phase 6
Comprehensive email template management workflow plugin for MetaBuilder email client. Provides template creation, variable interpolation, team sharing, and usage analytics.
Features
Template Lifecycle Management
- Create: Save email templates with rich content (plain text + HTML)
- Update: Modify templates with version tracking
- Delete: Soft-delete templates for recovery
- Recover: Restore accidentally deleted templates
- Get: Retrieve single template by ID
- List: Browse templates with filtering and pagination
Template Variables & Interpolation
- Standard Variables:
{{name}},{{date}},{{recipient}} - Custom Variables: Auto-detected from template content
- Auto-Expansion: Substitute variables on template usage
- Defaults & Fallbacks: Use default values for missing variables
- Type System: Support for text, date, number, email types
Template Categories
responses- Standard reply templatesgreetings- Opening lines and salutationssignatures- Email signaturescustom- User-defined templates
Team Sharing & Collaboration
- Share Templates: Grant view/edit/admin permissions
- Access Control: Fine-grained permission levels
- Audit Logging: Track all sharing changes
- Public Templates: Make templates available to all users
Usage Analytics
- Track Usage: Record template expansions with variable values
- Usage Statistics: Count total uses and last used timestamp
- Variable Analytics: Identify most frequently used variables
- Performance Insights: Analyze template effectiveness
Data Isolation
- Multi-Tenant: Full tenant isolation with ACL
- Soft Delete: Preserve data for recovery without hard deletion
- Version Control: Track template changes over time
Configuration
Create Template
const config: TemplateManagerConfig = {
action: 'create',
accountId: 'acc-123456',
template: {
name: 'Welcome Message',
subject: 'Welcome to {{company}}, {{name}}!',
bodyText: 'Dear {{name}},\n\nWelcome to {{company}}...',
bodyHtml: '<p>Dear {{name}},</p><p>Welcome to {{company}}...</p>',
category: 'greetings',
tags: ['welcome', 'new-users'],
isPublic: false
}
};
Expand Template
const config: TemplateManagerConfig = {
action: 'expand',
accountId: 'acc-123456',
templateId: 'tmpl-abc123',
variableValues: {
name: 'John Doe',
company: 'Acme Corp',
date: '2026-01-30'
}
};
Share Template
const config: TemplateManagerConfig = {
action: 'share',
accountId: 'acc-123456',
templateId: 'tmpl-abc123',
shareWithUserId: 'user-002',
sharePermission: 'edit' // 'view' | 'edit' | 'admin'
};
List Templates with Filtering
const config: TemplateManagerConfig = {
action: 'list',
accountId: 'acc-123456',
filters: {
category: 'greetings',
searchText: 'welcome',
isPublic: false,
sharedOnly: false,
includeDeleted: false
},
pagination: {
page: 1,
pageSize: 20
}
};
Get Usage Statistics
const config: TemplateManagerConfig = {
action: 'get-usage-stats',
accountId: 'acc-123456',
templateId: 'tmpl-abc123'
};
Response Structure
Template Creation Response
{
status: 'success',
output: {
action: 'create',
template: {
templateId: 'tmpl-xyz789',
accountId: 'acc-123456',
tenantId: 'tenant-001',
ownerId: 'user-001',
name: 'Welcome Message',
subject: 'Welcome to {{company}}, {{name}}!',
bodyText: 'Dear {{name}},...',
bodyHtml: '<p>Dear {{name}},...</p>',
category: 'greetings',
variables: [
{
name: 'name',
placeholder: '{{name}}',
description: 'Recipient full name',
type: 'text',
required: false,
examples: ['John Smith', 'Jane Doe']
},
{
name: 'company',
placeholder: '{{company}}',
description: 'Custom variable: company',
type: 'text',
required: false
}
],
tags: ['welcome', 'new-users'],
isPublic: false,
sharedWith: [],
usageCount: 0,
createdAt: 1704067200000,
updatedAt: 1704067200000,
isDeleted: false,
version: 1
},
success: true,
message: 'Template "Welcome Message" created successfully',
stats: {
operationDuration: 15,
itemsAffected: 1,
storageUsed: 1248
}
}
}
Template Expansion Response
{
status: 'success',
output: {
action: 'expand',
expandedTemplate: {
templateId: 'tmpl-xyz789',
subject: 'Welcome to Acme Corp, John Doe!',
bodyText: 'Dear John Doe,\n\nWelcome to Acme Corp...',
bodyHtml: '<p>Dear John Doe,</p><p>Welcome to Acme Corp...</p>',
variables: {
name: 'John Doe',
company: 'Acme Corp',
date: '2026-01-30'
},
missingVariables: [],
errors: []
},
success: true,
message: 'Template "Welcome Message" expanded successfully',
stats: {
operationDuration: 8,
itemsAffected: 1,
storageUsed: 892
}
}
}
Usage Statistics Response
{
status: 'success',
output: {
action: 'get-usage-stats',
usageStats: {
templateId: 'tmpl-xyz789',
totalUsage: 156,
lastUsedAt: 1704153600000,
averageVariableCount: 3.2,
topVariables: [
{ name: 'name', usageCount: 156 },
{ name: 'company', usageCount: 145 },
{ name: 'date', usageCount: 98 },
{ name: 'recipient', usageCount: 67 },
{ name: 'customVar', usageCount: 23 }
]
},
success: true,
stats: {
operationDuration: 12,
itemsAffected: 1,
storageUsed: 0
}
}
}
Variable Reference
Standard Variables
| Variable | Placeholder | Type | Description | Example |
|---|---|---|---|---|
| name | {{name}} |
text | Recipient full name | John Smith |
| date | {{date}} |
date | Current date (ISO format) | 2026-01-30 |
| recipient | {{recipient}} |
Recipient email address | john@example.com |
Custom Variables
Extract automatically from template content. Examples:
{{company}}- Organization name{{department}}- Department identifier{{projectName}}- Project identifier{{deadline}}- Deadline date- Any custom placeholder in format
{{varName}}
Actions
Template Lifecycle
create- Create new templateupdate- Update existing templatedelete- Soft-delete templaterecover- Restore deleted templateget- Retrieve single templatelist- List templates with filters
Template Operations
expand- Expand template with variable substitutionshare- Share template with another userunshare- Remove sharing from usertrack-usage- Record template expansionget-usage-stats- Get usage analytics
Permission Model
Ownership
- Owner: User who created the template
- Actions: Full control (create, read, update, delete, share)
Sharing Permissions
view- Read-only access, can expand but not editedit- Can modify template content and expandadmin- Full control including sharing with others
Access Control
- Public templates available to all authenticated users
- Private templates only to owner and explicitly shared users
- Multi-tenant isolation enforced on all queries
Best Practices
Template Design
- Use descriptive template names
- Add variables for frequently changing content
- Provide HTML alternative for better rendering
- Include tags for easier discovery
Variable Naming
- Use camelCase for custom variables:
{{firstName}} - Use clear, self-documenting names
- Avoid special characters in variable names
Sharing Strategy
- Start with 'view' permission for discovery
- Upgrade to 'edit' for trusted collaborators
- Use 'admin' only for team leads
- Audit sharing changes regularly
Usage Tracking
- Analyze
topVariablesto understand usage patterns - Review
lastUsedAtto identify outdated templates - Monitor
usageCountto measure effectiveness
Error Handling
Common errors and resolution:
| Error | Cause | Resolution |
|---|---|---|
| Template not found | Invalid templateId | Verify ID, use list to find templates |
| Unauthorized | Permission denied | Check ownership or sharing permissions |
| Missing variables | Required variables not provided | Supply values for all required variables |
| Invalid category | Unknown category | Use: responses, greetings, signatures, custom |
| Storage exceeded | Template too large | Reduce content size or use simpler HTML |
Performance Notes
- Templates are cached in-memory for fast access
- List operations support pagination for large result sets
- Variable substitution is O(n) where n = template size
- Usage tracking is asynchronous (non-blocking)
- Soft-delete preserves data without reclaim delay
Testing
Run tests with:
npm test
Coverage includes:
- ✓ Template CRUD operations
- ✓ Variable extraction and expansion
- ✓ Template sharing and permissions
- ✓ Usage tracking and analytics
- ✓ Multi-tenant isolation
- ✓ Error handling
- ✓ Validation
Integration with Email Client
Typical Workflow
- Create template with variables
- Share with team members
- Expand template when composing email
- Track usage for analytics
- Monitor statistics and refine templates
Compose Integration
// In compose flow
const expanded = await templateManager.execute({
action: 'expand',
templateId: selectedTemplate.id,
variableValues: {
name: recipientName,
recipient: recipientEmail,
date: today
}
});
// Populate compose fields
composeForm.subject = expanded.expandedTemplate.subject;
composeForm.body = expanded.expandedTemplate.bodyText;
composeForm.bodyHtml = expanded.expandedTemplate.bodyHtml;
Future Enhancements
- Template preview with mock variables
- Template templates (nested templates)
- Conditional sections based on variables
- Template branching logic
- Import/export in multiple formats
- Template versioning and rollback
- Collaborative template editing
- Template rating and recommendations
Related Plugins
draft-manager- Draft auto-save and recoverysmtp-send- Email sendingemail-parser- Message parsingattachment-handler- Attachment managementmessage-threading- Message threadingspam-detector- Spam detection
Support
For issues, questions, or contributions:
- Check existing templates and examples
- Review error messages and resolution steps
- File issues in the MetaBuilder repository
- Contact the email client team
Phase 6 - Phase Status: Complete Last Updated: 2026-01-24 Maintainer: MetaBuilder Email Team