← All samples

WhatsApp quote and invoice bot (prototype)

What it does

> quote acme 2 hours
< Quotation QT-2026-0001 for Acme Properties (fictional): AED 1795.5 (2 h @ 900, 5% off, VAT incl.)
> invoice blueview 4.5h
< Invoice INV-2026-0002 for BlueView Events (fictional): AED 4725 (4.5 h @ 1000, 0% off, VAT incl.)
  1. Reads the incoming message from the WhatsApp Cloud API webhook payload.
  2. Parses quote|invoice <client> <hours> and looks up the client's rate and discount.
  3. "Learns" from history: after 3 invoices, a client automatically gets a loyalty discount. The rule is editable.
  4. Auto-increments document numbers (QT-YYYY-0001, INV-YYYY-0001).
  5. Renders the document from a template with {{placeholders}}. In production the template lives in Google Drive and is exported to PDF.
  6. Logs a row to a sheet. Here that's a CSV stand-in; in production it uses the Google Sheets API values.append.
  7. Replies with a summary. In production it also sends the PDF through the WhatsApp Cloud API media message.

Sample output: quotation · sheet log (CSV)

Tests

node --test test.js   →  # pass 4  # fail 0

The tests cover parsing, pricing maths, numbering, the loyalty discount, and the replies for an unknown client or a badly formatted message.

Production checklist (what a real build adds)

Download code (zip)