Learn how to build a reliable backend pipeline to auto-generate GST invoices and dispatch PDF copies directly via the official WhatsApp Business API.
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.
When building wholesale management tools like [Inventory Management / InvMaster OS](/projects/1), I structure the billing pipeline into four distinct asynchronous steps:
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;
}
}
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.
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).
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.
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.
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.