# PILOT-006

## Message Template & Delivery Engine

You are implementing the sixth Pilot Launch feature for the INVEETAIRE platform.

Current Status

✅ Sprint 0 Complete

✅ Sprint 1 Complete

✅ Sprint 2 Complete

✅ Sprint 3 Complete

✅ PILOT-001 Invitation Engine

✅ PILOT-002 Guest Import

✅ PILOT-003 Public Guest Identity Layer

✅ PILOT-004 Public Invitation Rendering

✅ PILOT-005 Guest Interaction Engine

Implement ONLY the Message Template & Delivery Engine.

Do NOT implement WhatsApp API.

Do NOT implement WuzAPI.

Do NOT implement QR Check-In.

Do NOT implement Attendance Dashboard.

---

# Goal

Allow Couples to send personalized wedding invitations through WhatsApp Deep Links.

The architecture must be provider-independent.

Today's delivery channel:

WhatsApp Deep Link (wa.me)

Future channels:

* WuzAPI
* WhatsApp Cloud API
* Email
* SMS

Business logic must not depend on any provider.

---

# Mandatory Reading

Read:

* AI.md
* WORKFLOW.md
* IMPLEMENTATION_ROADMAP.md

Read implementation memories:

* PILOT-001
* PILOT-002
* PILOT-003
* PILOT-004
* PILOT-005

---

# Files Allowed

Create:

app/modules/Messaging/

```
MessageTemplateService.php

MessageDeliveryService.php

MessageController.php

MessageModel.php

routes.php
```

app/views/message/

```
template.php

preview.php
```

Modify:

routes/couple.php

No other files.

---

# Functional Scope

Implement ONLY:

## Message Template Management

Allow Couple/Admin to edit the invitation message template.

Store the template using the existing message_templates table.

Support placeholders.

Do NOT hardcode message text.

---

## Supported Placeholders

Implement at minimum:

{{guest_name}}

{{bride_name}}

{{groom_name}}

{{couple_name}}

{{invitation_url}}

{{holy_information}}

{{reception_information}}

{{wedding_date}}

{{workspace_name}}

Unknown placeholders must remain unchanged.

---

## Event Information

Generate dynamically.

If guest is invited only to Holy Matrimony:

Render only Holy information.

If guest is invited only to Reception:

Render only Reception information.

If guest is invited to both:

Render both sections in chronological order.

No empty labels.

No hardcoded if/else inside templates.

---

## Invitation URL

Reuse the Guest Identity Layer.

Every generated message must contain the guest's personal invitation URL.

Never expose guest_id.

Never expose workspace_id.

---

## WhatsApp Deep Link

Generate:

https://wa.me/{phone}?text={urlencoded_message}

Do NOT send automatically.

Open WhatsApp only.

User manually presses Send.

---

## Guest List Integration

For every guest provide:

* Preview Message
* Copy Message
* Copy Invitation Link
* Open WhatsApp

No bulk sending yet.

No scheduling.

---

# Service Responsibilities

MessageTemplateService

* Placeholder replacement
* Event rendering
* Message composition

MessageDeliveryService

* WhatsApp URL generation
* Copy payload generation
* Future provider abstraction

No SQL.

No HTML.

---

# Model Responsibilities

Own:

* message_templates retrieval
* template persistence

Prepared PDO statements only.

Workspace isolation mandatory.

---

# Security

Verify:

Workspace isolation.

Prepared statements.

escape_html().

No internal IDs exposed.

Unknown placeholders safely preserved.

URL encoding performed before WhatsApp link generation.

---

# Constraints

Do NOT:

* implement WhatsApp API
* implement WuzAPI
* implement Email
* implement SMS
* implement Bulk Sending
* implement Scheduling
* implement QR Check-In
* modify app/core/*
* modify database schema
* perform git operations

---

# Verification

Verify:

Template save.

Placeholder replacement.

Holy-only rendering.

Reception-only rendering.

Dual-event rendering.

Invitation URL generation.

WhatsApp Deep Link generation.

Workspace isolation.

PHP syntax.

---

# Acceptance Criteria

PASS only if:

* Messaging module created.
* Template editor created.
* Placeholder engine implemented.
* Message preview works.
* WhatsApp Deep Link generated.
* Provider-independent architecture established.
* Workspace isolation maintained.
* PHP syntax passes.
* Scope respected.

---

# Output

Provide:

1. Files created.
2. Files modified.
3. Template workflow.
4. Placeholder workflow.
5. Event rendering workflow.
6. WhatsApp delivery workflow.
7. Security verification.
8. Acceptance checklist.
9. PHP syntax results.

Stop after implementation.

Wait for Human Approval.
