A Telegram Bot to track your expenses.
Expense Tracker Bot
is a Telegram Bot to track your expenses. It is built using Go.
-
Create a new bot using BotFather.
- Use
/newbot
command to create a new bot. - Use
/setname
command to set a name for the bot. - Use
/setdescription
command to set a description for the bot.
- Use
-
Set commands for the bot using
/setcommands
command.new - Add new Transaction, Account or User newtxn - Add new transaction user - List persons involved in some loan/borrow with the system user balance - List Account Balance expense - Fetch Expense of Current month summary - Transaction summary of current month allsummary - Transaction summary based on Type, Category, Subcategory report - Transaction Report cat - List Transaction categories help - Show Usage page
-
Create a Token for the bot.
- Use
/token
command to get the bot token.
- Use
create-telegram-bot.mp4
By default, the application uses SQLite as its database, requiring no additional setup.
If you prefer to use PostgreSQL, follow these steps:
-
Install PostgreSQL using Homebrew:
brew update brew install postgresql brew services start postgresql
-
Create a superuser named
postgres
with passwordpostgres
:psql postgres -c "CREATE USER postgres WITH SUPERUSER PASSWORD 'postgres';"
-
Create a new database named
expense
:psql -u postgres -c "CREATE DATABASE expense;"
If you want to back up your SQLite database to Google Drive regularly, follow these steps:
-
Create a Google Project (if not already created).
-
Create a Service account named
expense-tracker
and download a service account JSON key. -
Enable the Google Drive API for your project.
-
On Google Drive:
- Create a folder named
.expense-tracker
. - Share this folder with the service account (
expense-tracker@<project-id>.iam.gserviceaccount.com
) and grant it "Editor" permission.
- Create a folder named
-
Clone the repository:
mkdir -p $GOPATH/src/github.com/masudur-rahman cd $GOPATH/src/github.com/masudur-rahman git clone [email protected]:masudur-rahman/expense-tracker-bot.git
-
Update the configuration file (
configs/.expense-tracker.yaml
) as needed. You can modify the Telegram user and specify the database type.telegram: user: masudur_rahman database: type: sqlite
-
Export required environment variables:
export TELEGRAM_BOT_TOKEN=<TELEGRAM_BOT_TOKEN>
If backing up to Google Drive:
export GOOGLE_APPLICATION_CREDENTIALS=$HOME/Downloads/service-account-key.json
-
Run the server:
make run
-
Write configuration file
mkdir -p $HOME/.expense-tracker/configs echo ' telegram: user: masudur_rahman database: type: sqlite ' > $HOME/.expense-tracker/configs/.expense-tracker.yaml
-
Run Expense Tracker Bot
docker run -v $HOME/.expense-tracker/configs:/configs \ -v $HOME/.expense-tracker:/.expense-tracker \ -e TELEGRAM_BOT_TOKEN=<TELEGRAM_BOT_TOKEN> \ ghcr.io/masudur-rahman/expense-tracker-bot:v1.0.0 serve
- Create a new app on Back4App.
- Connect your app to a GitHub repository.
- Set the environment variables to the
Settings.Environment Variables
section. - Restart the server.
To deploy Expense Tracker Bot
application in production environment, the preferred way is through Helm Chart. Checkout more here.
- First you need to add the repo for the helm chart.
helm repo add masud https://masudur-rahman.github.io/helm-charts/stable helm repo update helm search repo masud/expense-tracker-bot
- Install the chart
- For installing just with SQLite database (without Google Drive backup)
helm upgrade --install expense-tracker-bot masud/expense-tracker-bot -n demo \ --create-namespace \ --set telegram.token=<TELEGRAM_BOT_TOKEN> \ --set telegram.user=<TELEGRAM_USERNAME>
- SQLite with Google Drive backup
helm upgrade --install expense-tracker-bot masud/expense-tracker-bot -n demo \ --create-namespace \ --set telegram.token=<TELEGRAM_BOT_TOKEN> \ --set telegram.user=<TELEGRAM_USERNAME> \ --set database.sqlite.syncToDrive=true \ --set-file googleCredJson=<GOOGLE-SVC-ACCOUNT-JSON-FILEPATH>
- Postgres database
helm upgrade --install expense-tracker-bot masud/expense-tracker-bot -n demo \ --create-namespace \ --set telegram.token=<TELEGRAM_BOT_TOKEN> \ --set telegram.user=<TELEGRAM_USERNAME> \ --set database.type=postgres \ --set database.deploy=true # set to false if you want to use external database # --set database.postgres.user=<POSTGRES_USER> \ # --set database.postgres.password=<POSTGRES_PASSWORD> \ # --set database.postgres.db=<POSTGRES_DB> \ # --set database.postgres.host=<POSTGRES_HOST> \ # --set database.postgres.port=<POSTGRES_PORT> \ # --set database.postgres.sslmode=<POSTGRES_SSL_MODE>
- For installing just with SQLite database (without Google Drive backup)
- Install the chart
- Verify Installation
To check if
Expense Tracker Bot
is installed, run the following command:$ kubectl get pods -n demo -l "app.kubernetes.io/instance=expense-tracker-bot" NAME READY STATUS RESTARTS AGE expense-tracker-bot-7989d96fcc-b4smq 1/1 Running 2 (30s ago) 31s expense-tracker-bot-postgres-55dcb67965-95r7g 1/1 Running 0 31s