# WhatsApp Messaging

<p class="doc-lead">Share sale documents with customers on WhatsApp — instantly from the invoice screen, or automatically through the Notification System using Meta-approved templates.</p>

<div class="doc-toc">
<p class="doc-toc-title">On this page</p>
<div class="doc-toc-section">
<span class="doc-toc-group-title">Quick send</span>
<div class="doc-toc-links">
<a href="#/features/whatsapp?id=quick-send">Send from Sale Invoice</a>
</div>
</div>
<div class="doc-toc-section">
<span class="doc-toc-group-title">Notification System setup</span>
<div class="doc-toc-links">
<a href="#/features/whatsapp?id=overview">Overview</a>
<a href="#/features/whatsapp?id=prerequisites">Prerequisites</a>
<a href="#/features/whatsapp?id=quick-start">Quick Start — Full Setup</a>
<a href="#/features/whatsapp?id=provider-setup">1. WhatsApp Provider</a>
<a href="#/features/whatsapp?id=template-setup">2. WhatsApp Template</a>
<a href="#/features/whatsapp?id=template-parameters">Template parameters</a>
<a href="#/features/whatsapp?id=recipient-setup">3. Recipient Rule</a>
<a href="#/features/whatsapp?id=config-setup">4. Transaction Config</a>
</div>
</div>
<div class="doc-toc-section">
<span class="doc-toc-group-title">Reference</span>
<div class="doc-toc-links">
<a href="#/features/whatsapp?id=examples">Worked Examples</a>
<a href="#/features/whatsapp?id=history">Transaction History</a>
<a href="#/features/whatsapp?id=faq">FAQ</a>
</div>
</div>
</div>

<hr class="doc-section-divider">

<h2 id="quick-send">Send from Sale Invoice</h2>

The fastest way to share an invoice — no Notification System setup required.

<ol>
<li>Open a <b>Sale Invoice</b>.</li>
<li>Ensure the customer master has a valid <b>Phone</b> number. The button is hidden when phone is blank.</li>
<li>Click <b>Send to Whatsapp</b> on the view toolbar.</li>
<li>WhatsApp opens (web or app) with a pre-filled message containing the invoice type (Cash/Credit), bill number, amount, date, and a <b>PDF download link</b>.</li>
<li>Review the message and send from your WhatsApp account.</li>
</ol>

