UNPKG

education-module-ai

Version:
161 lines (160 loc) 6.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NotificationPlugin = exports.NotificationType = void 0; /** * Notification types supported by the plugin */ var NotificationType; (function (NotificationType) { NotificationType["SESSION_REMINDER"] = "session_reminder"; NotificationType["CONTENT_RECOMMENDATION"] = "content_recommendation"; NotificationType["PROGRESS_UPDATE"] = "progress_update"; NotificationType["ACHIEVEMENT"] = "achievement"; NotificationType["SYSTEM"] = "system"; NotificationType["LEARNING_PATH"] = "learning_path"; })(NotificationType || (exports.NotificationType = NotificationType = {})); /** * Notification Plugin for the Education Module * Manages user notifications for learning activities and achievements */ class NotificationPlugin { constructor() { this.isInitialized = false; this.notifications = {}; // userId -> notifications this.notificationCount = 0; } /** * Initialize the notification plugin */ async initialize() { // In a real implementation, this would connect to a notification service console.log("Notification Plugin: Initializing..."); this.isInitialized = true; console.log("Notification Plugin: Initialized successfully"); return Promise.resolve(); } /** * Create and send a notification to a user */ async sendNotification(userId, type, title, message, data) { if (!this.isInitialized) { console.warn("Notification Plugin: Not initialized. Notification not sent."); throw new Error("Notification plugin not initialized"); } const notification = { id: `notification_${++this.notificationCount}`, userId, type, title, message, timestamp: new Date(), read: false, data, }; // Store notification if (!this.notifications[userId]) { this.notifications[userId] = []; } this.notifications[userId].push(notification); console.log(`Notification Plugin: Sent ${type} notification to user ${userId}`); // In a real implementation, this would send the notification through a service // (email, push notification, in-app notification, etc.) return notification; } /** * Get all notifications for a user */ async getUserNotifications(userId) { return this.notifications[userId] || []; } /** * Mark a notification as read */ async markNotificationAsRead(userId, notificationId) { const userNotifications = this.notifications[userId]; if (!userNotifications) return false; const notification = userNotifications.find(n => n.id === notificationId); if (!notification) return false; notification.read = true; return true; } /** * Clear all notifications for a user */ async clearUserNotifications(userId) { if (!this.notifications[userId]) return false; this.notifications[userId] = []; return true; } // Session event handlers async onSessionStarted(session) { await this.sendNotification(session.userId, NotificationType.SESSION_REMINDER, "Learning Session Started", `Your ${session.subject} learning session has started.`, { sessionId: session.id, subject: session.subject }); } async onSessionEnded(session) { // Calculate session duration in minutes const duration = session.endTime && session.startTime ? Math.round((session.endTime.getTime() - session.startTime.getTime()) / 60000) : 0; await this.sendNotification(session.userId, NotificationType.PROGRESS_UPDATE, "Learning Session Completed", `You've completed a ${duration} minute session on ${session.subject}.`, { sessionId: session.id, subject: session.subject, duration, messageCount: session.messages.length }); } // Profile event handlers async onProfileCreated(profile) { await this.sendNotification(profile.id, NotificationType.SYSTEM, "Welcome to the Learning Platform", "Your learning profile has been created. Start exploring subjects and content!", { profileId: profile.id }); } // Learning path event handlers async onLearningPathGenerated(path) { await this.sendNotification(path.userId, NotificationType.LEARNING_PATH, `Learning Path Created: ${path.topic}`, `Your personalized learning path for ${path.topic} is ready. It contains ${path.steps.length} steps to master this topic.`, { pathId: path.id, topic: path.topic, estimatedTime: path.estimatedCompletionTime, stepCount: path.steps.length }); } async onLearningPathCompleted(path) { await this.sendNotification(path.userId, NotificationType.ACHIEVEMENT, `Learning Path Completed: ${path.topic}`, `Congratulations! You've completed your learning path for ${path.topic}. Well done on reaching this milestone!`, { pathId: path.id, topic: path.topic }); } /** * Send a recommendation notification to a user */ async sendRecommendation(userId, subject, contentTitle, contentId) { return this.sendNotification(userId, NotificationType.CONTENT_RECOMMENDATION, `New ${subject} Content Recommendation`, `We recommend checking out: ${contentTitle}`, { contentId, subject }); } /** * Send an achievement notification to a user */ async sendAchievementNotification(userId, achievementTitle, description, subject) { return this.sendNotification(userId, NotificationType.ACHIEVEMENT, `Achievement Unlocked: ${achievementTitle}`, description, { achievement: achievementTitle, subject }); } /** * Schedule a session reminder for a user */ async scheduleSessionReminder(userId, subject, scheduledTime) { // In a real implementation, this would schedule a notification for the future console.log(`Notification Plugin: Scheduled reminder for ${subject} session at ${scheduledTime.toISOString()}`); // For demo purposes, we'll just log it console.log(`Reminder scheduled for user ${userId} for ${subject} at ${scheduledTime.toISOString()}`); } /** * Send a learning path step reminder */ async sendPathStepReminder(userId, pathId, topic, stepNumber, stepTitle) { return this.sendNotification(userId, NotificationType.LEARNING_PATH, `Learning Path Progress Reminder`, `Continue your learning journey for ${topic}. Your next step is: ${stepTitle}`, { pathId, stepNumber, stepTitle, topic }); } } exports.NotificationPlugin = NotificationPlugin;