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

  1. Go to facebook.com and click Create new account.
  2. 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.
  3. 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.

  1. Navigate to Settings & Privacy > Settings > Accounts Center > Password and Security > Two-Factor Authentication.
  2. Select your account and choose Authentication App (Google Authenticator, Authy, or 1Password) instead of SMS for maximum reliability.
  3. 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

  1. Open business.facebook.com/overview.
  2. Click Create an account (top-right).
  3. 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).
  4. Click Submit and confirm the verification email received in your inbox.

2.2 Adding Payment Method (Required for Scaling)

  1. In Meta Business Settings, click Payment Methods in the left sidebar.
  2. Click Add Payment Method, select your country and currency, and enter your corporate credit/debit card.
  3. Set this card as the primary payment method.

Phase 3: Meta for Developers Account & App Creation

3.1 Register as a Meta Developer

  1. Go to developers.facebook.com and click Log In with your Facebook account.
  2. Click Get Started (or My Apps > Register).
  3. Accept the Meta Developer Terms, verify your phone number via SMS OTP, and pick your role as Developer.

3.2 Create the Business App

  1. Go to developers.facebook.com/apps and click Create App.
  2. Select Other (if prompted with category tiles), then click Next.
  3. Select Business as the app type and click Next.
  4. 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.
  5. 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

  1. In your App Dashboard, scroll down to Add products to your app.
  2. Find WhatsApp and click Set up.
  3. 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

  1. On the Developer App dashboard, go to WhatsApp > API Setup.
  2. Scroll to Step 5: Add a phone number and click Add phone number.
  3. Provide:
    • Profile Display Name: Must comply with Meta Display Name Guidelines.
    • Category: (e.g., Automotive, Retail, Services).
    • Description: Brief overview of your company.
  4. Enter the phone number and select SMS or Phone Call.
  5. 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

  1. Open Meta Business Settings.
  2. In the left menu under Users, select System Users.
  3. Click Add (or Create System User).
  4. Enter:
    • System User Name: frappe-whatsapp-user
    • System User Role: Select Admin (recommended so it can manage templates, profiles, and media).
  5. Click Create System User.

6.2 Assign Developer App Asset

  1. Under Users > System Users, select frappe-whatsapp-user.
  2. Click Add Assets.
  3. 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.
  4. Click Save Changes.

6.3 Assign WhatsApp Business Account (WABA) Asset

  1. In the left navigation, go to Accounts > WhatsApp Accounts.
  2. Select your WhatsApp Account.
  3. Click Assign People (or Assign Partners / System Users).
  4. Select frappe-whatsapp-user.
  5. Under Full Control, toggle Manage WhatsApp account to ON.
  6. Click Save Changes.

6.4 Generate the Permanent Access Token

  1. Return to Users > System Users and select frappe-whatsapp-user.
  2. Click Generate New Token.
  3. Select App: Choose your Developer App from the dropdown.
  4. Token Expiration: Select Never.
  5. 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)
  6. Click Generate Token.
  7. 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.

  1. Navigate to: Awesome Bar > WhatsApp Account List > New WhatsApp Account.
  2. Populate the fields as follows:
    Field Name Source / Value Description
    Account Name e.g. Primary Support Number Descriptive 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 (Never expire)
    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
  3. 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:

  1. Open WhatsApp Profile (or click Fetch Profile on your WhatsApp Account).
  2. 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).
  3. Click Update to Meta to synchronize changes directly to WhatsApp servers via the Cloud API.
  4. 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

  1. Open WhatsApp Template List.
  2. Click the Sync from Meta (or Get Templates) button on the top right.
  3. 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

  1. Click New WhatsApp Template.
  2. Fill in:
    • Template Name: Lowercase letters and underscores only (e.g., invoice_notification).
    • Category: UTILITY, MARKETING, or AUTHENTICATION.
    • 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}}).
  3. 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.

  1. Navigate to WhatsApp Notification List > New WhatsApp Notification.
  2. 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., status changes to Paid).
      • Date Trigger: For reminders (e.g., 2 days before due_date).
  3. Filter Condition (Python Expression): Add conditions to prevent spamming:
    doc.outstanding_amount > 0 and doc.docstatus == 1
  4. Recipient Mobile Number:
    • Specify the field path holding the phone number:
      • contact_mobile
      • customer_address.phone
      • Or a custom script expression: doc.contact_mobile or frappe.db.get_value("Customer", doc.customer, "mobile_no")
  5. 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
  6. 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.
  7. Click Save and enable the notification.

Phase 9: How the System Works in Operation

9.1 Transactional Event Execution Flow

  1. An accountant creates and clicks Submit on a Sales Invoice in ERPNext.
  2. The frappe_whatsapp notification hook intercepts the on_submit event.
  3. The engine evaluates the condition: doc.outstanding_amount > 0.
  4. The system renders the invoice PDF via the selected Print Format.
  5. The engine prepares the JSON payload:
    • Resolves variables: {{1}} becomes Jane Doe, {{2}} becomes ACC-SINV-2026-00012.
    • Embeds media header ID.
  6. The app makes a POST request 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
  7. 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_chat extension): 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.