Automate AI Billing Automation — Smart Debt Collection via WhatsApp + Email (Omie / Conta Azul) in n8n — Step by Step
If your business runs on Omie or Conta Azul, you already know the pain: overdue invoices pile up, your team spends hours chasing clients manually, and by the time someone sends a follow-up message, th
If your business runs on Omie or Conta Azul, you already know the pain: overdue invoices pile up, your team spends hours chasing clients manually, and by the time someone sends a follow-up message, the tone is either too aggressive or too soft. The result? Cash flow pressure and burned relationships — at the same time. This article shows you exactly how to eliminate that problem using an n8n workflow that checks overdue invoices every morning, generates context-aware collection messages with GPT-4o, and sends them automatically via WhatsApp and email — without a single manual step.
The Real Cost of Manual Debt Collection
Most SMBs in Brazil treat billing follow-up as a reactive task. Someone remembers a client is overdue, opens the ERP, exports a spreadsheet, writes a message, copies the phone number, and sends it — maybe. If the team is busy, the follow-up doesn't happen at all, or it happens two weeks late when the relationship is already strained.
The compounding problem: a client who is 1 day overdue needs a gentle reminder. A client who is 30 days overdue needs a firm message with clear consequences. Sending the same template to both destroys either the relationship or the collection rate. Manual processes can't scale nuance — automated AI can.
Research from SERASA Experian shows that the probability of collecting a debt drops by over 40% after 90 days. Every day of delay in follow-up costs you money. Automating the first 60 days of collection — where the bulk of recovery happens — is not a luxury, it's infrastructure.
How the Workflow Works (Architecture Overview)
The automation runs on a scheduled trigger every weekday morning. Here's the complete flow:
1. Schedule Trigger — Fires at 08:00 every business day using n8n's built-in Cron node. No external scheduler needed.
2. Omie / Conta Azul API Pull — An HTTP Request node hits the financial API to fetch all overdue receivables. For Omie, this uses the ListarContasReceber method filtered by status_titulo = "VENCIDO". For Conta Azul, the /financas/receber endpoint with the situacao=pendente and vencimento_fim date filter.
3. Split In Batches — The SplitInBatches node processes each invoice individually, preventing API rate limit issues and enabling per-client logic.
4. Calculate Days Overdue — A Function node computes the exact number of days between today and the invoice due date. This number is passed to GPT-4o as part of the prompt context.
5. GPT-4o Message Generation — The OpenAI node receives client name, invoice amount, days overdue, and your company name. The system prompt instructs GPT-4o to calibrate tone based on urgency: friendly and understanding for 1–7 days, firmer and action-oriented for 8–30 days, formal and legally-aware for 30+ days.
6. Parallel Send — WhatsApp + Email — Two branches run simultaneously. One sends via the WhatsApp Business API (or Z-API / WPPConnect for smaller operations). The other sends via SMTP or a transactional email provider like SendGrid or Brevo.
7. Log to ERP — A final HTTP Request node updates the invoice record in Omie or Conta Azul with a note confirming the message was sent, including timestamp and channel.
Step-by-Step Setup in n8n
Step 1: Connect your ERP
In n8n, create an HTTP Request node. For Omie, set Method to POST, URL to https://app.omie.com.br/api/v1/financas/pesquisartitulos/. Add your app_key and app_secret in the JSON body alongside the filter object. For Conta Azul, authenticate via OAuth2 using the n8n built-in Conta Azul credential type — this handles token refresh automatically.
Step 2: Filter and enrich invoice data
Add a Function node after the API call. This node should extract: client_name, client_phone, client_email, invoice_value, due_date, and compute days_overdue using JavaScript's Date difference. Example:
const today = new Date();
const due = new Date(item.data_vencimento);
const days = Math.floor((today - due) / (1000 * 60 * 60 * 24));
item.days_overdue = days;
Step 3: Configure the OpenAI node
Add the OpenAI node (Chat Model). Set model to gpt-4o. In the System Message field, write your tone instructions — something like: "You are a professional billing assistant for [Company Name]. Write a collection message in Brazilian Portuguese. For debts under 7 days: empathetic, assume it was a simple oversight. For 8–30 days: clear and firm, mention the payment link. For 30+ days: formal, mention that legal measures will be considered if not resolved within 5 business days." In the User Message field, pass the dynamic variables from the previous node using n8n expressions: Client: {{$json.client_name}}, Amount: R$ {{$json.invoice_value}}, Overdue: {{$json.days_overdue}} days.
Step 4: Send via WhatsApp
If you're using Z-API, add an HTTP Request node with POST method to your Z-API instance endpoint. Body should include phone (formatted as 5527999999999) and message (the GPT-4o output). For WhatsApp Business API, use the official Meta endpoint with your Bearer token. The message text comes from {{$node["OpenAI"].json.choices[0].message.content}}.
Step 5: Send via Email
Add an Email Send node (SMTP) or use the SendGrid node for better deliverability. Map To to {{$json.client_email}}, Subject to something like "Pendência financeira — [Company Name]", and Body (HTML) to include the GPT-4o message wrapped in a clean email template. Avoid spam trigger words in the subject line — test deliverability before going live.
Step 6: Log the action back to the ERP
Add a final HTTP Request node to update the invoice in your ERP. For Omie, use the AlterarContaReceber method and append a note to the observacao field with the timestamp and "Cobrança enviada via WhatsApp + Email — [date]". This creates an audit trail inside your ERP without needing a separate database.
Why GPT-4o Makes the Difference
Generic collection templates fail because they ignore context. A client who has been with you for 3 years and missed one payment needs a different message than a new client who is already 45 days overdue. GPT-4o handles this nuance at scale — every message sounds like it was written by a human who read the account history.
Beyond tone calibration, GPT-4o avoids the word patterns that trigger WhatsApp's spam filters and email spam folders. It writes messages that pass as human communication because they are contextually appropriate — not because they use evasion techniques. The model also handles pluralization, payment value formatting (R$ 1.500,00 not $1500), and Brazilian Portuguese register correctly without manual intervention.
The practical result: higher open rates on email, higher reply rates on WhatsApp, and fewer clients blocking your number because the messages feel respectful rather than robotic.
Common Pitfalls and How to Avoid Them
Pitfall 1: Sending to clients who already paid
Always filter by payment status at the API level, not just due date. Omie's API returns payments that were settled on the same day as overdue if you only filter by date. Add a status check: status_titulo = "VENCIDO" explicitly excludes settled items. Test this filter against your real data before enabling the automation.
Pitfall 2: WhatsApp rate limits and blocks
Don't send to more than 50 clients simultaneously from the same number. Use the SplitInBatches node with a batch size of 10 and add a Wait node of 30 seconds between batches. This mimics human sending patterns and significantly reduces the risk of your number being flagged by WhatsApp's anti-spam systems.
Pitfall 3: Phone number formatting errors
Brazilian numbers in ERPs are stored inconsistently — sometimes with country code, sometimes without, sometimes with the 9th digit, sometimes not. Add a Function node that normalizes the phone: strips non-numeric characters, ensures the number starts with 55, and adds the 9th digit for mobile numbers in states that require it. A single malformed number can cause the entire batch to fail if not handled gracefully.
Pitfall 4: No error handling on API failures
Add an Error Trigger node at the workflow level. Configure it to send you a Slack message or email if any execution fails. Without this, the workflow silently fails and your clients receive no follow-up — which is worse than not having the automation at all. Use the continueOnFail setting on each node so a single bad record doesn't stop the entire run.
Pitfall 5: GPT-4o hallucinating payment details
Never ask GPT-4o to generate invoice numbers, amounts, or due dates from memory. Pass all financial data explicitly in the prompt and instruct the model in the system message: "Never invent or modify any numbers provided. Use exactly the values given." Hallucinated payment amounts in collection messages create legal and relationship risks.
What to Expect After Deployment
Teams that implement automated billing follow-up consistently report a 20–35% improvement in collection rates within the first 60 days, primarily because the system sends messages at the right time rather than whenever someone remembers. The WhatsApp channel alone typically achieves open rates above 90% — compared to 20–30% for email — making the dual-channel approach significantly more effective than either channel alone.
Beyond collection rates, the operational impact is immediate: your finance team stops spending 2–4 hours per week on manual follow-up, the messages are consistent and legally appropriate regardless of who is on the team, and every action is logged automatically in your ERP. The workflow also runs on weekdays only by default, avoiding messages on weekends that would be perceived as aggressive regardless of the AI-generated tone.
Start by running the workflow in a test mode — disable the WhatsApp and Email send nodes, log the generated messages to a Google Sheet or Notion instead, and review 50 samples manually. This validation step takes one week and ensures the prompts are calibrated correctly for your specific client base before any message is sent automatically.
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 $39 →