template
This commit is contained in:
parent
a109df2deb
commit
8901d99dd2
11 changed files with 380 additions and 13 deletions
|
|
@ -1318,6 +1318,7 @@ async def send_account_broadcast(
|
|||
recipients: list[str],
|
||||
body_parameters: list[str] | None = None,
|
||||
product_policy: str = "STRICT",
|
||||
use_sample_header: bool = False,
|
||||
) -> dict[str, Any]:
|
||||
"""Send a marketing template through Meta's marketing endpoint."""
|
||||
account = _owned_account(db, user, account_id)
|
||||
|
|
@ -1337,14 +1338,20 @@ async def send_account_broadcast(
|
|||
if len(numbers) > 20:
|
||||
raise HTTPException(status_code=422, detail="A test broadcast can include up to 20 numbers.")
|
||||
parameters = [str(item).strip() for item in (body_parameters or []) if str(item).strip()]
|
||||
components = None
|
||||
components: list[dict[str, Any]] = []
|
||||
if use_sample_header:
|
||||
from .whatsapp_template_service import header_parameter_for_send
|
||||
|
||||
components.append(
|
||||
await header_parameter_for_send(db, user, account, token, phone.phone_number_id, name, language)
|
||||
)
|
||||
if parameters:
|
||||
components = [
|
||||
components.append(
|
||||
{
|
||||
"type": "body",
|
||||
"parameters": [{"type": "text", "text": item} for item in parameters],
|
||||
}
|
||||
]
|
||||
)
|
||||
client = WhatsAppGraphClient(
|
||||
access_token=token,
|
||||
phone_number_id=phone.phone_number_id,
|
||||
|
|
@ -1366,7 +1373,7 @@ async def send_account_broadcast(
|
|||
recipient,
|
||||
name,
|
||||
language_code=language,
|
||||
components=components,
|
||||
components=components or None,
|
||||
product_policy=policy,
|
||||
)
|
||||
except WhatsAppGraphError as exc:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue