Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/rahul-baberwal/django-meta-whatsapp/llms.txt

Use this file to discover all available pages before exploring further.

WhatsApp requires pre-approved message templates for outbound marketing and utility messages. django-meta-whatsapp lets you sync approved templates from Meta, create new templates in the dashboard, and push them to Meta for review — all without leaving your Django project.

WhatsAppTemplate model fields

FieldTypeDescription
accountFK → WhatsAppAccountThe WhatsApp account this template belongs to
nameCharFieldTemplate name — must match Meta’s naming rules: lowercase letters, numbers, and underscores only
meta_template_idCharFieldThe ID returned by Meta after the template is created
languageCharFieldBCP-47 language code, default "en"
categoryCharFieldMARKETING, UTILITY, or AUTHENTICATION
statusCharFieldAPPROVED, PENDING, REJECTED, or DRAFT
headerJSONFieldOptional header component: {"type": "TEXT"|"IMAGE"|"VIDEO"|"DOCUMENT", "text": "..."}
body_textTextFieldTemplate body text. Use {{1}}, {{2}} … for variables
footer_textCharFieldOptional footer line below the body
buttonsJSONFieldOptional list of buttons: [{"type": "QUICK_REPLY", "text": "Yes"}]

Syncing templates from Meta

Pull all approved and pending templates from your WhatsApp Business Account into the local database. Via the dashboard: navigate to /whatsapp/templates/ and click the Sync from Meta button. This calls TemplateSyncFromMetaView, which requires WABA_ID to be configured on the active account or in WHATSAPP['WABA_ID'] in settings. Via Python:
from django_meta_whatsapp.utils import sync_templates_from_meta
from django_meta_whatsapp.models import WhatsAppAccount

account = WhatsAppAccount.objects.get(pk=1)
templates = sync_templates_from_meta(account=account)
print(f"Synced {len(templates)} templates")
sync_templates_from_meta returns the raw list of template dicts from Meta’s Graph API. The dashboard view then calls WhatsAppTemplate.objects.update_or_create(...) for each one. Via management command:
python manage.py wa_sync_templates
# or target a specific account:
python manage.py wa_sync_templates --account-id 1

Creating a template

Build a new template locally at /whatsapp/templates/add/. After saving, the template has status="DRAFT" and exists only in your database. Click Push to Meta on the template detail page to submit it for review. Pushing to Meta via Python:
from django_meta_whatsapp.utils import push_template_to_meta
from django_meta_whatsapp.models import WhatsAppTemplate

template = WhatsAppTemplate.objects.get(name="order_update")
push_template_to_meta(template)
push_template_to_meta assembles a components array from the template’s header, body_text, footer_text, and buttons fields and POSTs it to /{waba_id}/message_templates on the Graph API. After a successful call, Meta sets the template status to PENDING until it is reviewed.

Template variables

Use {{1}}, {{2}}, … as ordered placeholders in body_text (and optionally in header when the header type is TEXT). At send time, supply values for each placeholder using build_template_components:
from django_meta_whatsapp.utils import build_template_components, send_template_message

components = build_template_components(
    body_params=["Rahul", "ORD-999"],   # fills {{1}}, {{2}} in body
    header_params=["Order Update"],      # fills {{1}} in header (if TEXT header)
)

send_template_message(
    "919876543210",
    template_name="order_update",
    language_code="en",
    components=components
)
build_template_components also accepts a buttons list for dynamic URL or quick-reply payloads:
build_template_components(
    body_params=["Rahul"],
    buttons=[{"index": 0, "sub_type": "url", "payload": "ORD-999"}]
)

Template statuses

StatusMeaning
APPROVEDReviewed and approved by Meta — ready to use in campaigns and direct sends
PENDINGSubmitted to Meta and awaiting review (typically 24–48 hours)
REJECTEDRejected by Meta — edit and re-submit via Push to Meta
DRAFTCreated locally, not yet pushed to Meta

Template categories

CategoryUse case
MARKETINGPromotional messages, product announcements, offers
UTILITYTransactional messages such as order confirmations, receipts, and shipping updates
AUTHENTICATIONOne-time passwords and verification codes
Only APPROVED templates can be used in campaign sends or direct send_template_message calls. Sending a non-approved template will result in an error from Meta.

Build docs developers (and LLMs) love