How to Set Up AI Billing Automation — Smart Debt Collection via WhatsApp + Email (Omie / Conta Azul) in n8n
Every month, a chunk of your revenue is already earned — you just haven't collected it. Overdue invoices sit in Omie or Conta Azul while someone on your team either forgets to chase them or dreads the
Every month, a chunk of your revenue is already earned — you just haven't collected it. Overdue invoices sit in Omie or Conta Azul while someone on your team either forgets to chase them or dreads the awkward "you owe us money" conversation. Manual dunning is inconsistent, emotionally draining, and it scales terribly. The fix isn't hiring a collections person. It's an n8n workflow that reads your overdue receivables every morning, lets GPT-4o write a human-sounding message calibrated to how late each invoice is, and fires it off via WhatsApp and email — automatically, before you've finished your coffee.
The problem: money you earned but never chased
Late payments are rarely malicious. Most clients simply forget, lost the boleto, or are waiting to be reminded. But the cost of not reminding them is brutal: cash flow gaps, ballooning days-sales-outstanding (DSO), and the slow accumulation of "dead" receivables that eventually get written off. The founders who suffer most are the ones running lean — no dedicated finance team, no CRM discipline, just a growing list of overdue invoices nobody wants to own.
The naive solution is a canned reminder blast. That backfires. A client one day late needs a gentle, almost apologetic nudge. A client thirty days late needs firm, clear language with consequences. Send the harsh message to the day-one client and you damage the relationship; send the soft message to the day-thirty client and you get ignored. Tone has to scale with severity — and no template library handles that well. That's exactly the gap an LLM fills.
The solution: an AI collections agent that runs itself
This template turns dunning into a background process. Every morning it queries your accounting system (Omie or Conta Azul) for invoices past their due date, groups them by how overdue they are, and hands each one to GPT-4o with the client's name, amount, due date, and days overdue. The model writes a message in the right register — warm reminder for a fresh miss, direct escalation for a chronic one — then the workflow delivers it on both WhatsApp and email so it actually gets seen.
The whole thing is deterministic where it matters (which invoices, which channels, what data) and generative only where it helps (the wording). You keep control of the logic; the AI just handles the part humans procrastinate on — writing the message.
Step-by-step setup in n8n
Here's how the workflow is wired. If you're building from scratch, this is the node graph. If you install the ready-made template, this is what you're configuring.
1. Schedule Trigger. Start with a Schedule Trigger node set to fire once daily, typically 08:00 in your business timezone. Morning delivery lands the message when people check their phones and inboxes, which lifts open rates. Set the cron expression to 0 8 * * * and confirm the workflow's timezone in n8n settings matches your locale (America/Sao_Paulo for BR operations).
2. Fetch overdue invoices (Omie or Conta Azul). Use an HTTP Request node against your accounting API. For Omie, POST to /api/v1/financas/contareceber/ with ListarContasReceber, filtering on status_titulo and a due date less than today. For Conta Azul, hit the receivables endpoint with an OAuth2 credential (store it in n8n's OAuth2 API credential type so tokens refresh automatically). Return the invoice ID, client name, contact fields, amount, and due date.
3. Compute days overdue and filter. Drop in a Code node (or a Set + expression) that calculates daysOverdue = Math.floor((Date.now() - dueDate) / 86400000) for each item. Discard anything with daysOverdue <= 0. Then add a Switch node that routes each invoice into a bucket — for example 1–7 days, 8–30 days, and 30+ days — so the prompt can reference the right severity tier.
4. Generate the message with GPT-4o. Add an OpenAI node (Chat model, gpt-4o) or the generic AI Agent node. In the system prompt, define the persona: a polite but effective accounts-receivable assistant writing in Brazilian Portuguese. In the user prompt, inject the invoice data with expressions: {{$json.clientName}}, {{$json.amount}}, {{$json.dueDate}}, and crucially {{$json.daysOverdue}}. Instruct the model explicitly: gentle and understanding under 7 days, firm and specific with a clear next step over 30. Ask for two variants in one call — a short WhatsApp version and a slightly longer email version with a subject line — and request JSON output so you can parse both cleanly.
5. Send via WhatsApp. Feed the WhatsApp text into an HTTP Request node hitting your provider — the WhatsApp Cloud API, or a gateway like Z-API/Evolution. Map the client's phone number to the recipient field and the generated text to the message body. Add a small Wait node (a few seconds) between sends if you're looping through many invoices, to stay under rate limits and avoid looking like spam.
6. Send via email. In parallel, route the email variant into a Send Email (SMTP) or Gmail node. Use the model's generated subject line and body. Sending on both channels roughly doubles the chance the reminder is actually seen — some clients live in WhatsApp, others only check email.
7. Log the result. Close the loop with a node that writes back what happened — a Google Sheets append, a database insert, or a note back into Omie/Conta Azul. Record invoice ID, channel, timestamp, and the message sent. This gives you an audit trail and prevents duplicate chasing.
Benefits: what changes once it's live
Faster collection, lower DSO. Reminders go out the day an invoice turns overdue — not whenever someone remembers. Consistency alone recovers cash that used to slip through.
Tone that protects relationships. Because GPT-4o adapts wording to severity, your day-one clients feel gently nudged, not accused. You collect without burning goodwill.
Zero manual effort. Nobody writes messages, nobody maintains a spreadsheet of who to chase. The ops team gets its mornings back and the founder stops being the collections department.
Dual-channel reach. WhatsApp gets the immediacy; email gets the paper trail and the formality some clients expect. Together they beat either one alone.
Full visibility. Every message is logged, so you always know who was contacted, when, and on which channel — no more "did we ever follow up on that?"
Common pitfalls (and how to avoid them)
Sending duplicates. Without a log check, the workflow will re-chase the same invoice every single morning until it's paid. Add a guard: before sending, check whether a reminder for that invoice already went out today (or within your chosen cadence, e.g. every 3 days). Filter those items out before the AI node.
Bad or missing contact data. Overdue records often have empty phone or email fields. Add an IF node that validates contact info before the send nodes, and route the gaps to an alert channel so a human fixes the record instead of the workflow failing silently.
Letting the AI invent facts. LLMs can hallucinate amounts or dates if the prompt is loose. Pass the numbers as structured data and instruct the model to use them verbatim — never to recompute or estimate. Keep the temperature low (0.3–0.5) for predictable, on-brand output.
WhatsApp rate limits and template rules. The official WhatsApp Business API requires pre-approved message templates for business-initiated conversations. Get your dunning templates approved, or use a gateway that fits your compliance posture — and throttle sends so you don't trip anti-spam limits.
Timezone drift. If your n8n instance runs in UTC but your clients are in BRT, "due today" math and the 08:00 trigger will be off by hours. Set the workflow timezone explicitly and test the days-overdue calculation against a known invoice before going live.
No escalation path. Automated reminders work for the first few tiers, but a 60-day-overdue invoice needs a human. Add a branch that flags anything past a threshold for manual review instead of endlessly messaging a client who clearly won't pay by nudge alone.
Set it up once and it quietly recovers revenue every morning — the kind of automation that pays for itself in the first collected invoice.
Ja construimos isso pra voce
Nao comece do zero. O AI Billing Automation — Smart Debt Collection via WhatsApp + Email (Omie / Conta Azul) e um workflow n8n pronto para instalar — conecta suas ferramentas em minutos, sem codigo.
Instalar por $199 →