<p><b>What the message contains.</b> A short thank-you line, whether the invoice is Cash or Credit, the bill number and total, the invoice date, and a link to download the PDF (<code>save.freespaceerp.com/pdf</code> using the document's public token). This does <b>not</b> send through the Notification System — it opens your device's WhatsApp client with the text ready to send.</p>

<p><b>Related:</b> <a href="#/sales/sale-invoice">Sale Invoice</a> · <a href="#/sales/customers">Customers</a></p>

<hr class="doc-section-divider">

<h2 id="overview">Overview — Notification System</h2>

For **automated** WhatsApp messages on document status change (e.g. on approve), or templated messages through **WhatsApp Cloud API** or **WATI**, configure the Notification System:

| Component | Purpose |
|-----------|---------|
| <b>Providers</b> | Connect to WhatsApp Cloud or WATI with API credentials. |
| <b>Templates</b> | Map Meta-approved template names and parameters to ERP document fields. |
| <b>Recipient Rules</b> | Resolve customer phone from the document. |
| <b>Transaction Configs</b> | Define when to send (document type + status + channel). |
| <b>Transaction History</b> | Audit log of queued, sent, and failed messages. |

<p>This is separate from the in-app <b>Notifications</b> inbox (bell icon) and separate from the <b>Send to Whatsapp</b> quick-link on invoices. See <a href="#/settings/notification-settings">Notifications</a> vs <a href="#/settings/settings?id=notification-system">Notification System</a>.</p>

<p>Your company plan must include the <b>WhatsApp</b> feature for Notification System sends. Contact support if Transaction Configs do not queue messages.</p>

<hr class="doc-section-divider">

<h2 id="prerequisites">Prerequisites</h2>

<ul>
<li><b>WhatsApp Business</b> account with Meta Business Manager (for WhatsApp Cloud) or a WATI account.</li>
<li><b>Approved message templates</b> on Meta — template name, language, and body structure must match exactly in Freespace.</li>
<li><b>Customer mobile</b> on the party master (<b>Phone</b> or <b>Secondary Phone</b>) in a format the API can normalize (include country code where required).</li>
<li><b>Admin access</b> to Settings → Notification System.</li>
</ul>

<hr class="doc-section-divider">

<h2 id="quick-start">Quick Start — Full Setup</h2>

<h3>Step 1 — Provider</h3>

<b>Settings → Notification System → Providers → New</b>

| Field | WhatsApp Cloud example |
|-------|------------------------|
| Name | WhatsApp Cloud Main |
| Provider Type | WhatsApp Cloud |
| API Endpoint | https://graph.facebook.com/v18.0 |
| Phone Number ID | *(from Meta developer console)* |
| Access Token | *(permanent or system user token)* |

For **WATI**, select Provider Type <b>WATI</b>, endpoint <b>https://api.wati.io</b>, and API Token instead.

<h3>Step 2 — Template</h3>

<b>Settings → Notification System → Templates → New</b>

| Field | Example |
|-------|---------|
| Provider Type | WhatsApp Cloud |
| Channel | WhatsApp |
| Name | Invoice Approved WhatsApp |
| Template Name (API) | invoice_approved_default *(must match Meta exactly)* |
| Language Code | en_US |
| Template Category | UTILITY |
| Template Components | Header type and buttons if your Meta template uses them |

<h3>Step 2b — Template parameters</h3>

Add one row per variable in your Meta template body (and header, if TEXT header with variables):

| Parameter Name | Field Path | Component Type | Data Type | Order |
|----------------|------------|----------------|-----------|-------|
| 1 | customer.name | Body | String | 1 |
| 2 | billNumber | Body | String | 2 |
| 3 | netTotal | Body | Currency | 3 |

<p><b>Parameter Name</b> must match the variable position or name in your Meta-approved template (often <code>1</code>, <code>2</code>, <code>3</code> for positional templates). <b>Field Path</b> is the document field the API reads — see <a href="#/features/whatsapp?id=template-parameters">Template parameters</a>.</p>

Use <b>Preview</b> on the template to validate parameter resolution before go-live.

<h3>Step 3 — Recipient Rule</h3>

<b>Settings → Notification System → Recipient Rules → New</b>

| Step | Step Type | Recipient Type | Recipient ID Field Path |
|------|-----------|----------------|-------------------------|
| 1 | resolve | customer | customerId |

<p><b>Recipient ID Field Path</b> is the field on the loaded document that holds the customer ID — typically <code>customerId</code>. The API then reads <code>phone</code> or <code>secondaryPhone</code> from the customer master.</p>

<h3>Step 4 — Transaction Config</h3>

<b>Settings → Notification System → Transaction Configs → New</b>

| Field | Example |
|-------|---------|
| Use for Manual Send | Leave unchecked *(WhatsApp manual send from compose is not supported — use automatic configs)* |
| Transaction Type | Sale Invoice |
| Transaction Status | Approved |
| Channel | WhatsApp |
| Default Provider | WhatsApp Cloud Main |
| Notification Template | Invoice Approved WhatsApp |
| Default Recipient Rule | Customer Mobile Rule |
| Delay (minutes) | 0 or 5 *(optional wait before send)* |

Save. Approve a test invoice and check <b>Transaction History</b>.

<hr class="doc-section-divider">

<h2 id="provider-setup">1. WhatsApp Provider</h2>

<p><b>ERP path:</b> Settings → Notification System → Providers</p>

See <a href="#/settings/notification-providers">Notification Providers</a> for list actions and suspend/activate.

<h3>WhatsApp Cloud Configuration</h3>

| Field | Description |
|-------|-------------|
| API Endpoint | Meta Graph API base URL (default https://graph.facebook.com/v18.0). |
| Phone Number ID * | Sender phone number ID from Meta Business suite. |
| Access Token * | API token with WhatsApp message permissions. |

<h3>WATI Configuration</h3>

| Field | Description |
|-------|-------------|
| API Endpoint * | https://api.wati.io |
| Phone Number ID * | WATI phone identifier. |
| API Token * | WATI API bearer token. |

<hr class="doc-section-divider">

<h2 id="template-setup">2. WhatsApp Template</h2>

<p><b>ERP path:</b> Settings → Notification System → Templates</p>

See also: <a href="#/settings/notification-templates">Notification Templates</a>.

<h3>General</h3>

| Field | Description |
|-------|-------------|
| Provider Type * | WhatsApp Cloud or WATI |
| Name * | Internal template name. |
| Channel * | WhatsApp |
| Template Name (API) * | Exact name registered and approved on Meta / WATI. Case-sensitive. |
| Language Code * | Must match approved template (e.g. en_US). |
| Template Category * | UTILITY, MARKETING, etc. |
| Priority | Lower number = higher priority when multiple templates match. |

<h3>Template Components</h3>

Match the structure of your Meta-approved template:

| Field | Description |
|-------|-------------|
| Header Type | None, Text, Image, Video, or Document — must match Meta template header. |
| Buttons | Optional URL or Quick Reply buttons with index positions matching Meta. |

Email-only sections (Email Subject, Email Body) are hidden when Channel is WhatsApp.

<h3 id="template-parameters">Template parameters</h3>

<p>Each row maps a Meta template variable to a field on the transaction record. When a notification fires, the API loads the document, resolves each <b>Field Path</b>, and builds the WhatsApp Cloud API payload.</p>

<p><b>How it works</b></p>

<ol>
<li>Add a parameter row with <b>Component Type</b> matching your Meta template — <b>Header</b> or <b>Body</b> (and <b>Button</b> if applicable).</li>
<li><b>Parameter Name</b> — the Meta variable identifier. For positional templates this is typically <code>1</code>, <code>2</code>, <code>3</code> in the order they appear in the approved template body.</li>
<li><b>Field Path</b> — dot-notation path on the loaded document JSON. Do <b>not</b> prefix with the transaction type (<code>customer.name</code>, not <code>saleInvoice.customer.name</code>).</li>
<li><b>Data Type</b> — String, Number, Currency, Date, URL, etc. Currency formats to two decimals; Date formats to <code>DD MMM YYYY</code>.</li>
<li><b>Order</b> — sort order for parameter resolution.</li>
</ol>

<p><b>Phone resolution</b> — Recipient Rules read <code>customer.phone</code> then <code>customer.secondaryPhone</code> (or supplier/employee equivalents). Template parameters supply the <b>message body variables</b> only.</p>

<h3>Common field paths (sale documents)</h3>

| Field Path | Description |
|------------|-------------|
| billNumber | Document number |
| date | Document date |
| dueDate | Payment due date |
| total | Grand total |
| netTotal | Net total after round-off |
| balance | Outstanding balance |
| customer.name | Customer name |
| customer.phone | Customer phone |
| customer.email | Customer email |
| employee.firstName | Sales employee first name |
| notes | Document notes |

<p>Supported <b>Transaction Types</b> for configs include Sale Invoice, Sale Order, Sale Quotation, Pro Forma Invoice, Credit Note, Delivery Note, Receipt Voucher, and Pay Run — check the Transaction Config form for the full list enabled on your plan.</p>

<p>Use <b>Preview</b> on the template record to validate parameter mapping before enabling automatic sends.</p>

<hr class="doc-section-divider">

<h2 id="recipient-setup">3. Recipient Rule</h2>

<p><b>ERP path:</b> Settings → Notification System → Recipient Rules</p>

See <a href="#/settings/notification-recipient-rules">Recipient Rules</a> for full field reference.

<b>Resolution Steps</b> define how the system finds the phone number:

| Step Type | Use when |
|-----------|----------|
| resolve | Look up customer, supplier, or employee contact from a field on the document. |
| manual | Use a fixed phone number if resolve fails or as the only step. |

Example — customer phone from sale invoice:

| Order | Step Type | Recipient Type | Recipient ID Field Path |
|-------|-----------|----------------|-------------------------|
| 1 | resolve | customer | customerId |

<p>For WhatsApp and SMS, the resolver tries <code>phone</code> then <code>secondaryPhone</code> on the customer (or <code>primaryPhone</code> / <code>secondaryPhone</code> on employees).</p>

<hr class="doc-section-divider">

<h2 id="config-setup">4. Transaction Config</h2>

<p><b>ERP path:</b> Settings → Notification System → Transaction Configs</p>

See <a href="#/settings/notification-transaction-configs">Transaction Configs</a>.

| Field | Description |
|-------|-------------|
| Transaction Type * | Document that triggers the message (e.g. Sale Invoice). |
| Transaction Status * | When to send (e.g. Approved). Hidden when <b>Use for Manual Send</b> is checked. |
| Channel * | WhatsApp |
| Default Provider * | WhatsApp provider record. |
| Notification Template * | Approved template mapping. |
| Default Recipient Rule | Who receives the message. |
| Delay (minutes) | Wait after trigger before sending. |
| Condition JSON | Optional filter (e.g. minimum amount). |
| Fallback Provider / Channel | Retry on another channel if primary fails. |

<p>Only <b>one active manual config</b> per transaction type and channel is allowed. WhatsApp does not use the email <b>Send Email</b> compose screen — automatic configs are the primary Notification System workflow for WhatsApp.</p>

<hr class="doc-section-divider">

<h2 id="examples">Worked Examples</h2>

<h3>Example A — Invoice approved WhatsApp (utility template)</h3>

<p><b>Meta template body:</b> "Hello {{1}}, your invoice {{2}} for {{3}} is ready."</p>

<p><b>Template parameters in Freespace:</b></p>

| Parameter Name | Field Path | Component Type | Data Type | Order |
|----------------|------------|----------------|-----------|-------|
| 1 | customer.name | Body | String | 1 |
| 2 | billNumber | Body | String | 2 |
| 3 | netTotal | Body | Currency | 3 |

<p><b>Config:</b> Sale Invoice + Approved + WhatsApp + 0 min delay + Customer recipient rule on <code>customerId</code>.</p>

<h3>Example B — Delay 5 minutes after approve</h3>

<p><b>Goal:</b> Allow time to cancel an invoice before WhatsApp goes out.</p>

<p>Set <b>Delay (minutes)</b> = <b>5</b> on Transaction Config. Message appears in History as Queued until the delay elapses.</p>

<h3>Example C — Quick link vs Notification System</h3>

| Method | When to use |
|--------|-------------|
| <b>Send to Whatsapp</b> on invoice | Immediate share with PDF link; you send manually from your WhatsApp; no Meta template required. |
| Notification System | Meta-approved template text; automatic on approve; audit in History; requires provider + template + config setup. |

<hr class="doc-section-divider">

<h2 id="history">Transaction History</h2>

<p><b>ERP path:</b> Settings → Notification System → Transaction History</p>

Filter by Channel <b>WhatsApp</b> or status <b>Failed</b> to troubleshoot.

| Status | Meaning |
|--------|---------|
| Queued | Waiting for delay or background worker |
| Sent | Accepted by WhatsApp Cloud / WATI API |
| Failed | Template, phone, or token error — open row for message |

Common failure reasons: template name mismatch, parameter count mismatch, invalid phone format, expired access token, customer opted out.

See <a href="#/settings/notification-transaction-history">Transaction History</a>.

<hr class="doc-section-divider">

<h2 id="faq">FAQ</h2>

<p><b>Send to Whatsapp vs Notification System — which should I use?</b></p>
<p><b>Send to Whatsapp</b> opens WhatsApp with a pre-filled message and PDF link — you tap Send in WhatsApp yourself. The Notification System sends Meta template messages automatically on approve and logs every attempt in History.</p>

<p><b>Does Send to Whatsapp attach the PDF?</b></p>
<p>No. It includes a download link in the message text. The customer opens the link to view or save the PDF.</p>

<p><b>Customer did not receive WhatsApp. What to check?</b></p>
<ul>
<li>Customer <b>Phone</b> on master — correct country code, no typos.</li>
<li><b>Transaction History</b> — status Failed? Read the error message.</li>
<li>Template Name (API) matches Meta exactly (case-sensitive).</li>
<li>Parameter count and order match the approved Meta template.</li>
<li>Provider Access Token not expired.</li>
<li>Customer has opted in / not blocked the business number (Meta policy).</li>
</ul>

<p><b>Must templates be approved on Meta first?</b></p>
<p>Yes for WhatsApp Cloud. Create and approve templates in Meta Business Manager, then copy the exact template name and language into Freespace.</p>

<p><b>Can I have multiple WhatsApp numbers?</b></p>
<p>Yes — create separate Provider records with different Phone Number IDs and link each on the relevant Transaction Config.</p>

<p><b>Can I send WhatsApp and email for the same approve event?</b></p>
<p>Yes — create two Transaction Configs: one Channel WhatsApp, one Channel Email, both on Approved status for the same transaction type.</p>

<p><b>Why is a message stuck in Queued?</b></p>
<p>Delay not elapsed, background worker not running, or provider rate limit. Refresh History after a few minutes; check Failed tab.</p>

<p><b>Does WhatsApp use Recipient Rules for Send to Whatsapp?</b></p>
<p>No. <b>Send to Whatsapp</b> uses <code>customer.phone</code> on the invoice. Recipient Rules apply to Notification System sends only.</p>

<p><b>Why is parameter {{2}} empty in Preview or on send?</b></p>
<p>Check the <b>Field Path</b> on the matching Template Parameter row. Use document-relative paths like <code>billNumber</code> and <code>customer.name</code>, not <code>saleInvoice.billNumber</code>. Ensure the field has a value on the test document.</p>

<hr class="doc-section-divider">

<h2 id="related">Related Topics</h2>

<ul>
<li><a href="#/features/email-notifications">Email Notifications</a></li>
<li><a href="#/settings/notification-providers">Notification Providers</a></li>
<li><a href="#/settings/notification-templates">Notification Templates</a></li>
<li><a href="#/settings/notification-transaction-configs">Transaction Configs</a></li>
<li><a href="#/settings/notification-recipient-rules">Recipient Rules</a></li>
<li><a href="#/settings/notification-transaction-history">Transaction History</a></li>
<li><a href="#/sales/sale-invoice">Sale Invoice</a></li>
<li><a href="#/sales/customers">Customers</a></li>
</ul>
