Add events to workflows

This commit is contained in:
Dries Augustyns
2025-12-01 18:37:53 +01:00
parent 5158756650
commit b1f0043940
11 changed files with 927 additions and 51 deletions
+11 -13
View File
@@ -8,6 +8,7 @@ import {HttpException} from '../exceptions/index.js';
import {BillingLimitService} from './BillingLimitService.js';
import {DomainService} from './DomainService.js';
import {EventService} from './EventService.js';
import {QueueService} from './QueueService.js';
import {sendRawEmail} from './SESService.js';
@@ -386,19 +387,16 @@ export class EmailService {
},
});
// Track event
await prisma.event.create({
data: {
projectId: email.projectId,
contactId: email.contactId,
emailId: email.id,
name: 'email.sent',
data: {
subject: formattedEmail.subject,
from: email.from,
messageId: result.messageId,
},
},
// Track event (this will trigger workflows)
await EventService.trackEvent(email.projectId, 'email.sent', email.contactId, email.id, {
subject: formattedEmail.subject,
from: email.from,
fromName: email.fromName,
messageId: result.messageId,
templateId: email.templateId,
campaignId: email.campaignId,
sourceType: email.sourceType,
sentAt: new Date().toISOString(),
});
} catch (error) {
console.error(`[EMAIL] Failed to send email ${emailId}:`, error);