bot_report — Telegram bot for exporting reports from Google Sheets
A password-protected Telegram bot built with Python that exports a secured Google Sheet and delivers it to the user as an Excel file upon request.

Slide 1 of 2
DESCRIPTION
The bot provides a summary report of the company stored in Google Sheets. It is implemented using pure requests: a custom long polling loop getUpdates with offset management and deduplication of updates by update_id (a set of processed ids trimmed to the last 1000 to avoid memory accumulation).
Password authentication
Access to the bot is password-protected. The list of authorized users is persisted in a JSON file (authorized_users.json); the password check normalizes input (removing spaces and converting to lowercase). After authorization, the user is provided with a permanent ReplyKeyboard featuring an export button.
Export via Google Drive API
The sheet is protected, so downloading occurs via the Google Drive API: a service account (api_gg.json) is authorized in the drive.readonly scope, the file is exported using the files().export_media method in xlsx format (preserving all sheets and styles) and downloaded in chunks through MediaIoBaseDownload to a temporary file, which is then sent as a document and deleted. Errors at each stage are caught and returned to the user with clear messages.
TOOLS USED
- Python
- Telegram Bot API
- requests
- Google Drive API
- google-auth
- google-api-python-client
- JSON
- Git
RESULT
- Implemented export of a protected Google Sheet via Drive API (export_media to xlsx) with chunked download to a temporary file.
- Implemented password access with a persistent list of authorized users in JSON and password input normalization.
- Implemented long polling with deduplication of updates by update_id and a buffer size limit for processed ids.
- Implemented a permanent ReplyKeyboard and error handling for exports with user-friendly message returns.
AI-ASSISTANT
Ask a question about this project