import dotenv from 'dotenv'; dotenv.config(); import WorkflowOrchestrator from './workflows/WorkflowOrchestrator'; import SessionManager from './rdrama/session/SessionManager'; import { CommentParser } from './rdrama/services/CommentParser'; import { DatabaseInitializer } from './db/initializeDatabase'; import { DatabaseService } from './db/services/Database'; import { DatabaseMaintenanceService } from './db/services/DatabaseMaintenance'; import { CommentProcessor } from './rdrama/services/CommentProcessor'; import { MessageService } from './utils/MessageService'; import { CommentPoster } from './rdrama/services/CommentPoster'; // Import other necessary services or configurations async function startApplication() { // Initialize SessionManager or other global configurations const sessionManager = SessionManager.getInstance(); if (!process.env.RDRAMA_API_KEY) { throw new Error('RDRAMA_API_KEY is undefined. Please set this environment variable.'); } sessionManager.setAuthorizationToken(process.env.RDRAMA_API_KEY); const databaseInitializer = DatabaseInitializer.getInstance(); const db = await databaseInitializer.getDbInstance() if (!db) { throw new Error('Failed to initialize the database.'); } const databaseService = new DatabaseService(db) const databaseMaintenance = new DatabaseMaintenanceService(databaseService) console.log('Database Maintenance Start') await databaseMaintenance.runMaintenanceTasks() // Initialize services with any required dependencies const commentFetcher = new CommentProcessor(databaseService); const commentParser = new CommentParser(); const commentPoster = new CommentPoster() const messageService = new MessageService(); // Initialize and start your workflow const workflowOrchestrator = new WorkflowOrchestrator( commentFetcher, commentParser, commentPoster, messageService, ); await workflowOrchestrator.executeWorkflow(); } startApplication() .then(() => console.log('Application started successfully.')) .catch((error) => console.error('Application failed to start:', error));