Telegram bot for tracking expenses and syncing them to Google Sheets.
- 💰 Track expenses via Telegram messages
- 📊 Automatic sync to Google Sheets
- 💱 Multi-currency support (USD, EUR, RUB, RSD, GBP, CHF, JPY, CNY, INR)
- 🏷️ Automatic category detection with confirmation
- 📈 Statistics and expense analysis
- 🔐 Secure OAuth2 authentication with Google
- 🤖 AI-powered expense analysis and advice (Hugging Face)
- 💼 Budget management and tracking
- 👥 Group chat support with shared expenses
- 🗓️ Daily AI financial advice (scheduled)
The bot understands various expense formats:
190 евро Alex hobby
190е Alex hobby
190д Alex hobby
190$ Alex hobby
190 $ Alex hobby
$190 Alex hobby
$ 190 евро Alex hobby
190 euro Alex hobby
190 Eur Alex hobby
190 EUR Alex hobby
1 900 RSD Lena hobby theater
Format: [amount] [currency?] [category] [comment]
bun install- Open @BotFather in Telegram
- Send
/newbotand follow instructions - Copy the bot token
- Go to Google Cloud Console
- Create a new project or select existing
- Enable Google Sheets API and Google Drive API:
- APIs & Services → Library
- Search for "Google Sheets API" and enable
- Search for "Google Drive API" and enable
- Create OAuth 2.0 credentials:
- APIs & Services → Credentials
- Click "Create Credentials" → "OAuth client ID"
- Application type: "Web application"
- Authorized redirect URIs:
http://localhost:3000/callback - Copy Client ID and Client Secret
- Go to Hugging Face
- Create account or sign in
- Go to Settings → Access Tokens
- Create new token with "Read" access
- Copy the token (starts with
hf_...)
Create .env file:
cp .env.example .envEdit .env with your credentials:
# Telegram Bot (from @BotFather)
BOT_TOKEN=your_telegram_bot_token
# Google OAuth (from Google Cloud Console)
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
GOOGLE_REDIRECT_URI=http://localhost:3000/callback
# OAuth Server
OAUTH_SERVER_PORT=3000
# Database
DATABASE_PATH=./data/expenses.db
# Encryption (generate with: openssl rand -hex 32)
ENCRYPTION_KEY=your_32_byte_hex_encryption_key
# Environment
NODE_ENV=development
# Hugging Face (optional, for AI features)
HF_TOKEN=your_hugging_face_api_tokenGenerate encryption key:
openssl rand -hex 32Development mode (with auto-reload):
bun run devProduction mode:
bun run startYou should see:
🚀 Starting ExpenseSyncBot...
📦 Initializing database...
✓ Database ready
🌐 Starting OAuth server...
✓ OAuth server running on http://localhost:3000
🤖 Starting Telegram bot...
✓ Bot started successfully
✅ ExpenseSyncBot is running!
Press Ctrl+C to stop
- Start a chat with your bot in Telegram
- Send
/start - Send
/connectto begin Google authorization - Click the authorization link
- Grant permissions in Google
- Select default currency
- Select additional currencies
- Bot will create a Google Sheet and you're ready!
Simply send a message in any supported format:
100 еда обед в ресторане
50$ транспорт такси
1900 RSD развлечения кино
The bot will:
- Parse the expense
- Show you the parsed data
- Ask for confirmation if it's a new category
- Save to Google Sheets
- Confirm the save
Basic Commands:
/start- Welcome message and setup status/connect- Connect Google account and setup/reconnect- Reconnect Google account
Expense Management:
/stats- View expense statistics/sum(or/total) - Sum expenses by filters (category, currency, date range)/sync- Manual sync to Google Sheets/categories- List all categories
Budget & Planning:
/budget- Create and manage budgets
Spreadsheet:
/spreadsheet- Get link to your Google Sheet
AI Features (Groups):
@botname <question>- Ask AI about your expenses (mention bot in groups)/advice- Get daily AI financial advice/prompt- Manage custom AI system prompt for your group
Settings:
/settings- View current settings
The bot includes AI-powered expense analysis using Hugging Face models:
- Ask Questions: Mention the bot in group chats with your question (e.g.,
@botname how much did I spend on food this month?) - Daily Advice: Set up scheduled financial advice using
/advicecommand - Custom Prompts: Configure AI behavior per-group using
/promptcommand - Context-Aware: AI has access to all expenses, budgets, and categories
AI features require HF_TOKEN in .env file.
The bot works in both personal chats and group chats:
- Personal: Each user has their own spreadsheet, categories, and expenses
- Groups: Shared spreadsheet and budgets, multiple users can contribute expenses
- AI features are available in groups (mention bot to ask questions)
src/
├── bot/
│ ├── commands/ # Bot commands (/start, /connect, etc.)
│ ├── handlers/ # Message and callback handlers
│ └── keyboards.ts # Inline keyboard builders
├── database/
│ ├── repositories/ # Data access layer
│ ├── schema.ts # Database migrations
│ └── types.ts # TypeScript types
├── services/
│ ├── google/
│ │ ├── oauth.ts # OAuth2 flow
│ │ └── sheets.ts # Google Sheets API
│ └── currency/
│ ├── parser.ts # Expense message parser
│ └── converter.ts # Currency conversion
├── web/
│ └── oauth-callback.ts # OAuth callback server
└── config/
├── constants.ts # App constants
└── env.ts # Environment config
- Runtime: Bun
- Telegram: GramIO
- Database: SQLite (bun:sqlite)
- Google API: googleapis
- AI: Hugging Face Inference API
- Currency: currency.js
- Date Utils: date-fns
# Development mode with auto-reload
bun run dev
# Production mode
bun run start
# Type checking
bun run type-check
# or directly:
bunx tsc --noEmitSQLite database is stored in ./data/expenses.db (gitignored).
Migrations run automatically on startup. See src/database/schema.ts for migration logic.
Important: Never modify deployed migrations - always add new ones.
Edit src/config/constants.ts:
- Add aliases to
CURRENCY_ALIASES - Add code to
SUPPORTED_CURRENCIES - Add symbol to
CURRENCY_SYMBOLS - Add exchange rate in src/services/currency/converter.ts
- Create handler in
src/bot/commands/ - Register in src/bot/index.ts
- Add to README commands list
The bot is deployed on Digital Ocean using PM2 process manager. See DEPLOY.md for complete deployment guide.
Key features:
- PM2 for process management and auto-restart
- Caddy reverse proxy for HTTPS OAuth callbacks
- GitHub Actions for auto-deployment
- SQLite database persisted in
./data/
Make sure the redirect URI in .env matches exactly what you configured in Google Cloud Console.
- Check bot token is correct
- Make sure bot is running (
bun run devorbun run start) - Check logs for errors
- Check OAuth token is valid (
/reconnect) - Verify spreadsheet wasn't deleted
- Check Google API quotas
- Verify
HF_TOKENis set in.env - Check Hugging Face API status
- Make sure you're using the bot in a group (for AI questions)
- Check logs for API errors
MIT
Built with Bun, GramIO, Claude code, and ❤️