Skip to content

im4tta/mefapibot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ‡°πŸ‡­ Data Portal Bot

Telegram Bot Node.js Docker License

A Telegram bot providing real-time public data from Cambodia


πŸ“‹ Overview

Data Portal Bot is an open-source Telegram bot that provides convenient access to Cambodia's public data through a simple chat interface. Get instant updates on air quality, weather, exchange rates, and stock market information - all from official public sources.

Data Sources:

  • Air Quality Index from public monitoring stations
  • Weather data from meteorological services
  • Exchange rates from official financial sources
  • Stock market data from Cambodia Securities Exchange (CSX)
  • All data sourced from MEF Cambodia Open Data Portal

✨ Features

  • 🌬️ Air Quality Index (AQI) - Real-time air quality monitoring
  • 🌀️ Weather Data - Current weather conditions
  • β˜€οΈ UV Index - Sun exposure levels with safety tips
  • πŸ’± Exchange Rates - USD/KHR and other currencies
  • πŸ“ˆ Stock Market - CSX index and market summary
  • πŸ“Š Economic Data - Public economic indicators
  • 🐳 Docker Support - Easy containerized deployment
  • πŸ”„ Auto-recovery - Automatic restart on failures
  • πŸ’Ύ Smart Caching - Efficient data caching (5-minute TTL)

πŸ“± Available Commands

/start       - Open main menu
/aqi         - Air Quality Index
/weather     - Current weather
/uv          - UV Index
/exchange    - Exchange rates
/csx_index   - CSX stock index
/csx_summary - CSX market summary
/stats       - Bot statistics
/health      - Health status

πŸš€ Quick Start

Prerequisites

Installation

# 1. Clone repository
git clone https://github.com/im4tta/mefapibot.git
cd mefapibot

# 2. Install dependencies
npm install

# 3. Configure environment
cp .env.example .env
# Edit .env with your credentials

# 4. Initialize database
npm run init-db

# 5. Start bot
npm start

πŸ” Configuration

Create a .env file with your credentials:

# Telegram Bot Token (required)
BOT_TOKEN=your_bot_token_from_botfather

# PostgreSQL Database URL (required)
DATABASE_URL=postgresql://user:password@host:5432/database

# Admin User IDs (optional)
ADMIN_USER_IDS=your_telegram_user_id

# API Configuration
MEF_API_URL=https://data.mef.gov.kh/api/v1

# Environment
NODE_ENV=production

Getting Credentials

  1. Bot Token: Message @BotFather on Telegram

    • Send /newbot and follow prompts
    • Copy the token provided
  2. Database: Get free PostgreSQL from:

  3. User ID: Message @userinfobot to get your Telegram ID

🐳 Docker Deployment

Using Docker Compose (Recommended)

cd docker
docker-compose up -d

# View logs
docker-compose logs -f

# Stop
docker-compose down

Using Docker Run

# Build
docker build -t data-portal-bot .

# Run
docker run -d \
  --name data-portal-bot \
  --env-file .env \
  -p 3000:3000 \
  data-portal-bot

Windows

cd docker
.\run-docker.bat

πŸ“ Project Structure

mefapibot/
β”œβ”€β”€ api/                    # API endpoints
β”‚   β”œβ”€β”€ daily-broadcast.js # Scheduled broadcasts
β”‚   β”œβ”€β”€ health.js          # Health check endpoint
β”‚   β”œβ”€β”€ index.js           # Express server
β”‚   β”œβ”€β”€ metrics.js         # Metrics endpoint
β”‚   └── webhook.js         # Telegram webhook handler
β”œβ”€β”€ docker/                 # Docker configuration
β”‚   β”œβ”€β”€ docker-compose.yml
β”‚   β”œβ”€β”€ run-docker.bat
β”‚   └── stop-docker.bat
β”œβ”€β”€ scenes/                 # Command handlers
β”‚   β”œβ”€β”€ aqi.js             # Air quality commands
β”‚   β”œβ”€β”€ economic.js        # Economic data commands
β”‚   β”œβ”€β”€ exchange.js        # Exchange rate commands
β”‚   └── weather.js         # Weather commands
β”œβ”€β”€ scripts/                # Utility scripts
β”‚   β”œβ”€β”€ init-db.js         # Database initialization
β”‚   └── setup-webhook.js   # Webhook setup
β”œβ”€β”€ admin.js                # Admin panel features
β”œβ”€β”€ bot.js                  # Main bot entry point
β”œβ”€β”€ bot-class.js            # Bot class implementation
β”œβ”€β”€ database.js             # Database utilities
β”œβ”€β”€ keyboards.js            # Telegram keyboard layouts
β”œβ”€β”€ package.json            # Dependencies
β”œβ”€β”€ Dockerfile              # Docker configuration
β”œβ”€β”€ .env.example            # Environment template
└── README.md               # This file

πŸ› οΈ Development

Available Scripts

npm start              # Start the bot
npm run dev            # Development mode
npm run init-db        # Initialize database
npm run setup-webhook  # Configure webhook
npm run docker:build   # Build Docker image
npm run docker:run     # Run Docker container
npm run docker:stop    # Stop Docker container

Database

The bot uses PostgreSQL to store operational data. Initialize with:

npm run init-db

Privacy Note: This bot does not collect or store personal user data.

πŸ”’ Security & Privacy

Data Privacy

  • βœ… No personal data collection
  • βœ… Public data sources only
  • βœ… No user tracking or analytics
  • βœ… Open source and transparent

Security Features

  • Environment variables for sensitive config
  • No hardcoded credentials
  • Input validation
  • Rate limiting on API calls
  • Secure database connections (SSL)
  • Error handling without exposing internals

Best Practices

  • Keep bot token secure
  • Use strong database passwords
  • Enable SSL for database
  • Keep dependencies updated: npm audit fix

οΏ½ API Endpoints

When running, the bot exposes these endpoints:

  • GET /api/health - Health check
  • GET /api/metrics - Bot metrics
  • POST /webhook - Telegram webhook (production)

🀝 Contributing

Contributions are welcome! To contribute:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

πŸ“ License

This project is licensed under the MIT License - see LICENSE file.

πŸ™ Acknowledgments

πŸ“ž Support

βš–οΈ Disclaimer

This bot provides information from public data sources for informational purposes only. The accuracy and availability of data depend on the source APIs. This is an independent project and is not officially affiliated with any government agency or data provider.


Made with ❀️ for Cambodia

About

A Telegram bot providing real-time public data from Cambodia

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages