A Python-based Telegram bot for investment fund reporting and portfolio management.
This is a secure, multi-user Telegram bot designed for investment fund managers and their investors. It automates fund reporting and communication through Telegram's convenient interface:
- For Fund Admins: Manage multiple users, send portfolio updates, log activities, and send bulk communications
- For Investors: Instantly download personalized PDF reports, view portfolio summaries, and access fund documents—all via Telegram
The bot integrates with Google Sheets (as a data source), generates professional RTL Persian/Arabic PDF reports with proper typography, and maintains a complete audit trail of all activities.
- Telegram bot built with
python-telegram-botlibrary - Google Sheets integration (read-only service account authentication)
- PDF report generation with RTL (Right-to-Left) support for Persian/Arabic
- Custom Arabic typography using Noto Sans Arabic fonts
- Admin dashboard with:
- User management (listing, filtering)
- Activity logs and summaries
- Bulk portfolio updates
- Capital reminder notifications
- User-friendly interface with:
- Portfolio summary views
- One-click PDF report downloads
- Contract and charity fund documents
- Full activity logging for compliance
The codebase follows a layered, service-oriented architecture with clear separation of concerns:
- Models Layer - Type-safe domain objects (User, Report, etc.)
- Repository Layer - Data persistence abstraction
- Service Layer - Business logic (SheetService, ReportService, UserService, ActivityService)
- Command Layer - 18 independent command classes for request handling
- Handler Layer - Telegram update routing and dispatch
- Dependency Injection - Centralized via DIContainer
Benefits: Testable, maintainable, extensible, reusable services
FundTelegramBot/
├── assets/
│ ├── fonts/
│ │ ├── NotoSansArabic-Regular.ttf
│ │ └── NotoSansArabic-Bold.ttf
│ └── docs/
│ └── contract.pdf
│
├── runtime/
│ ├── bot.log
│ ├── user_data.json
│ ├── chat_ids.json
│ └── snapshots/
│ └── [user wealth history NDJSON files]
│
├── secrets/
│ ├── telegram_bot_token.txt
│ └── fundtelegrambot-xxxx.json
│
├── src/
│ ├── main.py
│ ├── bot/
│ │ ├── app.py
│ │ ├── config.py
│ │ ├── di_container.py
│ │ ├── models/ (User, Report domain models)
│ │ ├── repositories/ (Data access layer)
│ │ ├── services/ (Business logic layer)
│ │ ├── handlers/ (Telegram I/O layer)
│ │ │ └── commands/ (18 independent command classes)
│ │ ├── pdf_report.py
│ │ ├── keyboards.py
│ │ ├── charts_utils.py
│ │ ├── activity_log.py
│ │ └── [utility modules]
│ └── snapshot/
│ ├── job.py
│ ├── build.py
│ ├── storage.py
│ └── parse.py
│
├── installer.sh
├── .gitignore
└── README.md
chmod +x install_dependencies.sh
./install_dependencies.shBefore running the bot, you must populate the secrets/ directory with two files:
This is your bot's authentication token from Telegram.
How to get it:
- Open Telegram and search for @BotFather (Telegram's official bot management service)
- Send
/newbotand follow the instructions to create a new bot - BotFather will provide you with a token like:
123456789:ABCdefGHIJklmnoPQRstuvwxyz-1234567890 - Copy this token into
secrets/telegram_bot_token.txt(just the token, nothing else)
This file allows the bot to read data from your Google Sheets (fund portfolio data).
How to get it:
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the Google Sheets API
- Go to Service Accounts (under "Credentials")
- Create a new service account
- Create a JSON key for the service account
- Save the downloaded JSON file as
secrets/google_service_credentials.jsonin thesecrets/directory - Share your Google Sheet with the service account's email address (found in the JSON file)
.gitignore).
secrets/
├── telegram_bot_token.txt (single line: your bot token)
└── google_service_credentials.json (Google service account JSON)
Beyond credentials, you must also configure these files with your actual fund data:
This file maps Telegram users to their roles and portfolio data.
What to do:
- Open
runtime/user_data.json - Replace the sample data with your actual users
- For each investor, add:
- Their Telegram username (without @)
- Their role (
"user"for investors,"admin"for managers) - Their name and family name (supports Persian/Arabic)
- The Google Sheet name containing their portfolio data
Example:
{
"investor_username": {
"role": "user",
"name": "محمد",
"family": "علی",
"sheet": "Mohammad"
},
"fund_manager": {
"role": "admin",
"name": "علی",
"family": "محمدی"
}
}This is the PDF contract document that investors can download via the bot.
What to do:
- Generate or prepare your fund's investment contract/agreement PDF
- Replace the existing
assets/docs/contract.pdfwith your actual contract - Ensure it's in PDF format
- The bot will serve this file when investors request the contract
- Use your actual fund contract, not a placeholder
- Ensure all legal text and terms are correct
- Test that the PDF downloads correctly through the bot
- Update this file whenever your contract terms change
./start_bot.shsource .venv/bin/activate
python src/main.pyPrivate / internal use.