Quick Overview
This workflow monitors Gmail for invoice or receipt emails, uses OpenAI to extract an expense amount and category, logs the result to Google Sheets, and sends a Slack alert when an expense exceeds a defined threshold.
How it works
- Triggers every minute when a new email arrives in Gmail.
- Filters emails to only those with “Invoice” or “Receipt” in the subject and extracts the sender, subject, received date, and snippet text.
- Validates that the email content is long enough, then sends the email snippet to OpenAI to return a JSON expense amount and category.
- Parses and merges the AI-extracted fields with the original email metadata and formats a single expense record with a normalized date.
- Looks up the expense in Google Sheets by subject and date to avoid logging duplicates.
- Appends the expense to the Google Sheets spreadsheet and posts a Slack message if the logged amount is greater than 5000.
Setup
- Connect your Gmail OAuth2 credentials and ensure the Gmail Trigger has access to the mailbox you want to monitor.
- Add an OpenAI credential and confirm the model in the OpenAI node matches what you want to use.
- Connect Google Sheets using a service account, update the spreadsheet/document and sheet tab, and ensure the sheet has columns matching Date, Amount, Sender, Category, and Subject.
- Connect Slack OAuth2 credentials, select the target channel for alerts, and invite the Slack app/bot to that channel.