feat: 集成飞书通知和机器人对话系统

- 新增通知系统 (notifications 表、服务、API)
- 新增飞书定时任务结果推送 (webhook + 应用消息)
- 新增飞书应用消息发送服务 (feishu_app_service)
- 新增飞书 WebSocket 长连接事件监听 (苹果应用)
- 新增飞书账号绑定/解绑 API
- 新增橙子飞书机器人 (独立 WS 连接,固定路由到橙子助手 Agent)
- 执行记录添加 schedule_id,用户添加飞书绑定字段

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
renjianbo
2026-05-02 16:17:49 +08:00
parent 0bbf68d5bb
commit 7ee80c74b2
29 changed files with 4288 additions and 5 deletions

View File

@@ -17,5 +17,6 @@ from app.models.agent_vector_memory import AgentVectorMemory
from app.models.agent_learning_pattern import AgentLearningPattern
from app.models.agent_schedule import AgentSchedule
from app.models.knowledge_base import KnowledgeBase, Document, DocumentChunk
from app.models.notification import Notification
__all__ = ["User", "Workflow", "WorkflowVersion", "Agent", "Execution", "ExecutionLog", "ModelConfig", "DataSource", "WorkflowTemplate", "TemplateRating", "TemplateFavorite", "NodeTemplate", "Role", "Permission", "WorkflowPermission", "AgentPermission", "AlertRule", "AlertLog", "PersistentUserMemory", "AgentLLMLog", "AgentVectorMemory", "AgentLearningPattern", "AgentSchedule", "KnowledgeBase", "Document", "DocumentChunk"]
__all__ = ["User", "Workflow", "WorkflowVersion", "Agent", "Execution", "ExecutionLog", "ModelConfig", "DataSource", "WorkflowTemplate", "TemplateRating", "TemplateFavorite", "NodeTemplate", "Role", "Permission", "WorkflowPermission", "AgentPermission", "AlertRule", "AlertLog", "PersistentUserMemory", "AgentLLMLog", "AgentVectorMemory", "AgentLearningPattern", "AgentSchedule", "KnowledgeBase", "Document", "DocumentChunk", "Notification"]

View File

@@ -16,6 +16,7 @@ class AgentSchedule(Base):
cron_expression = Column(String(100), nullable=False, comment="cron 表达式,如 0 9 * * *")
input_message = Column(Text, nullable=False, comment="定时执行时发送的消息内容")
timezone = Column(String(64), default="Asia/Shanghai", comment="时区")
webhook_url = Column(String(512), nullable=True, comment="飞书机器人 Webhook URL可选执行完成后推送通知")
enabled = Column(Boolean, default=True, comment="是否启用")
last_run_at = Column(DateTime, nullable=True, comment="上次执行时间")
last_run_status = Column(String(32), nullable=True, comment="上次执行状态: success/failed")

View File

@@ -25,6 +25,9 @@ class Execution(Base):
error_message = Column(Text, comment="错误信息")
execution_time = Column(Integer, comment="执行时间(ms)")
task_id = Column(String(100), comment="Celery任务ID")
schedule_id = Column(
CHAR(36), ForeignKey("agent_schedules.id"), nullable=True, comment="定时任务ID"
)
parent_execution_id = Column(
CHAR(36), ForeignKey("executions.id"), nullable=True, comment="父执行ID"
)

View File

@@ -0,0 +1,24 @@
"""通知模型 — 用于定时任务结果推送及系统通知"""
import uuid
from datetime import datetime
from sqlalchemy import Column, String, Text, DateTime, ForeignKey, Boolean
from sqlalchemy.dialects.mysql import CHAR
from app.core.database import Base
class Notification(Base):
"""系统通知 — 定时任务结果、告警、系统消息等"""
__tablename__ = "notifications"
id = Column(CHAR(36), primary_key=True, default=lambda: str(uuid.uuid4()))
user_id = Column(CHAR(36), ForeignKey("users.id"), nullable=False, index=True, comment="接收用户 ID")
title = Column(String(200), nullable=False, comment="通知标题")
content = Column(Text, nullable=True, comment="通知正文")
category = Column(String(32), default="system", comment="分类: schedule/alert/system")
ref_type = Column(String(32), nullable=True, comment="关联对象类型: schedule/execution")
ref_id = Column(String(36), nullable=True, comment="关联对象 ID")
is_read = Column(Boolean, default=False, comment="是否已读")
created_at = Column(DateTime, default=datetime.utcnow, comment="创建时间")
def __repr__(self):
return f"<Notification(id={self.id}, user_id={self.user_id}, title={self.title})>"

View File

@@ -17,6 +17,8 @@ class User(Base):
email = Column(String(100), unique=True, nullable=False, comment="邮箱")
password_hash = Column(String(255), nullable=False, comment="密码哈希")
role = Column(String(20), default="user", comment="角色: admin/user保留字段用于向后兼容")
feishu_open_id = Column(String(64), nullable=True, comment="飞书用户 open_id用于推送通知")
feishu_default_agent_id = Column(CHAR(36), nullable=True, comment="飞书对话默认 Agent ID")
created_at = Column(DateTime, default=func.now(), comment="创建时间")
updated_at = Column(DateTime, default=func.now(), onupdate=func.now(), comment="更新时间")