WhatsApp Cloud API & Frappe/ERPNext Integration Guide
This guide walks you through the entire end-to-end process of setting up Meta's official WhatsApp Business Cloud API—from personal Facebook account setup and System User permanent token generation to configuring the shridarpatil/frappe_whatsapp app inside Frappe / ERPNext for automated and template messaging.
Architectural Workflow
Meta Cloud Infrastructure
-------------------------
[Personal Facebook Account + 2FA]
|
v
[Meta Business Account / Portfolio]
|
+--> [Meta for Developers: Business App] --> [WhatsApp Product / Phone Number ID / WABA ID]
| | |
| +-- (Assign App Asset) -----+ | (Assign WABA Asset)
| v v
+-------------------------------> [System User: Admin Role]
|
v
[Permanent Access Token: Never Expire]
Frappe / ERPNext Site
---------------------
[Install frappe_whatsapp via Bench]
|
v
[WhatsApp Account DocType] <-- (Inject Token & IDs from Permanent Access Token)
|
+--> [WhatsApp Profile & Business Sync]
|
+--> [WhatsApp Template Sync from Meta]
|
v
[WhatsApp Notification Engine]
| (Auto Trigger on Doc Events: Submit / Save)
v
[WhatsApp Message Log] --> (Outbound HTTPS REST Request to Meta Cloud API)
Phase 1: Personal Facebook Account & Security Prerequisites
Meta requires every Business Account and Developer App to be anchored to a verified personal Facebook identity for legal accountability.
1.1 Account Creation
- Go to facebook.com and click Create new account.
- Enter your legal First Name, Last Name, Corporate/Personal Email, Password, Date of Birth, and Gender.
Important: Use your real legal name matching your government-issued ID. Meta frequently suspends accounts using aliases or company abbreviations during business verification.
- Verify your email address using the numeric confirmation code sent to your inbox.
1.2 Mandatory Two-Factor Authentication (2FA)
Meta enforces 2FA on any account that manages Business Portfolios, Developer Apps, or System Users.
- Navigate to Settings & Privacy > Settings > Accounts Center > Password and Security > Two-Factor Authentication.
- Select your account and choose Authentication App (Google Authenticator, Authy, or 1Password) instead of SMS for maximum reliability.
- Scan the QR code, submit the 6-digit TOTP code, and download your emergency recovery codes.
Phase 2: Meta Business Account (Business Portfolio)
A Meta Business Account (formerly Meta Business Manager) is the enterprise container that owns apps, WhatsApp accounts, payment methods, and system users.
2.1 Create the Business Account
- Open business.facebook.com/overview.
- Click Create an account (top-right).
- Fill in:
- Business Account Name: Your official company legal name (e.g.,
Acme Technologies Pvt Ltd). - Your Name: Your personal name (must match your personal account).
- Business Email Address: Corporate domain email (e.g.,
admin@acme.com).
- Business Account Name: Your official company legal name (e.g.,
- Click Submit and confirm the verification email received in your inbox.
2.2 Adding Payment Method (Required for Scaling)
- In Meta Business Settings, click Payment Methods in the left sidebar.
- Click Add Payment Method, select your country and currency, and enter your corporate credit/debit card.
- Set this card as the primary payment method.
Phase 3: Meta for Developers Account & App Creation
3.1 Register as a Meta Developer
- Go to developers.facebook.com and click Log In with your Facebook account.
- Click Get Started (or My Apps > Register).
- Accept the Meta Developer Terms, verify your phone number via SMS OTP, and pick your role as Developer.
3.2 Create the Business App
- Go to developers.facebook.com/apps and click Create App.
- Select Other (if prompted with category tiles), then click Next.
- Select Business as the app type and click Next.
- Configure App Details:
- App Name: Enter a clear identifier (e.g.,
ERPNext WhatsApp Gateway). - App Contact Email: Your technical notification email.
- Business Account: Select your Meta Business Account created in Phase 2.
- App Name: Enter a clear identifier (e.g.,
- Click Create App and re-enter your Facebook password if prompted.
Phase 4: WhatsApp Product Setup & Identifier Discovery
4.1 Add WhatsApp to the App
- In your App Dashboard, scroll down to Add products to your app.
- Find WhatsApp and click Set up.
- The dashboard will redirect to WhatsApp > API Setup (Quick Start).
4.2 Credentials & IDs to Record
Save the following three critical values from the API Setup page:
| Parameter Name | Description | Where to Copy |
|---|---|---|
| Phone Number ID | Identifies the sending phone number | Field: Phone number ID |
| WhatsApp Business Account ID (WABA ID) | The container holding templates and phone numbers | Field: WhatsApp Business Account ID |
| App ID | The Meta App ID | Top header bar next to your App Name |
Phase 5: Production Phone Number Registration
To send WhatsApp messages from your actual corporate number:
5.1 Number Prerequisites
- The number must be capable of receiving an SMS or Voice Call OTP.
- Important: It must not be registered on the consumer WhatsApp app or WhatsApp Business mobile app.
- If already registered: Open WhatsApp on the phone > Settings > Account > Delete My Account. Wait 5 minutes before proceeding.
5.2 Add and Verify Number
- On the Developer App dashboard, go to WhatsApp > API Setup.
- Scroll to Step 5: Add a phone number and click Add phone number.
- Provide:
- Profile Display Name: Must comply with Meta Display Name Guidelines.
- Category: (e.g., Automotive, Retail, Services).
- Description: Brief overview of your company.
- Enter the phone number and select SMS or Phone Call.
- Enter the 6-digit OTP code to verify. The number will now have its own dedicated Phone Number ID.
Phase 6: System User, Role Assignment & Permanent Access Token
The temporary token expires in 24 hours. ERPNext requires a System User access token configured to Never expire.
6.1 Create the System User
- Open Meta Business Settings.
- In the left menu under Users, select System Users.
- Click Add (or Create System User).
- Enter:
- System User Name:
frappe-whatsapp-user - System User Role: Select Admin (recommended so it can manage templates, profiles, and media).
- System User Name:
- Click Create System User.
6.2 Assign Developer App Asset
- Under Users > System Users, select
frappe-whatsapp-user. - Click Add Assets.
- In the dialog:
- Select Apps from the left column.
- Check your WhatsApp Developer App (
ERPNext WhatsApp Gateway). - Under Full Control, toggle Manage App to ON.
- Click Save Changes.
6.3 Assign WhatsApp Business Account (WABA) Asset
- In the left navigation, go to Accounts > WhatsApp Accounts.
- Select your WhatsApp Account.
- Click Assign People (or Assign Partners / System Users).
- Select
frappe-whatsapp-user. - Under Full Control, toggle Manage WhatsApp account to ON.
- Click Save Changes.
6.4 Generate the Permanent Access Token
- Return to Users > System Users and select
frappe-whatsapp-user. - Click Generate New Token.
- Select App: Choose your Developer App from the dropdown.
- Token Expiration: Select Never.
- Select Permissions: Check the following two essential scopes:
whatsapp_business_messaging(Required for sending messages, media, and template payloads)whatsapp_business_management(Required for fetching and syncing templates, phone numbers, and profile details)
- Click Generate Token.
- Copy the token immediately and store it securely.
Phase 7: Installing shridarpatil/frappe_whatsapp on Frappe / ERPNext
7.1 Bench Installation
Run the following commands in your bench directory on your server:
# 1. Fetch the app from GitHub
bench get-app https://github.com/shridarpatil/frappe_whatsapp.git
# 2. Install the app on your specific site
bench --site [your-site-name] install-app frappe_whatsapp
# 3. Run database migrations to create DocTypes
bench --site [your-site-name] migrate
# 4. Restart bench services to apply python and JS assets
bench restart
Phase 8: Configuring WhatsApp in Frappe
Once installed, search for WhatsApp in the Frappe Awesome Bar (Ctrl + K or Cmd + K) to access the newly installed module.
8.1 Step 1: Create a WhatsApp Account
The WhatsApp Account DocType stores your Meta API credentials and manages outbound sender routing.
- Navigate to: Awesome Bar > WhatsApp Account List > New WhatsApp Account.
- Populate the fields as follows:
Field Name Source / Value Description Account Name e.g. Primary Support NumberDescriptive internal name Phone Number ID From Phase 4 / Phase 5 Meta numeric Phone Number ID Business Account ID From Phase 4 (WABA ID) Meta WhatsApp Business Account ID App ID From Phase 3 Meta Developer App ID Access Token Permanent Token from Phase 6 System User token ( Neverexpire)Webhook Verify Token (e.g. my_frappe_wh_token_889)Custom token string for incoming events Is Default Outgoing [Checked]Routes default automated messages through this number Is Default Incoming [Checked]Routes inbound conversations to this account - Click Save.
8.2 Step 2: Configure WhatsApp Profile (Business Profile Management)
The frappe_whatsapp app allows you to inspect and synchronize your public WhatsApp Business Profile details with Meta servers directly from Desk:
- Open WhatsApp Profile (or click Fetch Profile on your WhatsApp Account).
- Configure your public business metadata:
- Display Name: Verified business name.
- About / Status: Brief tagline visible to users under your contact card.
- Category: E-commerce, Retail, Finance, etc.
- Address: Physical company address.
- Description: Detailed company services.
- Email & Websites: Official support email and store URLs.
- Profile Picture: Upload your company logo (square, min 640x640 px).
- Click Update to Meta to synchronize changes directly to WhatsApp servers via the Cloud API.
- Sender Contact Profiles: When customers message your number, the app automatically captures and saves their WhatsApp display name into WhatsApp Contact / Profile records.
8.3 Step 3: Managing WhatsApp Template
Outside of the 24-hour customer service window, Meta mandates the use of pre-approved message templates.
Option A: Sync Existing Templates from Meta
- Open WhatsApp Template List.
- Click the Sync from Meta (or Get Templates) button on the top right.
- The app connects to your WABA via your permanent access token and downloads all approved templates (e.g.,
order_confirmation,payment_reminder,hello_world) including their parameters and language codes.
Option B: Create a New Template inside Frappe
- Click New WhatsApp Template.
- Fill in:
- Template Name: Lowercase letters and underscores only (e.g.,
invoice_notification). - Category:
UTILITY,MARKETING, orAUTHENTICATION. - Language: Standard language code (e.g.,
en_US,en_GB,hi). - Header Type: None, Text, Image, Document, or Video. (Select Document if you plan to attach ERPNext Print Format PDFs).
- Body Text: Message content containing dynamic variables, for example:
Hello {{1}}, Thank you for your business. Your Sales Invoice {{2}} for the amount of {{3}} has been generated. Please find the attached invoice document. Regards, {{4}} - Buttons (Optional): Add Quick Replies (e.g.,
Contact Support) or Call-to-Action URLs (e.g.,https://example.com/pay/{{1}}).
- Template Name: Lowercase letters and underscores only (e.g.,
- Click Save and Submit to Meta. Meta reviews and approves the template within minutes.
8.4 Step 4: Configure Automated Messaging via WhatsApp Notification
The WhatsApp Notification DocType is the automated event engine that links ERPNext transactions to WhatsApp templates.
- Navigate to WhatsApp Notification List > New WhatsApp Notification.
- Channel & Trigger Settings:
- Channel: Select your configured WhatsApp Account.
- Reference DocType: Choose the target document (e.g.,
Sales Invoice,Delivery Note,Payment Entry,Quotation,Lead). - Send Event:
After Insert: When a document is first created.On Submit: When a transaction is submitted (ideal for Sales Invoices / Delivery Notes).Value Change: When a field changes (e.g.,statuschanges toPaid).Date Trigger: For reminders (e.g., 2 days beforedue_date).
- Filter Condition (Python Expression): Add conditions to prevent spamming:
doc.outstanding_amount > 0 and doc.docstatus == 1 - Recipient Mobile Number:
- Specify the field path holding the phone number:
contact_mobilecustomer_address.phone- Or a custom script expression:
doc.contact_mobile or frappe.db.get_value("Customer", doc.customer, "mobile_no")
- Specify the field path holding the phone number:
- Template & Variable Mapping:
- Select the approved WhatsApp Template (e.g.,
invoice_notification). - In the Template Parameters Table, map each variable to document fields:
- Parameter
{{1}}->doc.customer_name - Parameter
{{2}}->doc.name - Parameter
{{3}}->doc.get_formatted("grand_total") - Parameter
{{4}}->doc.company
- Parameter
- Select the approved WhatsApp Template (e.g.,
- PDF Attachment (ERPNext Print Format):
- Check Attach Print Format.
- Print Format: Choose standard or custom print format (e.g.,
Standard Sales Invoice). - The app will render the transaction into a PDF in memory, upload it to Meta Media Cloud API, and attach it to the template header.
- Click Save and enable the notification.
Phase 9: How the System Works in Operation
9.1 Transactional Event Execution Flow
- An accountant creates and clicks Submit on a
Sales Invoicein ERPNext. - The
frappe_whatsappnotification hook intercepts theon_submitevent. - The engine evaluates the condition:
doc.outstanding_amount > 0. - The system renders the invoice PDF via the selected Print Format.
- The engine prepares the JSON payload:
- Resolves variables:
{{1}}becomesJane Doe,{{2}}becomesACC-SINV-2026-00012. - Embeds media header ID.
- Resolves variables:
- The app makes a
POSTrequest to Meta's Cloud API endpoint using the System User Permanent Access Token configured in your WhatsApp Account:POST https://graph.facebook.com/v21.0/{PHONE_NUMBER_ID}/messages - A record is logged in the WhatsApp Message DocType inside Frappe with status
Sent.
9.2 Inspecting Logs & Interactive Chat
- WhatsApp Message List: Displays every outbound and inbound message with delivery status (
Sent,Delivered,Read,Failed), error logs, and recipient phone numbers. - WhatsApp Live Chat UI (if using
whatsapp_chatextension): Lets your sales and support agents chat directly with customers inside Frappe Desk within the active 24-hour window.
Production Verification Checklist
| Step | Verification Task | Expected Result |
|---|---|---|
| 1 | Meta System User Token | Token valid with whatsapp_business_messaging and whatsapp_business_management scopes, expiration set to Never. |
| 2 | WhatsApp Account in Frappe | Verified status; Phone Number ID and WABA ID match Meta Developer Console. |
| 3 | WhatsApp Template Sync | All approved templates appear in WhatsApp Template List with status Approved. |
| 4 | Notification Test | Submitting a test Sales Invoice sends an immediate WhatsApp message with a downloadable PDF attachment to the recipient. |
| 5 | Error Logging | Check Error Log in Frappe Desk if any message fails to deliver to review the raw Meta API error response. |