Automating GST Invoices and Retailer Notifications with WhatsApp Business API Integration

Learn how to build a reliable backend pipeline to auto-generate GST invoices and dispatch PDF copies directly via the official WhatsApp Business API.

Published by Aafaque Nazir on 2026-11-03 • 7 min read
Quick Answer: Automating GST invoicing and WhatsApp dispatch involves generating a compliant tax PDF on your backend, uploading it to Meta's servers, and calling the WhatsApp Cloud API template endpoint with the recipient's phone number and media ID.

The Problem with Manual Wholesale Billing

For wholesale distributors and retail godowns, manual billing is slow and prone to human error. Accountants generate GST invoices in desktop software, export PDFs manually, open WhatsApp Web, search for the retailer's phone number, attach the file, and type a confirmation message. When processing hundreds of orders daily, this routine wastes hours of labor and introduces calculation mistakes.

To solve this bottleneck, modern backend systems must handle invoicing and dispatch in one continuous transaction. When an order is confirmed, the system should compute tax breakdowns, generate a PDF, store the record in PostgreSQL, and push the document to the retailer's phone via the official Meta cloud infrastructure.

Architecture and Workflow Design

When building wholesale management tools like [Inventory Management / InvMaster OS](/projects/1), I structure the billing pipeline into four distinct asynchronous steps:

  • Order State Change: Database trigger or queue worker detects a fulfilled order.
  • PDF Generation: Node.js renders a compliant tax invoice using a headless browser or template engine.
  • Media Upload: The PDF is uploaded to the Meta Graph API to secure a unique media ID.
  • Template Dispatch: A pre-approved WhatsApp message template containing order metadata and the document reference is sent to the retailer.

Node.js Code Implementation for WhatsApp Dispatch

Below is a production-tested TypeScript snippet showing how to send a document message using the official WhatsApp Cloud API.

import axios from 'axios';

interface InvoiceDispatchPayload {
  recipientPhone: string;
  mediaId: string;
  invoiceNumber: string;
  customerName: string;
}

export async function sendWhatsAppInvoice({
  recipientPhone,
  mediaId,
  invoiceNumber,
  customerName
}: InvoiceDispatchPayload): Promise<boolean> {
  const accessToken = process.env.WHATSAPP_ACCESS_TOKEN;
  const phoneNumberId = process.env.WHATSAPP_PHONE_NUMBER_ID;

  const url = `https://graph.facebook.com/v19.0/${phoneNumberId}/messages`;

  try {
    const response = await axios.post(
      url,
      {
        messaging_product: 'whatsapp',
        to: recipientPhone,
        type: 'document',
        document: {
          id: mediaId,
          caption: `Hello ${customerName}, here is your official tax invoice #${invoiceNumber}. Thank you for your business!`,
          filename: `Invoice-${invoiceNumber}.pdf`
        }
      },
      {
        headers: {
          Authorization: `Bearer ${accessToken}`,
          'Content-Type': 'application/json'
        }
      }
    );

    return response.status === 200;
  } catch (error) {
    console.error('Failed to dispatch WhatsApp invoice:', error.response?.data || error.message);
    return false;
  }
}
Engineering Best Practice
Always wrap your external API calls in robust retry queues (such as BullMQ with Redis). Network hiccups between your server and Meta's Graph API should never cause a dropped customer invoice.

Ensuring Compliance and Reliability

GST invoices in India require specific fields including HSN/SAC codes, state supply codes, digital signatures or QR codes where applicable, and precise tax splitting. Storing the generated invoice payload in your database ensures you have an immutable audit trail for tax filing.

Need Help Implementing This in Your Product?

If you are looking to integrate automated WhatsApp billing, inventory workflows, or custom backend services into your business, I can help design and build it. [Explore my web development services](/services) or [get in touch with Aafaque for a project consultation](/contact).

Frequently Asked Questions

Which WhatsApp API is required to send automated PDF invoices?

You must use the official WhatsApp Business Cloud API provided by Meta. Unofficial WhatsApp wrappers or web-scraping scripts often lead to permanent phone number bans.

How do you calculate and attach GST data to invoices programmatically?

GST calculations (CGST, SGST, IGST) are handled in the backend database using state codes and item-level HSN codes before generating the final HTML/PDF invoice.

Can I integrate this automated billing into my existing inventory system?

Yes. As implemented in my [Inventory Management / InvMaster OS](/projects/1) project, billing triggers can be tied directly to order completion events in your database.

← Back to all articles