| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- """
- 通用回显执行器。
- 适用于任何实现了 ``send_text(reply_context, text) -> dict`` 的渠道连接器,
- 无需感知具体渠道类型(飞书、微信等)。
- """
- from __future__ import annotations
- import logging
- import uuid
- from typing import Any
- logger = logging.getLogger(__name__)
- class EchoExecutorBackend:
- """默认执行器:将用户消息原文回显,用于验证 Gateway → 渠道适配层 → IM 全链路。"""
- def __init__(self, *, prefix: str = "[Gateway] ", enabled: bool = True) -> None:
- self._prefix = prefix
- self._enabled = enabled
- async def handle_inbound_message(
- self,
- trace_id: str,
- text: str,
- reply_context: Any,
- connector: Any,
- *,
- event: Any,
- ) -> str:
- task_id = f"task-{uuid.uuid4()}"
- if not self._enabled:
- logger.info("EchoExecutor disabled, skip reply trace_id=%s", trace_id)
- return task_id
- reply_body = f"{self._prefix}{text}" if text else f"{self._prefix}(空消息)"
- result = await connector.send_text(reply_context, reply_body)
- if not result.get("ok"):
- logger.error("send_text failed trace_id=%s result=%s", trace_id, result)
- return task_id
|