This commit is contained in:
debu-2 2026-10-15 01:58:00 +05:30
parent 8901d99dd2
commit 29d867438c
7 changed files with 645 additions and 5 deletions

View file

@ -1,7 +1,7 @@
import json
import logging
from fastapi import APIRouter, Depends, Header, HTTPException, Query, Request, Response, status
from fastapi import APIRouter, Depends, File, Form, Header, HTTPException, Query, Request, Response, UploadFile, status
from pydantic import BaseModel, Field
from sqlalchemy import or_, select
from sqlalchemy.orm import Session
@ -16,6 +16,7 @@ from .models import (
WhatsAppPhoneAsset,
WhatsAppWebhookEvent,
)
from .whatsapp_broadcast_jobs import create_csv_broadcast, list_broadcast_jobs
from .whatsapp_graph_client import WhatsAppGraphClient, WhatsAppGraphError
from .whatsapp_config import resolved_whatsapp_app_secret
from .whatsapp_onboarding import (
@ -359,6 +360,47 @@ async def whatsapp_account_broadcast(
)
@router.get("/accounts/{account_id}/broadcasts/jobs")
def whatsapp_broadcast_jobs(
account_id: str,
db: Session = Depends(get_db),
user: UserAccount = Depends(current_user),
) -> list[dict]:
return list_broadcast_jobs(db, user, account_id)
@router.post("/accounts/{account_id}/broadcasts/csv")
async def whatsapp_broadcast_csv(
account_id: str,
file: UploadFile = File(),
country_code: str = Form(default="91"),
template_name: str = Form(),
template_language: str = Form(default="en"),
product_policy: str = Form(default="STRICT"),
use_sample_header: str = Form(default="false"),
body_parameters: str = Form(default=""),
db: Session = Depends(get_db),
user: UserAccount = Depends(current_user),
) -> dict:
raw = await file.read()
if len(raw) > 1_000_000:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="The CSV must be under 1 MB.")
parameters = [line.strip() for line in body_parameters.splitlines() if line.strip()]
return await create_csv_broadcast(
db,
user,
account_id,
file.filename or "broadcast.csv",
raw,
country_code=country_code,
template_name=template_name,
template_language=template_language,
body_parameters=parameters,
product_policy=product_policy,
use_sample_header=use_sample_header.strip().lower() in {"1", "true", "yes", "on"},
)
@router.get("/accounts/{account_id}/media/{media_id}")
async def whatsapp_account_media(
account_id: str,