Quick overview
This workflow accepts electricity bill submissions via webhook or a monthly schedule, uses OpenAI to validate and summarize the bill, pulls up to 12 months of billing history and either returns an advisory report immediately or escalates high-severity cases via SendGrid email after a 24-hour wait.
How it works
- Receives a bill submission through a POST webhook or runs monthly on a cron schedule to recheck submitted bills.
- Uses OpenAI to extract, normalize, and validate key bill fields (such as billing period, units consumed, bill amount, and tariff category) and rejects invalid submissions with an error response.
- Fetches the account’s historical bill records from a Google Sheets BillsLog sheet and analyzes the most recent 12 months in Python to calculate a weighted anomaly score and severity.
- Uses OpenAI to generate a plain-language advisory report based on the anomaly metrics and recommended next steps.
- Returns the advisory report immediately and appends the result to Google Sheets for Normal and Moderate cases.
- For High-severity cases, responds with an “escalation pending” message, waits 24 hours (with an optional resume webhook), then sends a support alert email via SendGrid and logs the escalated case to Google Sheets.
Setup
- Add an OpenAI API credential for the OpenAI Chat Model used by the extraction/validation and advisory generation steps.
- Add Google Sheets OAuth2 credentials and replace YOUR_SHEET_ID in the Google Sheets API HTTP request and both Google Sheets append steps.
- Add a SendGrid API key as an HTTP Header Auth credential (Authorization: Bearer <key>) and set the verified sender/recipient details in the SendGrid email request payload.
- If using the webhook intake, copy the production webhook URL from n8n and configure your app or gateway to POST the required bill fields to it.
- Ensure your Google Sheets document contains a BillsLog sheet with columns that match the workflow’s expected row positions used for history parsing.