refactor(schemas): 统一 message/notification 命名边界,旧名收敛至兼容映射表

- notification 域:渠道能力(MessageChannel→NotificationChannel、ChannelCapability* 迁入 notification.py)
- message 域:消息收发(Notification→Message、NotificationType→MessageType、CommingMessage→IncomingMessage、NotificationHistoryItem→MessageHistoryItem、NotificationClear*→MessageClear*)
- Agent 工具契约:send_notification_message→send_message、notification_callback→message_callback
- 源码不保留旧名物理别名,旧导入经 app/runtime/compat/manifest.py SYMBOL_ALIASES 惰性解析
- API 路径与持久化键冻结不变,前端零改动
- 新增兼容守护测试与 docs/rules/07 命名边界规范
This commit is contained in:
jxxghp
2026-08-16 19:32:20 +08:00
parent 98276a68a8
commit 240a4dffe6
96 changed files with 1975 additions and 1751 deletions
+31 -31
View File
@@ -14,9 +14,9 @@ from app.runtime.log import logger
from app.modules import _ModuleBase, _MessageBase
from app.modules.telegram.telegram import Telegram
from app.schemas import (
MessageChannel,
CommingMessage,
Notification,
NotificationChannel,
IncomingMessage,
Message,
CommandRegisterEventData,
NotificationConf,
MessageResponse,
@@ -26,7 +26,7 @@ from app.foundation.collections import DictUtils
register_channel_admin_resolver(
MessageChannel.Telegram,
NotificationChannel.Telegram,
lambda config: resolve_config_principal_ids(
config, "TELEGRAM_ADMINS", "TELEGRAM_CHAT_ID"
),
@@ -45,7 +45,7 @@ class TelegramModule(_ModuleBase, _MessageBase[Telegram]):
super().init_service(
service_name=Telegram.__name__.lower(), service_type=Telegram
)
self._channel = MessageChannel.Telegram
self._channel = NotificationChannel.Telegram
@staticmethod
def get_name() -> str:
@@ -62,11 +62,11 @@ class TelegramModule(_ModuleBase, _MessageBase[Telegram]):
return ModuleType.Notification
@staticmethod
def get_subtype() -> MessageChannel:
def get_subtype() -> NotificationChannel:
"""
获取模块子类型
"""
return MessageChannel.Telegram
return NotificationChannel.Telegram
@staticmethod
def get_priority() -> int:
@@ -125,14 +125,14 @@ class TelegramModule(_ModuleBase, _MessageBase[Telegram]):
if not admins:
return False
return not matches_channel_admin(
MessageChannel.Telegram,
NotificationChannel.Telegram,
config,
*user_ids,
)
def message_parser(
self, source: str, body: Any, form: Any, args: Any
) -> Optional[CommingMessage]:
) -> Optional[IncomingMessage]:
"""
解析消息内容,返回字典,注意以下约定值:
userid: 用户ID
@@ -211,7 +211,7 @@ class TelegramModule(_ModuleBase, _MessageBase[Telegram]):
def _handle_callback_query(
self, message: dict, client_config: NotificationConf, client: Telegram
) -> Optional[CommingMessage]:
) -> Optional[IncomingMessage]:
"""
处理按钮回调查询
"""
@@ -242,13 +242,13 @@ class TelegramModule(_ModuleBase, _MessageBase[Telegram]):
callback_text = f"CALLBACK:{callback_data}"
# 创建包含完整回调信息的CommingMessage
return CommingMessage(
channel=MessageChannel.Telegram,
return IncomingMessage(
channel=NotificationChannel.Telegram,
source=client_config.name,
userid=user_id,
username=user_name,
is_channel_admin=matches_channel_admin(
MessageChannel.Telegram,
NotificationChannel.Telegram,
client_config.config,
user_id,
),
@@ -265,7 +265,7 @@ class TelegramModule(_ModuleBase, _MessageBase[Telegram]):
def _handle_text_message(
self, msg: dict, client_config: NotificationConf, client: Telegram
) -> Optional[CommingMessage]:
) -> Optional[IncomingMessage]:
"""
处理普通文本消息
"""
@@ -323,13 +323,13 @@ class TelegramModule(_ModuleBase, _MessageBase[Telegram]):
)
return None
return CommingMessage(
channel=MessageChannel.Telegram,
return IncomingMessage(
channel=NotificationChannel.Telegram,
source=client_config.name,
userid=user_id,
username=user_name,
is_channel_admin=matches_channel_admin(
MessageChannel.Telegram,
NotificationChannel.Telegram,
client_config.config,
user_id,
),
@@ -344,7 +344,7 @@ class TelegramModule(_ModuleBase, _MessageBase[Telegram]):
return None
@staticmethod
def _extract_images(msg: dict) -> Optional[List[CommingMessage.MessageImage]]:
def _extract_images(msg: dict) -> Optional[List[IncomingMessage.MessageImage]]:
"""
从Telegram消息中提取图片file_id
"""
@@ -355,7 +355,7 @@ class TelegramModule(_ModuleBase, _MessageBase[Telegram]):
file_id = largest_photo.get("file_id")
if file_id:
images.append(
CommingMessage.MessageImage(
IncomingMessage.MessageImage(
ref=f"tg://file_id/{file_id}",
mime_type="image/jpeg",
size=largest_photo.get("file_size"),
@@ -368,7 +368,7 @@ class TelegramModule(_ModuleBase, _MessageBase[Telegram]):
mime_type = document.get("mime_type", "")
if file_id and mime_type.startswith("image/"):
images.append(
CommingMessage.MessageImage(
IncomingMessage.MessageImage(
ref=f"tg://file_id/{file_id}",
name=document.get("file_name"),
mime_type=document.get("mime_type"),
@@ -399,7 +399,7 @@ class TelegramModule(_ModuleBase, _MessageBase[Telegram]):
return audio_refs if audio_refs else None
@staticmethod
def _extract_files(msg: dict) -> Optional[List[CommingMessage.MessageAttachment]]:
def _extract_files(msg: dict) -> Optional[List[IncomingMessage.MessageAttachment]]:
"""
从 Telegram 消息中提取非图片文件附件。
"""
@@ -413,7 +413,7 @@ class TelegramModule(_ModuleBase, _MessageBase[Telegram]):
return None
return [
CommingMessage.MessageAttachment(
IncomingMessage.MessageAttachment(
ref=f"tg://document_file_id/{file_id}",
name=document.get("file_name"),
mime_type=document.get("mime_type"),
@@ -504,7 +504,7 @@ class TelegramModule(_ModuleBase, _MessageBase[Telegram]):
return cleaned
def post_message(self, message: Notification, **kwargs) -> None:
def post_message(self, message: Message, **kwargs) -> None:
"""
发送消息
:param message: 消息体
@@ -562,7 +562,7 @@ class TelegramModule(_ModuleBase, _MessageBase[Telegram]):
)
def post_medias_message(
self, message: Notification, medias: List[MediaInfo]
self, message: Message, medias: List[MediaInfo]
) -> None:
"""
发送媒体信息选择列表
@@ -587,7 +587,7 @@ class TelegramModule(_ModuleBase, _MessageBase[Telegram]):
)
def post_torrents_message(
self, message: Notification, torrents: List[Context]
self, message: Message, torrents: List[Context]
) -> None:
"""
发送种子信息选择列表
@@ -613,7 +613,7 @@ class TelegramModule(_ModuleBase, _MessageBase[Telegram]):
def delete_message(
self,
channel: MessageChannel,
channel: NotificationChannel,
source: str,
message_id: int,
chat_id: Optional[int] = None,
@@ -641,7 +641,7 @@ class TelegramModule(_ModuleBase, _MessageBase[Telegram]):
def edit_message(
self,
channel: MessageChannel,
channel: NotificationChannel,
source: str,
message_id: Union[str, int],
chat_id: Union[str, int],
@@ -685,7 +685,7 @@ class TelegramModule(_ModuleBase, _MessageBase[Telegram]):
def mark_message_processing_started(
self,
channel: MessageChannel,
channel: NotificationChannel,
source: str,
userid: Optional[Union[str, int]] = None,
message_id: Optional[Union[str, int]] = None,
@@ -718,7 +718,7 @@ class TelegramModule(_ModuleBase, _MessageBase[Telegram]):
def mark_message_processing_finished(
self,
channel: MessageChannel,
channel: NotificationChannel,
source: str,
userid: Optional[Union[str, int]] = None,
message_id: Optional[Union[str, int]] = None,
@@ -741,7 +741,7 @@ class TelegramModule(_ModuleBase, _MessageBase[Telegram]):
return False
return client.stop_typing(chat_id=chat_id, userid=userid)
def send_direct_message(self, message: Notification) -> Optional[MessageResponse]:
def send_direct_message(self, message: Message) -> Optional[MessageResponse]:
"""
直接发送消息并返回消息ID等信息
:param message: 消息体
@@ -789,7 +789,7 @@ class TelegramModule(_ModuleBase, _MessageBase[Telegram]):
return MessageResponse(
message_id=result.get("message_id"),
chat_id=result.get("chat_id"),
channel=MessageChannel.Telegram,
channel=NotificationChannel.Telegram,
source=conf.name,
success=True,
)