feat(channel-service): add Python FastAPI pywechat channel service
- 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
This commit is contained in:
33
channel-service/app/services/send_service.py
Normal file
33
channel-service/app/services/send_service.py
Normal file
@@ -0,0 +1,33 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user