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:
53
channel-service/app/api/wechat_personal.py
Normal file
53
channel-service/app/api/wechat_personal.py
Normal file
@@ -0,0 +1,53 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import APIRouter
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from app.services.login_service import login_service
|
||||
from app.services.send_service import send_service
|
||||
|
||||
router = APIRouter(prefix="/v1/wechat-personal", tags=["wechat-personal"])
|
||||
|
||||
|
||||
class StartLoginRequest(BaseModel):
|
||||
account_id: str = Field(..., description="渠道账号唯一标识")
|
||||
account_name: Optional[str] = Field(None, description="账号显示名称")
|
||||
|
||||
|
||||
class SendTextRequest(BaseModel):
|
||||
account_id: str
|
||||
conversation_id: str = Field(..., description="目标会话/群 ID")
|
||||
text: str = Field(..., min_length=1, description="消息内容")
|
||||
|
||||
|
||||
class SendImageRequest(BaseModel):
|
||||
account_id: str
|
||||
conversation_id: str
|
||||
image_url: str
|
||||
|
||||
|
||||
@router.post("/login/start")
|
||||
def start_login(request: StartLoginRequest):
|
||||
return login_service.start_login(request.account_id, request.account_name)
|
||||
|
||||
|
||||
@router.get("/login/{account_id}/status")
|
||||
def login_status(account_id: str):
|
||||
return login_service.get_status(account_id)
|
||||
|
||||
|
||||
@router.post("/login/{account_id}/confirm")
|
||||
def confirm_login(account_id: str):
|
||||
return login_service.confirm_login(account_id)
|
||||
|
||||
|
||||
@router.post("/send/text")
|
||||
def send_text(request: SendTextRequest):
|
||||
return send_service.send_text(request.account_id, request.conversation_id, request.text)
|
||||
|
||||
|
||||
@router.post("/send/image")
|
||||
def send_image(request: SendImageRequest):
|
||||
return send_service.send_image(request.account_id, request.conversation_id, request.image_url)
|
||||
Reference in New Issue
Block a user