Quick Overview
This workflow captures receipt photos sent to a Telegram bot, uses Google Gemini (via an AI agent) to extract structured expense details, checks Google Sheets for duplicates by message ID, and either warns about duplicates or appends the expense and replies with a confirmation summary.
How it works
- Triggers when a new message is received by your Telegram bot.
- Normalizes the incoming Telegram payload and checks whether the message includes a receipt photo.
- If no photo is attached, sends a Telegram reply asking the user to upload a clear receipt image.
- If a photo is attached, downloads the image from Telegram and sends it to Google Gemini to extract receipt fields as JSON.
- Parses and validates the extracted data (including a confidence score) and flags the receipt for review if key fields are missing or uncertain.
- Looks up the Telegram message ID in a Google Sheets “Expenses” sheet to detect whether the receipt has already been logged.
- If it is a duplicate, sends a duplicate notice via Telegram; otherwise appends the expense to Google Sheets and sends a formatted summary back to the user.
Setup
- Create a Telegram bot with BotFather, add your Telegram credentials in n8n, and ensure the workflow is allowed to receive messages from your bot.
- Add Google Gemini (Google PaLM) API credentials for the Google Gemini chat model used by the AI agent.
- Add Google Sheets OAuth2 credentials and set the target spreadsheet and “Expenses” sheet in the Google Sheets nodes.
- Ensure your “Expenses” sheet includes a column named
messageId (and optionally the other mapped columns like merchant, receiptDate, total, and receiptId) so duplicate detection and appends work correctly.