A Telegram bot for monitoring the available balance in YNAB (You Need A Budget).
The application is built with Spring Boot, integrates with the YNAB API and the Telegram Bot API, stores balance state and recipient lists in DynamoDB, sends daily notifications, and responds to commands via a webhook.
- Fetches the available balance from YNAB (“to be budgeted”) with server knowledge support.
- Telegram command to request the current balance.
- Scheduled daily balance notifications.
- Telegram webhook for user registration and command handling.
- Manually triggered job endpoint to check for balance changes and send notifications.
- Persists the last known balance and server knowledge in DynamoDB.
- YNAB integration:
YnabClientcalls/budgets/{budgetId}/months/{month}and supports thelast_knowledge_of_serverparameter to reduce traffic. - Telegram webhook:
TelegramWebhookControllerreceives updates, handles/start(recipient registration), and processes the balance request command. - Daily scheduler:
DailyBalanceJobsends the balance to all recipients via cron. - Change detection:
BalancePollServicecompares the current value with the stored one and notifies recipients only if it has changed. - DynamoDB: stores balance state and the list of recipient chat IDs.
- Java 17
- Maven 3.9+
- AWS access (DynamoDB) for the non-dev profile
Core configuration is defined in src/main/resources/application.yml and can be overridden via environment variables.
| Variable | Description |
|---|---|
YNAB_TOKEN |
OAuth token for the YNAB API |
YNAB_BUDGET_ID |
YNAB budget ID |
TELEGRAM_BOT_TOKEN |
Telegram bot token |
TELEGRAM_WEBHOOK_SECRET |
Secret for validating webhook requests (X-Telegram-Bot-Api-Secret-Token) |
BUDGETBOT_JOB_TOKEN |
Token for /jobs/poll (X-Budgetbot-Job-Token) |
DYNAMODB_TABLE |
DynamoDB table for storing balance state |
DYNAMODB_RECIPIENTS_TABLE |
DynamoDB table for storing recipients |
server.port— HTTP server port (default: 8080)jobs.cronandjobs.zone— schedule and time zone for the daily jobcurrency.symbolandcurrency.fraction-digits— currency formatting
POST /telegram/webhook
X-Telegram-Bot-Api-Secret-Token: <TELEGRAM_WEBHOOK_SECRET>
POST /telegram/webhook— receives Telegram updates/startregisters a user in the recipients table and sends a keyboard- The "Get current balance" button returns the current available balance
POST /jobs/poll
X-Budgetbot-Job-Token: <BUDGETBOT_JOB_TOKEN>
Triggers a balance change check and sends notifications if the value has changed.
GET /actuator/healthGET /actuator/info
- Install Java 17.
- Export the required environment variables.
- Start the application:
./mvnw spring-boot:run
docker build -t budgetbot .
docker run -p 8080:8080 \
-e YNAB_TOKEN=... \
-e YNAB_BUDGET_ID=... \
-e TELEGRAM_BOT_TOKEN=... \
-e TELEGRAM_WEBHOOK_SECRET=... \
-e BUDGETBOT_JOB_TOKEN=... \
-e DYNAMODB_TABLE=... \
-e DYNAMODB_RECIPIENTS_TABLE=... \
budgetbot
The repository includes a GitHub Actions workflow that builds the Docker image, pushes it to ECR, and updates the ECS service. AWS credentials are provided via OIDC.
./mvnw test