Creating The Project Files & Connections
1. Create The Bot
- Open Telegram, search for @BotFather
- Send /newbot
- It’ll ask for a name (e.g. “My Expense Tracker”) and a username (e.g. myexpense_bot)
- It gives you a bot token β looks like 123456789:ABCdefβ¦
Save that token somewhere, you’ll need it.
2. Setting Up a Connector to the Sheet
- Go to console.cloud.google.com
- Create a new project (name it anything, e.g. “Expense Bot”)
- Search for “Google Sheets API” and enable it
- Search for “Google Drive API” and enable it
- Go to Credentials β Create Credentials β Service Account
- Give it any name, click through the defaults
- Choose Application data if asked
- Once created, click the service account β Keys tab β Add Key β JSON
- It downloads a .json file β keep that safe as credentials.json, that’s your key
And then:
- Open your Google Sheet
- Share it with the service account email (looks like [email protected])
- Give it Editor access
3. Install the Required Library
pip install python-telegram-bot gspread google-auth flask
You might need these libraries too if you want it to run in tray
pip install pystray pillow
###### DETAILS IS DIFFERENCE ACROSS PROJECTS ######
Running The Bot
1. Fill The Credentials
Open the file and find this
BOT_TOKEN = "YOUR_BOT_TOKEN" # β paste your BotFather token
JSON_KEY_FILE = "credentials.json" # β put your JSON file in the same folder
2. Run the Project
python expense_bot.py
To run in the background, change the extension from .py to .pyw and double click it. Note: only works on Windows
Closing
At the end, just run the .pyw file.