| 123456789101112131415161718192021222324252627282930313233343536373839 |
- from __future__ import annotations
- import logging
- import uuid
- from typing import TYPE_CHECKING, Any
- from gateway.core.channels.types import FeishuReplyContext, IncomingFeishuEvent
- if TYPE_CHECKING:
- from gateway.core.channels.feishu.connector import FeishuConnector
- logger = logging.getLogger(__name__)
- class EchoExecutorBackend:
- """默认执行器:回显或固定话术,验证「Gateway → Node → 飞书」链路。"""
- 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: FeishuReplyContext,
- connector: Any,
- *,
- event: IncomingFeishuEvent,
- ) -> 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
|