FOCUSCurrently working on ScheduleSomething and LayerdEvents algorithmsLearn More
FOCUSCurrently working on ScheduleSomething and LayerdEvents algorithmsLearn More
FOCUSCurrently working on ScheduleSomething and LayerdEvents algorithmsLearn More
FOCUSCurrently working on ScheduleSomething and LayerdEvents algorithmsLearn More
Tide OsBackend Modules
Meta Templates Engine Module
Docstide-osBackend ModulesMeta Templates Engine Module
GitHub Live Sync

Meta Templates Engine Module

Live technical documentation fetched from GitHub repository omghante/metapilot/docs/modules/templates.md

Templates Module Specification

1. Purpose & Overview

The
templates
module handles WhatsApp Highly Structured Message (HSM) templates, variable placeholders, and approval workflows with Meta.

2. Responsibilities

  • Maintain
    Template
    and
    TemplateComponent
    domain models.
  • Track Meta approval states (
    APPROVED
    ,
    PENDING
    ,
    REJECTED
    ).
  • Provide variable binding services for campaign message generation.

3. Directory Structure

text
services/api/templates/
├── admin.py
├── apps.py
├── migrations/
├── models.py
├── serializers.py
└── views.py

4. Models & Database Schemas

python
class TemplateStatus(models.TextChoices):
    PENDING = 'PENDING', 'Pending'
    APPROVED = 'APPROVED', 'Approved'
    REJECTED = 'REJECTED', 'Rejected'

class Template(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4)
    tenant = models.ForeignKey('tenants.Tenant', on_delete=models.CASCADE)
    name = models.CharField(max_length=255)
    category = models.CharField(max_length=50) # 'MARKETING', 'UTILITY'
    language = models.CharField(max_length=10, default='en_US')
    components = models.JSONField(default=list) # HEADER, BODY, FOOTER, BUTTONS
    status = models.CharField(max_length=20, choices=TemplateStatus.choices, default=TemplateStatus.PENDING)

5. Services & Business Logic

  • Template.render_body(variables_dict)
    : Replaces
    {{1}}
    ,
    {{2}}
    placeholders with customer variable data.

6. Serializers & Data Transfer Objects

  • TemplateSerializer
    : Validates structure of header, body, footer, and button components.

7. Views & API Endpoints

  • GET /api/templates/
    : List approved templates.
  • POST /api/templates/
    : Submit new template for Meta approval.

8. Permissions & Role Rules

  • TENANT_ADMIN
    &
    TENANT_USER
    : Access templates within active tenant.

9. Signals & Event Listeners

  • post_save
    : Notifies team when a pending template is approved by Meta.

10. Background Tasks & Celery Jobs

  • Periodic task syncs template statuses from Meta Graph API.

11. Data Flow & External Dependencies

  • Integrates with Meta WhatsApp Graph API (
    v22.0
    ) for template creation & status sync.

12. Business Rules & Validations

  • Template names must contain only lowercase alphanumeric characters and underscores.
  • Body components must contain valid numbered placeholders (
    {{1}}
    ).

13. Sequence Diagram (Mermaid)

Rendering diagram...

14. Known Limitations & Technical Debt

  • Local edits to templates must be synced back with Meta's developer portal.

15. Future Improvements

  • Add interactive Drag-and-Drop WhatsApp Template Builder in Next.js UI.