Update app/routes/pipeline.py
Browse files- app/routes/pipeline.py +26 -9
app/routes/pipeline.py
CHANGED
@@ -14,33 +14,50 @@ router = APIRouter(
|
|
14 |
dependencies=[Depends(require_api_key)]
|
15 |
)
|
16 |
|
17 |
-
|
|
|
18 |
|
19 |
@router.on_event("startup")
|
20 |
def startup_db():
|
|
|
21 |
init_db()
|
22 |
|
23 |
@router.get("/run", summary="Run full multi‑agent pipeline")
|
24 |
def run_pipeline(
|
25 |
-
niche: str = Query("fitness"),
|
26 |
-
business_type: str = Query("dropshipping")
|
27 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
manager = AgentManager(niche, business_type)
|
29 |
summary = manager.run_all()
|
30 |
-
|
|
|
31 |
for agent_name, result in summary.items():
|
32 |
log_action(agent_name, "pipeline_run", result)
|
|
|
|
|
33 |
payload = {
|
34 |
"niche": niche,
|
35 |
"business_type": business_type,
|
|
|
36 |
"results": summary,
|
37 |
"timestamp": datetime.utcnow().isoformat()
|
38 |
}
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
44 |
return {
|
45 |
"status": "pipeline_executed",
|
46 |
**payload
|
|
|
14 |
dependencies=[Depends(require_api_key)]
|
15 |
)
|
16 |
|
17 |
+
# Webhook URL for Zapier; set this as ZAPIER_WEBHOOK in your HF Secrets
|
18 |
+
WEBHOOK_URL = os.getenv("ZAPIER_WEBHOOK")
|
19 |
|
20 |
@router.on_event("startup")
|
21 |
def startup_db():
|
22 |
+
"""Initialize the SQLite database on startup."""
|
23 |
init_db()
|
24 |
|
25 |
@router.get("/run", summary="Run full multi‑agent pipeline")
|
26 |
def run_pipeline(
|
27 |
+
niche: str = Query("fitness", description="Business niche"),
|
28 |
+
business_type: str = Query("dropshipping", description="Type of business")
|
29 |
):
|
30 |
+
"""
|
31 |
+
Executes Strategy, Copy, Ads & Email agents in sequence,
|
32 |
+
logs each result to the database, fires a Zapier webhook,
|
33 |
+
and returns a combined JSON summary.
|
34 |
+
"""
|
35 |
+
# 1. Run all agents
|
36 |
manager = AgentManager(niche, business_type)
|
37 |
summary = manager.run_all()
|
38 |
+
|
39 |
+
# 2. Log each agent's output
|
40 |
for agent_name, result in summary.items():
|
41 |
log_action(agent_name, "pipeline_run", result)
|
42 |
+
|
43 |
+
# 3. Build the payload (include a test email for Zapier mapping)
|
44 |
payload = {
|
45 |
"niche": niche,
|
46 |
"business_type": business_type,
|
47 |
+
"email": "[email protected]", # replace with real user email later
|
48 |
"results": summary,
|
49 |
"timestamp": datetime.utcnow().isoformat()
|
50 |
}
|
51 |
+
|
52 |
+
# 4. Fire the webhook (non‑blocking)
|
53 |
+
if WEBHOOK_URL:
|
54 |
+
try:
|
55 |
+
requests.post(WEBHOOK_URL, json=payload, timeout=2)
|
56 |
+
except Exception:
|
57 |
+
# Silently ignore any webhook failures
|
58 |
+
pass
|
59 |
+
|
60 |
+
# 5. Return the pipeline summary
|
61 |
return {
|
62 |
"status": "pipeline_executed",
|
63 |
**payload
|