Refactor message sending architecture and implement legacy driver support
- Removed UniversalMessageSender from group_generator.py and private_generator.py. - Updated PlatformIOManager to manage legacy send drivers and ensure send pipeline readiness. - Enhanced LegacyPlatformDriver to utilize prepared messages for sending. - Refactored send_service to unify message sending logic and integrate with Platform IO. - Added regression tests for Platform IO legacy driver and send service functionality.
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
"""提供 Platform IO 的 legacy 传输驱动骨架。"""
|
||||
"""提供 Platform IO 的 legacy 传输驱动实现。"""
|
||||
|
||||
from typing import TYPE_CHECKING, Any, Dict, Optional
|
||||
|
||||
from src.platform_io.drivers.base import PlatformIODriver
|
||||
from src.platform_io.types import DeliveryReceipt, DriverDescriptor, DriverKind, RouteKey
|
||||
from src.platform_io.types import DeliveryReceipt, DeliveryStatus, DriverDescriptor, DriverKind, RouteKey
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from src.chat.message_receive.message import SessionMessage
|
||||
|
||||
|
||||
class LegacyPlatformDriver(PlatformIODriver):
|
||||
"""面向 ``maim_message`` 旧链路的 Platform IO 驱动骨架。"""
|
||||
"""面向 ``UniversalMessageSender`` 旧链的 Platform IO 驱动。"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -25,7 +25,7 @@ class LegacyPlatformDriver(PlatformIODriver):
|
||||
Args:
|
||||
driver_id: Broker 内的唯一驱动 ID。
|
||||
platform: 该 legacy 适配器链路负责的平台。
|
||||
account_id: 可选的账号 ID 或 self ID。
|
||||
account_id: 可选的账号 ID。
|
||||
scope: 可选的额外路由作用域。
|
||||
metadata: 可选的额外驱动元数据。
|
||||
"""
|
||||
@@ -45,7 +45,7 @@ class LegacyPlatformDriver(PlatformIODriver):
|
||||
route_key: RouteKey,
|
||||
metadata: Optional[Dict[str, Any]] = None,
|
||||
) -> DeliveryReceipt:
|
||||
"""通过 legacy 传输路径发送消息。
|
||||
"""通过旧链发送一条已经过预处理的消息。
|
||||
|
||||
Args:
|
||||
message: 要投递的内部会话消息。
|
||||
@@ -53,9 +53,40 @@ class LegacyPlatformDriver(PlatformIODriver):
|
||||
metadata: 本次出站投递可选的 Broker 侧元数据。
|
||||
|
||||
Returns:
|
||||
DeliveryReceipt: 由驱动返回的规范化回执。
|
||||
|
||||
Raises:
|
||||
NotImplementedError: 当前仍处于骨架阶段,尚未真正接入旧发送链。
|
||||
DeliveryReceipt: 规范化后的发送回执。
|
||||
"""
|
||||
raise NotImplementedError("LegacyPlatformDriver 仅完成地基实现,尚未接入旧发送链")
|
||||
from src.chat.message_receive.uni_message_sender import send_prepared_message_to_platform
|
||||
|
||||
show_log = False
|
||||
if isinstance(metadata, dict):
|
||||
show_log = bool(metadata.get("show_log", False))
|
||||
|
||||
try:
|
||||
sent = await send_prepared_message_to_platform(message, show_log=show_log)
|
||||
except Exception as exc:
|
||||
return DeliveryReceipt(
|
||||
internal_message_id=message.message_id,
|
||||
route_key=route_key,
|
||||
status=DeliveryStatus.FAILED,
|
||||
driver_id=self.driver_id,
|
||||
driver_kind=self.descriptor.kind,
|
||||
error=str(exc),
|
||||
)
|
||||
|
||||
if not sent:
|
||||
return DeliveryReceipt(
|
||||
internal_message_id=message.message_id,
|
||||
route_key=route_key,
|
||||
status=DeliveryStatus.FAILED,
|
||||
driver_id=self.driver_id,
|
||||
driver_kind=self.descriptor.kind,
|
||||
error="旧链发送失败",
|
||||
)
|
||||
|
||||
return DeliveryReceipt(
|
||||
internal_message_id=message.message_id,
|
||||
route_key=route_key,
|
||||
status=DeliveryStatus.SENT,
|
||||
driver_id=self.driver_id,
|
||||
driver_kind=self.descriptor.kind,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user