Quick overview
This workflow runs daily to read overdue invoices from Google Sheets, uses OpenAI (GPT-4o-mini) to draft personalized reminder emails and determine escalation level, sends emails via Gmail, posts Slack alerts for no-invoice runs or AI errors, and logs results back to Google Sheets.
How it works
- Runs every 24 hours on a schedule.
- Reads rows from the “invoices” tab in Google Sheets and, if no invoice value is found, posts a “no overdue invoices” message to Slack.
- For each invoice, sends the invoice details to OpenAI (GPT-4o-mini) to determine an escalation level, draft an HTML email, and recommend whether to escalate.
- Parses the AI’s JSON response (falling back to a default reminder if parsing fails) and sends the recovery email to the client via Gmail.
- If the AI recommends escalation, sends an internal escalation email via Gmail to the legal/AR team with invoice details and the AI summary.
- Updates the original invoice row in Google Sheets with the escalation level and summary, then appends an audit row to the “Recovery sheet” tab including the email subject, summary, and sent message label ID.
- If the AI step errors, posts an error alert to Slack and continues processing.
Setup
- Add Google Sheets OAuth2 credentials and replace YOUR_GOOGLE_SHEET_ID, ensuring the “invoices” and “Recovery sheet” tabs and columns (Invoice, Client, Email, Amount, Due Date, Days Overdue, Reminders Sent, plus row_number) match the workflow.
- Add an OpenAI credential for the GPT-4o-mini model.
- Add Gmail OAuth2 credentials and set the reply-to address ([email protected]) and escalation recipient ([email protected]) to your real emails.
- Add Slack OAuth2 credentials, replace YOUR_SLACK_CHANNEL_ID, and choose the channel that should receive status and error alerts.