Opening Problem Statement
Meet Rizqi, a small business owner who regularly receives invoices and receipts via Telegram from his team and suppliers. Every week, Rizqi spends hours manually extracting the details from each receipt photo — item names, quantities, prices, and taxes — and then painstakingly entering them one by one into his Notion finance tracker. He also struggles to get summarized reports and detailed breakdowns without spending even more time on spreadsheets or juggling multiple apps.
This manual workflow costs Rizqi at least 3-5 hours weekly just on data entry and report preparation, leaving room for human errors and lost financial insights. He needs a way to automate the entire process — from receiving invoice photos on Telegram to automatically recording expenses in Notion, enhanced with AI-driven data extraction and clear visual reports.
What This Automation Does
This n8n workflow seamlessly connects Telegram, Google Gemini AI, and Notion to automate Rizqi’s financial tracking. Here’s what happens each time it runs:
- When Rizqi sends (or receives) an invoice photo on Telegram, the bot automatically fetches the image file.
- The image is processed by Google Gemini AI, extracting structured invoice data including date, item names, quantities, prices, taxes, and categories.
- The AI output is converted into a detailed JSON object and then each transaction item is saved as a separate entry in a Notion database customized for expense tracking.
- A summary message is sent back to Rizqi on Telegram, confirming the recorded details.
- On a set schedule (e.g., weekly), the workflow fetches recent Notion expenses, summarizes spending by category, and generates a bar chart report.
- The chart image is automatically delivered to Rizqi’s preferred Telegram group or private chat for quick financial review.
This automation eliminates Rizqi’s manual data entry and reporting effort, saving at least 4 hours weekly and drastically reducing human error. The AI-driven extraction is tailored to invoice images, making the data highly reliable and instantly actionable.
Prerequisites ⚙️
- 📧 Telegram account with a bot token and chat group ID for message and media handling
- 🔐 Google Gemini (PaLM) API credentials for image-based AI data extraction
- 📁 Notion account with API credentials and access to a database configured for expense tracking
- ⚙️ An n8n account to build and run this automation (self-hosting possible—check out Hostinger guide)
Step-by-Step Guide
Step 1: Set Up Telegram Bot for Receiving Invoice Photos
Navigate to Telegram’s BotFather and create a new bot. Save the API token. Then, add the bot to your preferred chat or create a new group, recording its Chat ID (e.g., -1001957001324 from the workflow).
In n8n, add the Telegram Trigger node:
- Click Nodes → Telegram Trigger
- Authenticate with your Telegram bot API token
- Configure to trigger on new ‘message’ updates (specifically photos)
- Set operation to get file
- Use the photo file_id from the message payload (
{{ $json.message.photo[3].file_id }}) - Operation: information
- This helps check if the image is valid and suitable for AI processing.
- Use your Google API credentials previously set up
- Select the model models/gemini-2.5-flash-preview-04-17
You should see the node listening to incoming photo messages.
Common mistake: Forgetting to add the bot to the chat group or missing the correct Chat ID.
Step 2: Retrieve Photo Details
Following the trigger, add the Telegram node configured to fetch the file:
This fetches the actual invoice image for processing. Error check: Ensure the file_id path aligns with Telegram’s photo sizes.
Step 3: Extract Image Information
Add the Edit Image node for image information extraction:
You’ll see metadata about the invoice image. Mistake: Skipping validation may cause AI errors on unsupported files.
Step 4: Run Google Gemini AI to Extract Invoice Data
The Google Gemini Chat Model node sends the image to Google’s PaLM Gemini model for AI processing:
The next Basic LLM Chain node defines a custom AI prompt tailored to your invoice parsing needs:
=ini ada base64 invoice rangkumkan Pengeluaran dari invoice tersebut Nama Barang jumlah dan Pengeluaran masing masing barang dan total, outputnya jangan panjang panjang saya cukup berikan
date: DD-MM-YYYY ( Jika dari OCR tidak ada tanggal ambil tanggal hari ini )
id:
name:
qty:
price:
total:
category:
tax : (jika di total berbeda dengan item brati ada pajak nya hitungkan juga pajaknya masukan kesini)
untuk pilihan categorynya : Food & Beverage / Transportation / Utilities / Shopping / Healthcare / Entertaiment / Housing / Education
This ensures the AI returns a JSON array with itemized expense data categorized for Notion.
Step 5: Parse AI Output to Structured JSON
Add the Parse To your object | Table node, which uses a schema to convert the AI’s text output into structured JSON objects with fields like date, id, name, qty, price, total, category, and tax.
Keep the schema consistent with your AI prompt; otherwise, the data won’t map correctly.
Step 6: Split Out Each Transaction Item
Use the Split Out node to create individual output items for each transaction in the summary. This enables batch creation in Notion.
Step 7: Record Each Transaction to Notion Database
Add the Record To Notion Database node:
- Connect using your Notion API token
- Choose your expenses database (e.g., “Pengeluaran Rizqi Dini” with database ID)
- Map the fields appropriately (Name to title, qty, price, total, category, date, tax)
Upon execution, each invoice item is stored as a separate Notion page for detailed tracking.
Step 8: Send Summary Message Back to Telegram
Use the Telegram node to send a confirmation back to the same chat with a concise summary extracted from AI:
- Set chatId dynamically to where the photo came from
- Message text from the AI output summary (e.g., total expenses and main purchased items)
This reassures Rizqi the data was recorded correctly.
Step 9: Schedule Weekly Spending Report
The Schedule Trigger node lets you automate periodic report generation (weekly, monthly, etc.):
- Set the interval (e.g., every 7 days)
- Triggers fetching recent expenses from Notion via the Get Recent Data from Notions node filtered by “past_week”
This step provides data for the report chart.
Step 10: Summarize Spending by Category
The Summarize Transaction Data node aggregates totals by the expense category extracted from Notion entries.
Step 11: Format Data for Chart Generation with Code Node
The Convert Data to JSON chart payload code node runs this JavaScript:
const labels = [];
const values = [];
for (const item of items) {
labels.push(item.json.property_category);
values.push(item.json.sum_property_total);
}
return [
{
json: {
chart: {
type: 'bar',
data: {
labels,
datasets: [
{
label: 'Spending by Category',
data: values,
backgroundColor: 'rgba(54, 162, 235, 0.6)',
borderColor: 'rgba(54, 162, 235, 1)',
borderWidth: 1
}
]
},
options: {
plugins: {
title: {
display: true,
text: 'Spending Summary by Category'
}
},
scales: {
y: {
beginAtZero: true
}
}
}
}
}
}
];
This outputs the JSON chart configuration for the QuickChart node.
Step 12: Generate a Visual Spending Chart
The Generate Chart node uses the chart configuration to produce a bar chart image representing spending by category.
Step 13: Send the Chart Report via Telegram
Finally, the Send Chart Image to Group or Private Chat Telegram node delivers the chart image to the specified chat (group or private), using the chat ID and supporting threaded message reply.
Customizations ✏️
- Adjust AI Prompt Categories: In the Basic LLM Chain node, update the list of invoice categories to better match your expense types (e.g., add “Travel” or “Office Supplies” categories).
- Change Report Frequency: Modify the Schedule Trigger node’s interval to daily, monthly, or custom schedules as desired.
- Modify Notion Properties: In the Record To Notion Database node, map additional invoice fields, such as vendor name or payment method, if your Notion database supports it.
- Customize Chart Type: In the Convert Data to JSON chart payload node, customize the chart type from bar to pie or line charts using QuickChart’s API options.
Troubleshooting 🔧
Problem: “Could not fetch file – invalid file_id”
Cause: The Telegram photo file_id path is incorrect, or the photo array index does not exist.
Solution: Verify in the Telegram trigger node output the exact photo array size, then adjust {{ $json.message.photo[3].file_id }} accordingly, e.g., photo[0] or photo[1].
Problem: “AI output does not match expected JSON schema”
Cause: The AI prompt or output parser schema is not aligned, causing parsing failures.
Solution: Cross-check the prompt in the Basic LLM Chain node and the JSON schema in the Parse To your object | Table node. Make sure required fields and types align perfectly.
Problem: “Notion API rate limits or save failures”
Cause: Too many database write attempts in quick succession.
Solution: Enable n8n’s error workflow on the Record To Notion Database node or add a delay node to throttle requests if large invoices are frequent.
Pre-Production Checklist ✅
- Verify Telegram bot has permission to read media and send messages in the designated chat.
- Confirm Google Gemini API credentials are valid and quota is sufficient.
- Check Notion database structure matches the mapped fields exactly.
- Test by sending a sample invoice photo to Telegram and verify structured data appears in Notion.
- Test scheduled report generation by manually triggering the Schedule Trigger node.
Deployment Guide
Activate the workflow in n8n and ensure it’s running continuously to listen for incoming Telegram messages.
Monitor the execution logs on your n8n dashboard for errors or stalls.
Schedule is mandatory for report sending, so ensure the Schedule Trigger node interval matches your reporting preference.
FAQs
Q: Can I use another AI model instead of Google Gemini?
A: Yes, but you’ll need to adapt the prompt and authentication for other LLM nodes like OpenAI or Cohere.
Q: Does this automation consume API credits?
A: Yes, Google Gemini and Notion API usage may incur costs based on your plan.
Q: Is my financial data secure?
A: This automation uses API credentials with your own accounts. Keep your n8n instance secure and never share API keys publicly.
Q: Can I handle hundreds of invoices?
A: Yes, but consider adding throttling or batching to avoid Notion API limits.
Conclusion
By following this guide, you have created an intelligent financial tracking system that automatically converts Telegram invoice photos into detailed Notion database entries. Thanks to Google Gemini AI, the process is fast and highly accurate, saving Rizqi at least 4 hours per week on manual data entry and reporting.
Next, you might explore adding payment status updates, integrating bank transactions, or expanding report visualizations using dashboards.
Automating invoice tracking this way frees up your valuable time to focus on growing your business instead of tedious bookkeeping.