console_im_service.py 973 Bytes
"""Console IM service — prints hook output instead of sending to real IM."""
import json
from typing import Dict, Any, Optional


class ConsoleIMService:
    """IMService replacement that prints to console for testing."""

    def __init__(self):
        self._client = None

    async def send_message(
        self,
        bot_id: str,
        content: str,
        contact_id: str,
        at_list: str = "",
    ) -> Dict[str, Any]:
        payload = {
            "bot_id": bot_id,
            "content": content,
            "contact_id": contact_id,
            "msg_type": "text",
        }
        if at_list:
            payload["at_list"] = at_list

        print("\n" + "=" * 50)
        print("  [Hook: post_reply] → 计划发送到 IM")
        print("=" * 50)
        print(json.dumps(payload, ensure_ascii=False, indent=2))
        print("=" * 50 + "\n")

        return {"status": "printed", "bot_id": bot_id}

    async def close(self):
        pass