CoolFace
Apppublic

flexistcrypto/AtlasMapBot

sourceHugging Faceupdated 4mo agoView on Hugging Face
0likes
App README

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 (via RapidFuzz with $\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 /health diagnostic 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:

text
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 suite

Local 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:

bash
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

Install the production dependencies:

bash
pip install -r requirements.txt

3. Configure Environment Variables

Create a file named .env in the root of the project (a template .env is provided):

env
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.json

4. Run the Bot

Start the polling loop locally:

bash
python bot.py

Testing Suite

The project includes a robust testing suite powered by pytest with $\ge 90\%$ test coverage.

To run the unit tests:

bash
pytest -v

Tests 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:

bash
docker-compose up -d --build

To view rolling logs:

bash
docker-compose logs -f

Option 2: Production VPS (Ubuntu Systemd)

For deploying directly on an Ubuntu VPS without containers:

  1. 1.Clone files to /var/www/india_geography_bot/.
  2. 2.Ensure the database JSON is placed at /var/www/india_geography_db/india_geography.json.
  3. 3.Set up the virtual environment, install requirements, and configure the .env file.
  4. 4.Create a systemd service file:
bash
   sudo nano /etc/systemd/system/geobot.service
  1. 1.Paste the following configuration:
ini
   [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
  1. 1.Reload, enable, and start the daemon:
bash
   sudo systemctl daemon-reload
   sudo systemctl enable geobot.service
   sudo systemctl start geobot.service

Option 3: Railway / Render

To deploy on PaaS environments:

  1. 1.GitHub Repository: Push the project folder to GitHub. Ensure requirements.txt is in the root.
  2. 2.Environment Variables: Configure BOT_TOKEN, ADMIN_ID, LOG_LEVEL in the Render/Railway service settings.
  3. 3.Database File: If the database file is static, place india_geography.json inside a subdirectory within the repository (e.g. india_geography_db/india_geography.json) and configure DATABASE_PATH=./india_geography_db/india_geography.json in your PaaS env variables.
  4. 4.Deploy: Render/Railway will automatically detect requirements.txt, build the environment, and execute python bot.py.