Service layer with proper separation of concerns. Each service handles a specific domain:
email.service.ts
): Email communication and template formattingnotion.service.ts
): Notion API integration for database and file operationsopenai.service.ts
): AI/ML processing and analysisServices should:
Purpose: Centralized email communication with template management
Key Functions:
sendProcessingAcknowledgment()
- Immediate user feedbacksendProcessingCompletion()
- Final status notificationsendProcessingError()
- Error notificationsFeatures:
Purpose: Notion API integration for database queries and page updates
Key Functions:
updatePageProperties()
for any property updatescreateNotionFileUpload()
- Step 1: Create upload objectuploadFileToNotionUrl()
- Step 2: Upload file contents via FormDataattachFileUploadToPage()
- Step 3: Attach file to page with "file_upload" typePurpose: OpenAI API integration with two-stage consensus analysis
Key Functions:
gpt-4o-mini
for cost efficiencygpt-4o
for high-quality reasoningFeatures:
import { sendProcessingAcknowledgment } from "../services/email.service.ts";
await sendProcessingAcknowledgment({
originalEmail: email,
processingId: "abc123",
pdfCount: 5
});
Use /test-async-email-processing?email=your@email.com&count=3
to test the complete workflow.