feat(fase2): add Flow API routes and Flow Engine main app
API Gateway: - Add flows router with CRUD endpoints - Add activate/deactivate endpoints - Auto-deactivate other flows for welcome/fallback triggers Flow Engine: - Add main.py with FastAPI app - Add /process endpoint for message handling - Add SQLAlchemy models (mirrors api-gateway) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
49
services/flow-engine/app/main.py
Normal file
49
services/flow-engine/app/main.py
Normal file
@@ -0,0 +1,49 @@
|
||||
from fastapi import FastAPI, Depends
|
||||
from pydantic import BaseModel
|
||||
from typing import Optional
|
||||
from sqlalchemy.orm import Session
|
||||
from app.models import get_db
|
||||
from app.engine import FlowEngine
|
||||
from app.config import get_settings
|
||||
|
||||
settings = get_settings()
|
||||
|
||||
app = FastAPI(
|
||||
title="WhatsApp Centralizado - Flow Engine",
|
||||
version="1.0.0",
|
||||
)
|
||||
|
||||
|
||||
class ProcessMessageRequest(BaseModel):
|
||||
conversation_id: str
|
||||
contact: dict
|
||||
conversation: dict
|
||||
message: dict
|
||||
|
||||
|
||||
class ProcessMessageResponse(BaseModel):
|
||||
handled: bool
|
||||
flow_id: Optional[str] = None
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
def health_check():
|
||||
return {"status": "ok", "service": "flow-engine"}
|
||||
|
||||
|
||||
@app.post("/process", response_model=ProcessMessageResponse)
|
||||
async def process_message(
|
||||
request: ProcessMessageRequest,
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""Process an incoming message through the flow engine"""
|
||||
engine = FlowEngine(db)
|
||||
|
||||
handled = await engine.process_message(
|
||||
conversation_id=request.conversation_id,
|
||||
contact=request.contact,
|
||||
conversation=request.conversation,
|
||||
message=request.message,
|
||||
)
|
||||
|
||||
return ProcessMessageResponse(handled=handled)
|
||||
Reference in New Issue
Block a user