whatsapp broadcast

This commit is contained in:
debu-2 2026-10-13 03:14:52 +05:30
parent 63011f7d96
commit 70ccb720aa
9 changed files with 570 additions and 4 deletions

View file

@ -24,14 +24,17 @@ from .whatsapp_onboarding import (
account_logs,
complete_signup,
connect_with_token,
create_marketing_template,
customer_token_for_phone,
developer_config,
disconnect_account,
download_account_media,
enable_customer_delivery,
list_account_messages,
list_accounts,
mask_identifier,
register_phone_number,
send_account_broadcast,
send_account_message,
list_templates,
refresh_account,
@ -180,6 +183,20 @@ class SendWhatsAppTextRequest(BaseModel):
phone_number_id: str = Field(min_length=4, max_length=64)
class MarketingTemplateRequest(BaseModel):
name: str = Field(min_length=1, max_length=512)
language: str = Field(default="en", max_length=16)
body: str = Field(min_length=1, max_length=1024)
class BroadcastSendRequest(BaseModel):
template_name: str = Field(min_length=1, max_length=512)
template_language: str = Field(default="en", max_length=16)
recipients: list[str] = Field(min_length=1, max_length=20)
body_parameters: list[str] = Field(default_factory=list, max_length=10)
product_policy: str = "STRICT"
class CustomerSendRequest(BaseModel):
to: str = Field(min_length=8, max_length=20)
message_type: str = "text"
@ -200,6 +217,10 @@ class RegisterPhoneRequest(BaseModel):
pin: str | None = Field(default=None, max_length=6)
class DeliverySecretRequest(BaseModel):
app_secret: str = Field(min_length=8, max_length=256)
class ManualTokenRequest(BaseModel):
access_token: str = Field(min_length=1, max_length=4096)
waba_id: str = Field(min_length=1, max_length=64)
@ -285,6 +306,16 @@ def whatsapp_account_messages(
return list_account_messages(db, user, account_id, limit)
@router.post("/accounts/{account_id}/delivery")
async def whatsapp_account_delivery(
account_id: str,
payload: DeliverySecretRequest,
db: Session = Depends(get_db),
user: UserAccount = Depends(current_user),
) -> dict:
return await enable_customer_delivery(db, user, account_id, payload.app_secret)
@router.post("/accounts/{account_id}/messages/send")
async def whatsapp_account_send(
account_id: str,
@ -295,6 +326,35 @@ async def whatsapp_account_send(
return await send_account_message(db, user, account_id, payload.model_dump())
@router.post("/accounts/{account_id}/templates")
async def whatsapp_account_create_template(
account_id: str,
payload: MarketingTemplateRequest,
db: Session = Depends(get_db),
user: UserAccount = Depends(current_user),
) -> dict:
return await create_marketing_template(db, user, account_id, payload.name, payload.language, payload.body)
@router.post("/accounts/{account_id}/broadcasts")
async def whatsapp_account_broadcast(
account_id: str,
payload: BroadcastSendRequest,
db: Session = Depends(get_db),
user: UserAccount = Depends(current_user),
) -> dict:
return await send_account_broadcast(
db,
user,
account_id,
payload.template_name,
payload.template_language,
payload.recipients,
payload.body_parameters,
payload.product_policy,
)
@router.get("/accounts/{account_id}/media/{media_id}")
async def whatsapp_account_media(
account_id: str,