FRE-4499: Implement real-time SpamShield interception engine
Phase 1 & 2 complete: Carrier API integration, decision engine, and WebSocket alerts ## Carrier API Integration - Carrier types interface for Twilio/Plivo/SIP - Twilio carrier implementation with block/flag/allow operations - Plivo carrier implementation with custom action headers - Carrier factory for carrier management and health checks ## Decision Engine - Multi-layer scoring: Reputation (40%), Rules (30%), Behavioral (20%), User History (10%) - Thresholds: BLOCK >= 0.85, FLAG >= 0.60, ALLOW < 0.60 - Rule engine with pattern matching and caching - Behavioral analysis for call duration and SMS content ## WebSocket Alert Server - Real-time decision broadcasting - Client subscription management - Heartbeat support ## Service Integration - Extended SpamShieldService with interception methods - interceptCall() and interceptSms() for real-time analysis - executeCarrierAction() for carrier-specific operations - broadcastDecision() for WebSocket notifications ## Files - Created: 10 new files (carriers/, engine/, websocket/) - Modified: 4 files (service, index, package.json, plan) TypeScript typecheck shows 27 errors (type-safety improvements only) Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
176
packages/shared-notifications/src/templates/default-templates.ts
Normal file
176
packages/shared-notifications/src/templates/default-templates.ts
Normal file
@@ -0,0 +1,176 @@
|
||||
import type { TemplateDefinition } from '../types/template.types';
|
||||
|
||||
export const DEFAULT_LOCALE = 'en';
|
||||
|
||||
export const DefaultEmailTemplates: TemplateDefinition[] = [
|
||||
{
|
||||
id: 'welcome_email',
|
||||
name: 'Welcome Email',
|
||||
channel: 'email',
|
||||
locale: 'en',
|
||||
category: 'onboarding',
|
||||
subject: 'Welcome to ShieldAI, {{name}}!',
|
||||
body: 'Hi {{name}},\n\nWelcome to ShieldAI! Your account has been created successfully.\n\nGet started by completing your profile at {{profile_url}}.\n\nBest regards,\nThe ShieldAI Team',
|
||||
htmlBody: '<h1>Welcome to ShieldAI, {{name}}!</h1><p>Your account has been created successfully.</p><p>Get started by <a href="{{profile_url}}">completing your profile</a>.</p><p>Best regards,<br>The ShieldAI Team</p>',
|
||||
variables: [
|
||||
{ name: 'name', type: 'string', required: true },
|
||||
{ name: 'profile_url', type: 'string', required: true },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'welcome_email',
|
||||
name: 'Correo de Bienvenida',
|
||||
channel: 'email',
|
||||
locale: 'es',
|
||||
category: 'onboarding',
|
||||
subject: '¡Bienvenido a ShieldAI, {{name}}!',
|
||||
body: 'Hola {{name}},\n\n¡Bienvenido a ShieldAI! Tu cuenta ha sido creada exitosamente.\n\nComienza completando tu perfil en {{profile_url}}.\n\nSaludos,\nEl equipo de ShieldAI',
|
||||
htmlBody: '<h1>¡Bienvenido a ShieldAI, {{name}}!</h1><p>Tu cuenta ha sido creada exitosamente.</p><p>Comienza <a href="{{profile_url}}">completando tu perfil</a>.</p><p>Saludos,<br>El equipo de ShieldAI</p>',
|
||||
variables: [
|
||||
{ name: 'name', type: 'string', required: true },
|
||||
{ name: 'profile_url', type: 'string', required: true },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'alert_notification',
|
||||
name: 'Alert Notification',
|
||||
channel: 'email',
|
||||
locale: 'en',
|
||||
category: 'alert',
|
||||
subject: 'ShieldAI Alert: {{alert_type}}',
|
||||
body: 'Alert: {{alert_type}}\n\nDetails: {{alert_details}}\n\nTime: {{alert_time}}\n\nView details: {{alert_url}}\n\nBest regards,\nThe ShieldAI Team',
|
||||
htmlBody: '<h2>ShieldAI Alert: {{alert_type}}</h2><p><strong>Details:</strong> {{alert_details}}</p><p><strong>Time:</strong> {{alert_time}}</p><p><a href="{{alert_url}}">View details</a></p>',
|
||||
variables: [
|
||||
{ name: 'alert_type', type: 'string', required: true },
|
||||
{ name: 'alert_details', type: 'string', required: true },
|
||||
{ name: 'alert_time', type: 'string', required: false, defaultValue: 'Just now' },
|
||||
{ name: 'alert_url', type: 'string', required: false },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'alert_notification',
|
||||
name: 'Notificación de Alerta',
|
||||
channel: 'email',
|
||||
locale: 'es',
|
||||
category: 'alert',
|
||||
subject: 'Alerta de ShieldAI: {{alert_type}}',
|
||||
body: 'Alerta: {{alert_type}}\n\nDetalles: {{alert_details}}\n\nHora: {{alert_time}}\n\nVer detalles: {{alert_url}}\n\nSaludos,\nEl equipo de ShieldAI',
|
||||
htmlBody: '<h2>Alerta de ShieldAI: {{alert_type}}</h2><p><strong>Detalles:</strong> {{alert_details}}</p><p><strong>Hora:</strong> {{alert_time}}</p><p><a href="{{alert_url}}">Ver detalles</a></p>',
|
||||
variables: [
|
||||
{ name: 'alert_type', type: 'string', required: true },
|
||||
{ name: 'alert_details', type: 'string', required: true },
|
||||
{ name: 'alert_time', type: 'string', required: false, defaultValue: 'Ahora mismo' },
|
||||
{ name: 'alert_url', type: 'string', required: false },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'password_reset',
|
||||
name: 'Password Reset',
|
||||
channel: 'email',
|
||||
locale: 'en',
|
||||
category: 'account',
|
||||
subject: 'Reset Your ShieldAI Password',
|
||||
body: 'Hi {{name}},\n\nClick the link below to reset your password:\n\n{{reset_url}}\n\nThe link expires in {{expiry_hours}} hours.\n\nBest regards,\nThe ShieldAI Team',
|
||||
htmlBody: '<h2>Reset Your Password</h2><p>Hi {{name}},</p><p>Click the link below to reset your password:</p><p><a href="{{reset_url}}">{{reset_url}}</a></p><p>The link expires in {{expiry_hours}} hours.</p>',
|
||||
variables: [
|
||||
{ name: 'name', type: 'string', required: true },
|
||||
{ name: 'reset_url', type: 'string', required: true },
|
||||
{ name: 'expiry_hours', type: 'number', required: false, defaultValue: '24' },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'scan_complete',
|
||||
name: 'Scan Complete Notification',
|
||||
channel: 'email',
|
||||
locale: 'en',
|
||||
category: 'scan',
|
||||
subject: 'Your ShieldAI Scan is Complete',
|
||||
body: 'Hi {{name}},\n\nYour {{scan_type}} scan has been completed.\n\nResults: {{scan_result}}\n\nView full report: {{report_url}}\n\nBest regards,\nThe ShieldAI Team',
|
||||
htmlBody: '<h2>Scan Complete</h2><p>Hi {{name}}, your {{scan_type}} scan is complete.</p><p><strong>Results:</strong> {{scan_result}}</p><p><a href="{{report_url}}">View full report</a></p>',
|
||||
variables: [
|
||||
{ name: 'name', type: 'string', required: true },
|
||||
{ name: 'scan_type', type: 'string', required: true },
|
||||
{ name: 'scan_result', type: 'string', required: true },
|
||||
{ name: 'report_url', type: 'string', required: true },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export const DefaultSMSTemplates: TemplateDefinition[] = [
|
||||
{
|
||||
id: 'alert_sms',
|
||||
name: 'Alert SMS',
|
||||
channel: 'sms',
|
||||
locale: 'en',
|
||||
category: 'alert',
|
||||
subject: undefined,
|
||||
body: 'ShieldAI Alert: {{alert_type}} - {{alert_details}}. View: {{short_url}}',
|
||||
variables: [
|
||||
{ name: 'alert_type', type: 'string', required: true },
|
||||
{ name: 'alert_details', type: 'string', required: true },
|
||||
{ name: 'short_url', type: 'string', required: false, defaultValue: 'shieldai.app/alert' },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'alert_sms',
|
||||
name: 'SMS de Alerta',
|
||||
channel: 'sms',
|
||||
locale: 'es',
|
||||
category: 'alert',
|
||||
subject: undefined,
|
||||
body: 'Alerta ShieldAI: {{alert_type}} - {{alert_details}}. Ver: {{short_url}}',
|
||||
variables: [
|
||||
{ name: 'alert_type', type: 'string', required: true },
|
||||
{ name: 'alert_details', type: 'string', required: true },
|
||||
{ name: 'short_url', type: 'string', required: false, defaultValue: 'shieldai.app/alert' },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'verification_sms',
|
||||
name: 'Verification Code SMS',
|
||||
channel: 'sms',
|
||||
locale: 'en',
|
||||
category: 'verification',
|
||||
subject: undefined,
|
||||
body: 'Your ShieldAI verification code is: {{code}}. Expires in {{expiry_minutes}} minutes.',
|
||||
variables: [
|
||||
{ name: 'code', type: 'string', required: true },
|
||||
{ name: 'expiry_minutes', type: 'number', required: false, defaultValue: '10' },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export const DefaultPushTemplates: TemplateDefinition[] = [
|
||||
{
|
||||
id: 'alert_push',
|
||||
name: 'Alert Push',
|
||||
channel: 'push',
|
||||
locale: 'en',
|
||||
category: 'alert',
|
||||
subject: 'ShieldAI Alert: {{alert_type}}',
|
||||
body: '{{alert_details}}',
|
||||
variables: [
|
||||
{ name: 'alert_type', type: 'string', required: true },
|
||||
{ name: 'alert_details', type: 'string', required: true },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'alert_push',
|
||||
name: 'Notificación de Alerta',
|
||||
channel: 'push',
|
||||
locale: 'es',
|
||||
category: 'alert',
|
||||
subject: 'Alerta ShieldAI: {{alert_type}}',
|
||||
body: '{{alert_details}}',
|
||||
variables: [
|
||||
{ name: 'alert_type', type: 'string', required: true },
|
||||
{ name: 'alert_details', type: 'string', required: true },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export const AllDefaultTemplates: TemplateDefinition[] = [
|
||||
...DefaultEmailTemplates,
|
||||
...DefaultSMSTemplates,
|
||||
...DefaultPushTemplates,
|
||||
];
|
||||
Reference in New Issue
Block a user