flexistcrypto/AtlasMapBot
India Geography Telegram Bot Assistant
An intelligent, production-grade Telegram Bot that acts as an interactive geography encyclopedia. Powered entirely by a validated in-memory JSON database containing detailed profiles of all 28 Indian states and 5 Union Territories.
Key Features
- ๐ Interactive Profiles: Comprehensive details on Capitals, Area, Population, Demographics, Languages, Economy, Culture, Rivers, and Tourist Attractions.
- ๐ Smart Search Engine: Exact matching, partial matching, alias mapping (e.g.
up,wb,tn), and fuzzy string matching (viaRapidFuzzwith $\ge 85$ score threshold) with spelling suggestions. - ๐ง Rule-Based NLU Parser: Automatically understands natural queries like "what is the capital of UP?" or "population of Bihar" and routes to the correct section.
- ๐ Dynamic Analytics: dynamic statistics calculation (extremes for largest/smallest by area, population density, least/most populous, etc.) derived dynamically from JSON.
- ๐ฎ Interactive Menus: Clean paginated UI keyboards and inline selection carousels optimized for Telegram Mobile.
- ๐ฅ Admin Dashboard: Secure
/healthdiagnostic panel displaying loaded records, uptime, and server memory metrics.
Project Architecture
The bot uses a clean, highly modular Service-Oriented Architecture to keep logic decoupled and future-proof:
india_geography_bot/
โโโ .env # Environment configurations
โโโ requirements.txt # Dependency manifest
โโโ bot.py # Bot bootstrap & catch-all unknown command router
โโโ config.py # Config loader & Loguru rotation setup
โโโ models/
โ โโโ geography.py # Pydantic schema schemas
โโโ services/
โ โโโ geography_service.py # In-memory database loader & indexer
โ โโโ search_service.py # Fuzzy match & advanced keyword search
โ โโโ nlp_service.py # Regex-based Natural Language query parser
โ โโโ analytics_service.py # Dynamic metrics calculations
โ โโโ ai_service.py # Future LLM integration abstraction
โโโ keyboards/
โ โโโ menu.py # Inline paginations & profile keyboards
โโโ handlers/
โ โโโ command_handlers.py # Slash commands routers
โ โโโ callback_handlers.py # Inline selection callback routers
โ โโโ message_handlers.py # Main text routing & NLP queries
โโโ utils/
โ โโโ formatter.py # Safe HTML formatting & sanitization
โโโ tests/ # Test suiteLocal Setup & Installation
1. Prerequisites
Ensure you have Python 3.11+ installed on your system.
2. Clone and Setup Environment
Navigate to your project directory and create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activateInstall the production dependencies:
pip install -r requirements.txt3. Configure Environment Variables
Create a file named .env in the root of the project (a template .env is provided):
BOT_TOKEN=YOUR_TELEGRAM_BOT_TOKEN_FROM_BOTFATHER
ADMIN_ID=YOUR_TELEGRAM_NUMERIC_USER_ID
LOG_LEVEL=INFO
DATABASE_PATH=../india_geography_db/india_geography.json4. Run the Bot
Start the polling loop locally:
python bot.pyTesting Suite
The project includes a robust testing suite powered by pytest with $\ge 90\%$ test coverage.
To run the unit tests:
pytest -vTests cover:
- Database Models: Validation checks and type coercions.
- Search Service: Exact, case-insensitive, alias abbreviations, and fuzzy matching.
- NLP Parser: Regex intent extractions and entities resolution.
- Analytics Engine: Extreme statistics validation.
Deployment Guide
Option 1: Docker (Recommended)
Make sure Docker and Docker Compose are installed on your host.
To start the bot container in background detached mode:
docker-compose up -d --buildTo view rolling logs:
docker-compose logs -fOption 2: Production VPS (Ubuntu Systemd)
For deploying directly on an Ubuntu VPS without containers:
- Clone files to
/var/www/india_geography_bot/. - Ensure the database JSON is placed at
/var/www/india_geography_db/india_geography.json. - Set up the virtual environment, install requirements, and configure the
.envfile. - Create a systemd service file:
sudo nano /etc/systemd/system/geobot.service- Paste the following configuration:
[Unit]
Description=India Geography Telegram Bot
After=network.target
[Service]
Type=simple
User=ubuntu
WorkingDirectory=/var/www/india_geography_bot
ExecStart=/var/www/india_geography_bot/venv/bin/python bot.py
Restart=on-failure
RestartSec=5
Environment=PYTHONUNBUFFERED=1
[Install]
WantedBy=multi-user.target- Reload, enable, and start the daemon:
sudo systemctl daemon-reload
sudo systemctl enable geobot.service
sudo systemctl start geobot.serviceOption 3: Railway / Render
To deploy on PaaS environments:
- GitHub Repository: Push the project folder to GitHub. Ensure
requirements.txtis in the root. - Environment Variables: Configure
BOT_TOKEN,ADMIN_ID,LOG_LEVELin the Render/Railway service settings. - Database File: If the database file is static, place
india_geography.jsoninside a subdirectory within the repository (e.g.india_geography_db/india_geography.json) and configureDATABASE_PATH=./india_geography_db/india_geography.jsonin your PaaS env variables. - Deploy: Render/Railway will automatically detect
requirements.txt, build the environment, and executepython bot.py.
