Quick Overview
This workflow monitors Gmail for receipt emails, uses Google Gemini to extract transaction details, checks recent transactions stored in Google Sheets for potential duplicate charges, logs the result back to the sheet, and sends a Slack alert when it finds a possible double charge.
How it works
- Triggers every minute when a new Gmail message matching the search query (for example, “receipt”) arrives.
- Fetches the full Gmail message, extracts a clean email body from MIME parts, and prepares core metadata such as sender, subject, thread ID, and received timestamp.
- Sends the email content to Google Gemini to extract structured transaction fields (merchant, amount, currency, transaction date/time, reference, and type) and parses the JSON response.
- Validates that the email represents a successful charge with the required fields, and normalizes merchant, amount, currency, and timestamps into a consistent format.
- Generates a deterministic transaction ID, pulls recent transactions from Google Sheets, and flags the current charge as a potential duplicate when merchant, amount, and currency match within a 48-hour window.
- Appends the transaction to Google Sheets, posts a Slack alert when a potential duplicate is detected, and then labels the Gmail message as processed.
Setup
- Connect Gmail OAuth2 credentials and update the Gmail trigger query and the “processed” label ID used to tag handled messages.
- Add Google Gemini (PaLM) API credentials and confirm the selected model is available in your Google AI Studio account.
- Connect Google Sheets credentials, set the target spreadsheet and “Transactions” sheet, and ensure the sheet has columns for transaction fields and duplicate status (including email_message_id and transaction_timestamp).
- Connect Slack credentials and select the channel where duplicate-charge alerts should be posted.
- (Optional) Adjust the duplicate detection time window in the duplicate-checking code (48 hours by default) to fit your review process.