- Add FastAPI project under channel-service/ - Implement mock pywechat client adapter (login, send, heartbeat) - Add /v1/wechat-personal/login/*, /v1/wechat-personal/send/* APIs - Add /v1/heartbeat and /v1/monitor/status for client health - Add /monitor HTML page with Web Components - Add pytest suite and Dockerfile - Update .gitignore for Python/Node artifacts
34 lines
1.3 KiB
Python
34 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from app.clients.pywechat_client import ClientRegistry, OnlineStatus, registry
|
|
|
|
|
|
class SendService:
|
|
def __init__(self, registry: ClientRegistry):
|
|
self.registry = registry
|
|
|
|
def send_text(self, account_id: str, conversation_id: str, text: str) -> dict:
|
|
client = self.registry.get(account_id)
|
|
if client is None:
|
|
return {"success": False, "error": f"account {account_id} not registered"}
|
|
if client.state.online_status != OnlineStatus.ONLINE:
|
|
return {"success": False, "error": "account not online"}
|
|
return client.send_text(conversation_id, text)
|
|
|
|
def send_image(self, account_id: str, conversation_id: str, image_url: str) -> dict:
|
|
# Placeholder for image sending via pywechat.
|
|
client = self.registry.get(account_id)
|
|
if client is None:
|
|
return {"success": False, "error": f"account {account_id} not registered"}
|
|
if client.state.online_status != OnlineStatus.ONLINE:
|
|
return {"success": False, "error": "account not online"}
|
|
return {
|
|
"success": True,
|
|
"message_id": f"mock-img-{image_url.split('/')[-1]}",
|
|
"conversation_id": conversation_id,
|
|
"type": "image",
|
|
}
|
|
|
|
|
|
send_service = SendService(registry)
|