dvysn
← Projects

Author

Tally — Telegram Expense Tracker

2026Python0 stars

Telegram bot that logs expenses from natural-language text or voice notes, parses them with an LLM, and writes structured rows to Google Sheets.

Overview

Telegram bot that logs expenses from natural-language text or voice notes, parses them with an LLM, and writes structured rows to Google Sheets.

Architecture

User sends a text or voice message to a Telegram bot. Text messages are passed directly to an LLM (Qwen via OpenRouter) which extracts structured expense fields (amount, category, notes) and returns JSON. Voice notes are first transcribed via Replicate (GPT-4o Mini Transcribe), then follow the same LLM path. Validated output is appended as a row to Google Sheets via the Sheets API. A /summary command aggregates the current month's spend by category and uses the LLM to generate a one-line observation.

Implementation

Bot built with python-telegram-bot. LLM calls go through OpenRouter's chat completions API using Qwen-Turbo, with a strict system prompt that enforces JSON output and defines 11 spending categories. Output validation checks amount, category membership, and notes length before writing to Sheets. Speech-to-text handled asynchronously via Replicate. The system prompt includes explicit prompt injection defences so user messages are treated as data only. /undo deletes the most recently appended Sheets row.

Results

Handles the full loop — voice or text in, categorised row in Google Sheets out — with no manual data entry. Works reliably for casual phrasing like '500 on groceries' or 'paid 1200 for electricity'. The main limitation is dependency on OpenRouter uptime and Replicate latency for voice notes (~2-4s transcription round-trip).

PythonTelegramLLMGoogle SheetsReplicate