Intelligent Telegram bot providing real-time COVID-19 statistics with automated data validation and multi-format support. Built with Node.js and modern API integration.
Live Demo: @stay_aware_of_covid19_bot
- Real-time Data: Fetches live COVID-19 statistics from Johns Hopkins University via disease.sh API
- Multi-language Support: Accepts country names in English, Russian, and other languages
- Smart Fallback Logic: Automatically switches between today's/yesterday's data when API returns zero values
- Data Validation: Handles null/undefined values gracefully with "ΠΠ΅Ρ Π΄Π°Π½Π½ΡΡ " placeholders
- User-friendly Interface: Interactive keyboard with flags, emoji-enhanced responses
- Error Handling: Robust retry logic for API failures and invalid country names
- Runtime: Node.js
- Framework: Telegraf (Telegram Bot Framework)
- API Integration: disease.sh (Johns Hopkins University data)
- Data Processing: Custom formatting with toLocaleString() for readability
- Environment: dotenv for secure token management
- Development: nodemon for auto-restart during development
Problem: Original covid19-api library became deprecated and returned HTML errors instead of JSON.
Solution: Migrated to direct API integration with disease.sh, implementing custom HTTPS request handling with proper error management.
Problem: Many countries report 0 new cases for "today" due to reporting delays. Solution: Implemented intelligent fallback using yesterday's data when today returns 0, ensuring users always see meaningful statistics.
Problem: Users input country names with flags (πΊπΈ Π‘Π¨Π), mixed case, or various spellings. Solution: Created comprehensive mapping dictionary with 100+ country aliases and flag-to-name conversion.
- Input Sanitization: Removes emoji flags, special characters, normalizes case
- Country Mapping: Extensive dictionary supporting 100+ countries in multiple languages
- API Request: Direct HTTPS call to disease.sh with retry logic
- Data Validation: Checks for null/NaN/undefined before formatting
- Response Formatting: Structured Markdown output with timestamps
Users can interact with the bot using:
- Button clicks: πΊπΈ Π‘Π¨Π, π·πΊ Π ΠΎΡΡΠΈΡ, π°πΏ ΠΠ°Π·Π°Ρ ΡΡΠ°Π½
- Text input: "USA", "usa", "Π‘Π¨Π", "Π ΠΎΡΡΠΈΡ", "russia"
- Mixed formats: "πΊπΈ USA", "russia", "Π’ΡΡΡΠΈΡ"
- API Integration: Handling rate limits, errors, and data inconsistencies in third-party APIs
- Data Validation: Implementing robust null-checking and fallback strategies for unreliable data sources
- Internationalization: Supporting multiple input formats and languages in a single interface
- Error Resilience: Building systems that gracefully handle failures while maintaining user experience
- Telegram Bot Architecture: Understanding webhook vs polling, message handling, and UI design with keyboards
- Push code to GitHub
- Connect Railway to repository
- Add environment variable
BOT_TOKEN - Deploy automatically
- Install flyctl:
brew install flyctl - Login:
fly auth login - Initialize:
fly launch - Set secret:
fly secrets set BOT_TOKEN=your_token - Deploy:
fly deploy
βββ bot.js # Main bot logic
βββ constants.js # Country list for /help
βββ package.json # Dependencies
βββ .env.example # Environment variables template
βββ README.md # Documentation
- Tokens and secrets stored in environment variables (never commit to Git!)
.gitignoreprotects sensitive files- Environment examples provided in
.env.example
- Telegram Bot: @stay_aware_of_covid19_bot
- GitHub: nodejs-telegram-bot-covid19
β If this project is helpful - give it a star on GitHub!

