This is a simple telegram bot expense tracker that allows you to add, edit and delete expenses. It use a Google Drive spreadsheet as a database.
- Add expense in telegram chat
- Edit expense in telegram chat
- Delete expense in telegram chat
- Show expenses in telegram chat
- Retrieve all monthly expenses in image format
- Retrieve all monthly expenses in pie chart format
- Save recurring expenses and automatically add them to the new spreadsheet
- (Optional) Wise integration: automatically add a new expense when a new transaction is made on your Wise account
- Create a new telegram bot using BotFather
- Create a new Google Drive spreadsheet
- Create a new Drive API service account and download the JSON file
- Share the spreadsheet with the service account email
- Create a new spreadsheet and share it with the service account email
Before working with Telegram's API, you need to get your own API ID and hash:
-
Go to https://my.telegram.org/ and login with your phone number.
-
Click under API Development tools.
-
A Create new application window will appear. Fill in your application details. There is no need to enter any URL, and only the first two fields (App title and Short name) can currently be changed later.
-
Click on Create application at the end. Remember that your API hash is secret and Telegram won't let you revoke it. Don't post it anywhere!
-
Open a conversation with @BotFather in Telegram
-
Use the /newbot command to create a new bot. The BotFather will ask you for a name and username, then generate an authorization token for your new bot.
The name of your bot is displayed in contact details and elsewhere.
The Username is a short name, to be used in mentions and telegram.me links. Usernames are 5-32 characters long and are case insensitive, but may only include Latin characters, numbers, and underscores. Your bot's username must end in ‘bot’, e.g. ‘tetris_bot’ or ‘TetrisBot’.
The token is a string along the lines of 110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw that is required to authorize the bot and send requests to the Bot API. Keep your token secure and store it safely, it can be used by anyone to control your bot.
In order to enable Wise integration you need to create a new Wise Webhook. You can do it from here.
curl -X GET https://api.sandbox.transferwise.tech/v4/profiles/P56202086/balances?types=STANDARD
-H 'Authorization: Bearer c61d6c7d-cbe1-431a-a484-ab493af05844'
curl -X GET "https://api.transferwise.com/v3/profiles/{{profileId}}/subscriptions/{{subscriptionId}}"
-H 'Authorization: Bearer c61d6c7d-cbe1-431a-a484-ab493af05844'
Environment | Function | Default Value |
---|---|---|
CURRENCY |
(Optional) the currency used in application | EUR |
TG_API_ID |
telegram API key generated at ´Generating Telegram API keys´ | [REQUIRED] |
TG_API_HASH |
telegram API hash generated at ´Generating Telegram API keys´ | [REQUIRED] |
TG_BOT_TOKEN |
telegram BOT token generated at ´Creating a Telegram Bot´ | [REQUIRED] |
SPREADSHEET_ID |
Id of the Google Drive Spreadsheet, you can retrieve it from url | [REQUIRED] |
USER_ID |
The autorized telegram user ID | [REQUIRED] |
GOOGLE_APPLICATION_CREDENTIALS_JSON |
The Google JSON credential file generated when created a new service account | [REQUIRED] |
On new year you need to create a new spreadsheet and share it with the service account email. Then you need to update
the SPREADSHEET_ID
environment variable with the new spreadsheet id.
version: "3"
services:
monthly-expenses:
privileged: true
image: stefanoimperiale/monthly-expenses
container_name: monthly-expense-tracker
restart: unless-stopped
environment:
- CURRENCY=EUR
- TG_API_ID=123456
- TG_API_HASH=123456
- TG_BOT_TOKEN=123456
- SPREADSHEET_ID=123456
- USER_ID=123456
- GOOGLE_APPLICATION_CREDENTIALS_JSON='{JSON-FILE-CONTENT}'