feat(feishu): 添加飞书长连接支持并重构事件处理

添加了 FeishuEventService 来统一处理飞书消息事件,
新增 long_connection.py 实现长连接客户端,
修改 webhook 路由使用新的事件处理服务,
添加了 lark-oapi 依赖支持长连接功能,
更新测试用例覆盖新的事件处理逻辑。

BREAKING CHANGE: 飞书事件处理逻辑重构,统一使用
FeishuEventService 进行消息处理和审计记录。
```
This commit is contained in:
2026-06-22 14:54:20 +08:00
parent 71ca804764
commit 09933b15ad
20 changed files with 177 additions and 869 deletions

View File

@@ -0,0 +1,43 @@
from typing import Any
from sqlalchemy.orm import Session
from app.modules.audit.schemas import AuditLogCreate
from app.modules.feishu.commands import FeishuCommandService
from app.modules.feishu.service import FeishuService
class FeishuEventService:
"""Handle Feishu message events from webhook or long connection."""
def __init__(self, db: Session):
self.db = db
self.feishu = FeishuService(db)
self.commands = FeishuCommandService(db)
def handle_event(
self,
payload: dict[str, Any],
source: str,
auto_reply: bool = True,
) -> dict[str, Any]:
self.feishu.verify_event(payload)
self.feishu.audit.log(
AuditLogCreate(
actor="feishu",
source="feishu",
action=f"{source}_event",
request_payload=payload,
response_payload={"accepted": True},
)
)
command = self.commands.extract_event_command(payload)
if not command:
return {"ok": True, "handled": False}
result = self.commands.handle_text(
command["text"],
chat_id=command["chat_id"],
actor=command["actor"],
auto_reply=auto_reply,
)
return {"ok": True, "handled": True, "result": result}