taskflow-ai
Version:
TaskFlow AI - 智能PRD文档解析与任务管理助手,支持多模型AI协同、MCP编辑器集成,专为开发团队设计的CLI工具
264 lines (263 loc) • 6.05 kB
TypeScript
/**
* 通知系统 - 处理各种通知和提醒
* 支持多种通知渠道和智能提醒
*/
import { EventEmitter } from 'events';
import { Logger } from '../../infra/logger';
import { User, Notification, NotificationType } from './collaboration-manager';
/**
* 通知渠道枚举
*/
export declare enum NotificationChannel {
IN_APP = "in_app",
EMAIL = "email",
PUSH = "push",
SLACK = "slack",
WEBHOOK = "webhook"
}
/**
* 通知模板接口
*/
export interface NotificationTemplate {
id: string;
type: NotificationType;
channel: NotificationChannel;
subject: string;
body: string;
variables: string[];
isActive: boolean;
}
/**
* 通知规则接口
*/
export interface NotificationRule {
id: string;
name: string;
description: string;
conditions: NotificationCondition[];
actions: NotificationAction[];
isActive: boolean;
priority: number;
}
/**
* 通知条件接口
*/
export interface NotificationCondition {
field: string;
operator: 'equals' | 'not_equals' | 'contains' | 'greater_than' | 'less_than' | 'in' | 'not_in';
value: any;
}
/**
* 通知动作接口
*/
export interface NotificationAction {
type: 'send_notification' | 'send_email' | 'create_reminder' | 'escalate';
channel: NotificationChannel;
template: string;
recipients: string[];
delay?: number;
}
/**
* 提醒接口
*/
export interface Reminder {
id: string;
userId: string;
taskId: string;
type: 'deadline' | 'follow_up' | 'status_check' | 'custom';
title: string;
message: string;
scheduledAt: Date;
isRecurring: boolean;
recurringPattern?: RecurringPattern;
isSent: boolean;
sentAt?: Date;
isActive: boolean;
}
/**
* 重复模式接口
*/
export interface RecurringPattern {
type: 'daily' | 'weekly' | 'monthly';
interval: number;
daysOfWeek?: number[];
dayOfMonth?: number;
endDate?: Date;
}
/**
* 通知统计接口
*/
export interface NotificationStats {
total: number;
sent: number;
delivered: number;
failed: number;
opened: number;
clicked: number;
byChannel: Record<NotificationChannel, number>;
byType: Record<NotificationType, number>;
}
/**
* 通知系统类
*/
export declare class NotificationSystem extends EventEmitter {
private logger;
private templates;
private rules;
private reminders;
private reminderInterval;
private stats;
constructor(logger: Logger);
/**
* 初始化统计信息
*/
private initializeStats;
/**
* 初始化默认模板
*/
private initializeDefaultTemplates;
/**
* 发送通知
* @param notification 通知信息
* @param user 用户信息
* @param context 上下文数据
*/
sendNotification(notification: Notification, user: User, context?: any): Promise<boolean>;
/**
* 发送到指定渠道
* @param channel 通知渠道
* @param notification 通知信息
* @param user 用户信息
* @param context 上下文数据
*/
private sendToChannel;
/**
* 发送应用内通知
*/
private sendInAppNotification;
/**
* 发送邮件通知
*/
private sendEmailNotification;
/**
* 发送推送通知
*/
private sendPushNotification;
/**
* 发送Slack通知
*/
private sendSlackNotification;
/**
* 发送Webhook通知
*/
private sendWebhookNotification;
/**
* 检查是否应该发送给用户
* @param notification 通知信息
* @param user 用户信息
*/
private shouldSendToUser;
/**
* 获取适用的规则
* @param notification 通知信息
* @param context 上下文数据
*/
private getApplicableRules;
/**
* 评估条件
* @param conditions 条件列表
* @param notification 通知信息
* @param context 上下文数据
*/
private evaluateConditions;
/**
* 获取字段值
* @param field 字段名
* @param notification 通知信息
* @param context 上下文数据
*/
private getFieldValue;
/**
* 评估单个条件
* @param condition 条件
* @param value 实际值
*/
private evaluateCondition;
/**
* 执行规则
* @param rule 规则
* @param notification 通知信息
* @param user 用户信息
* @param context 上下文数据
*/
private executeRule;
/**
* 执行动作
* @param action 动作
* @param notification 通知信息
* @param user 用户信息
* @param context 上下文数据
*/
private executeAction;
/**
* 创建提醒
* @param notification 通知信息
* @param user 用户信息
* @param context 上下文数据
*/
private createReminder;
/**
* 升级通知
* @param notification 通知信息
* @param user 用户信息
* @param context 上下文数据
*/
private escalateNotification;
/**
* 启动提醒调度器
*/
private startReminderScheduler;
/**
* 处理提醒
*/
private processReminders;
/**
* 发送提醒
* @param reminder 提醒信息
*/
private sendReminder;
/**
* 安排下次提醒
* @param reminder 提醒信息
*/
private scheduleNextReminder;
/**
* 更新统计信息
* @param notification 通知信息
* @param channel 通知渠道
* @param action 动作类型
*/
private updateStats;
/**
* 获取统计信息
*/
getStats(): NotificationStats;
/**
* 添加通知模板
* @param template 通知模板
*/
addTemplate(template: NotificationTemplate): void;
/**
* 添加通知规则
* @param rule 通知规则
*/
addRule(rule: NotificationRule): void;
/**
* 生成ID
*/
private generateId;
/**
* 销毁通知系统
*/
destroy(): void;
}