Skip to content

morakib/telegram-otp-bot

Repository files navigation

PROJECT SUMMARY

🎯 Telegram OTP Bot - Complete Implementation

This is a production-ready Telegram bot that automatically monitors IVASMS.com for new OTPs and sends them to a Telegram group with touch-to-copy functionality.

What's Included

Core Bot Files

  • main.py - Flask server + Telegram bot logic with web dashboard
  • scraper.py - IVASMS.com login and OTP extraction with robust parsing
  • otp_filter.py - Smart duplicate detection with persistent caching
  • utils.py - Message formatting and utility functions

Configuration & Dependencies

  • requirements.txt - All Python dependencies (Flask, python-telegram-bot, etc.)
  • .env - Environment variables (with your provided credentials)
  • .env.example - Template for environment variables
  • runtime.txt - Python version specification for cloud deployment

Deployment Files

  • Procfile - Heroku deployment configuration
  • .replit - Replit configuration for easy cloud hosting
  • replit.nix - Replit environment setup
  • .gitignore - Git ignore file (protects sensitive data)

Setup & Testing

  • setup.bat - Windows automatic setup script
  • setup.sh - Linux/Mac automatic setup script
  • start.py - Quick start script with dependency checking
  • test_bot.py - Comprehensive testing suite

Documentation

  • README.md - Project overview and basic setup
  • DEPLOYMENT.md - Detailed deployment guide for multiple platforms
  • templates/dashboard.html - Beautiful web dashboard for monitoring

🚀 Key Features Implemented

  1. ✅ IVASMS Integration

    • Automatic login with session management
    • Robust OTP extraction from multiple page formats
    • Error handling and retry logic
    • Phone number and service name detection
  2. ✅ Telegram Bot

    • Touch-to-copy OTP formatting using <code> tags
    • Group message sending with HTML parsing
    • Error handling and connection management
    • Status and health monitoring
  3. ✅ Duplicate Prevention

    • Persistent JSON-based caching
    • Automatic cache expiration (30 minutes)
    • Smart OTP fingerprinting
    • Cache statistics and management
  4. ✅ Flask Web Server

    • Beautiful dashboard with real-time status
    • RESTful API endpoints for control
    • Health check endpoints for monitoring
    • Background monitoring with threading
  5. ✅ Cloud Deployment Ready

    • Replit configuration for instant deployment
    • Heroku support with Procfile
    • Environment variable management
    • UptimeRobot integration guide

📱 Message Format Example

When an OTP is received, the bot sends this formatted message:

🔐 New OTP Received

🔢 OTP: 672984
📱 Number: +8801721XXXXXX
🌐 Service: Facebook
⏰ Time: 14:23:15

Tap the OTP to copy it!

The OTP code is wrapped in <code> tags making it instantly copyable by tapping in Telegram.

🌐 API Endpoints

  • GET / - Web dashboard or JSON status
  • GET /check-otp - Manual OTP check
  • GET /status - Detailed bot statistics
  • GET /test-message - Send test message
  • GET /clear-cache - Clear OTP cache
  • GET /start-monitor - Start background monitoring
  • GET /stop-monitor - Stop background monitoring

Quick Start Options

Option 1: Windows (Easiest)

double-click setup.bat

Option 2: Manual Setup

pip install -r requirements.txt
python main.py

Option 3: Replit (Cloud)

  1. Upload files to Replit
  2. Add secrets in Replit Secrets tab
  3. Click Run

📊 Monitoring & Maintenance

  1. Dashboard: Access http://localhost:5000 for real-time monitoring
  2. Logs: Console output shows all bot activity
  3. Health Checks: / endpoint for uptime monitoring
  4. UptimeRobot: Ping every 5 minutes to keep bot alive

🛡️ Security Features

  • Environment variable protection
  • Session management for IVASMS
  • Error handling and graceful degradation
  • No hardcoded credentials in source code
  • Gitignore protects sensitive files

🎯 Testing & Quality

  • test_bot.py - Comprehensive test suite
  • Import testing for all dependencies
  • Environment variable validation
  • Connection testing for both IVASMS and Telegram
  • Sample data generation and formatting tests

⚠️ Important Notes

  1. Ethical Use: Only use with your own IVASMS account
  2. Legal Compliance: Ensure compliance with local laws
  3. Rate Limiting: Bot checks every 60 seconds to avoid overloading
  4. Error Recovery: Automatic retry on failures
  5. Cache Management: OTPs expire after 30 minutes

🚀 Deployment Success

This bot is designed to run 24/7 on cloud platforms:

  • Replit: Instant deployment with web interface
  • Heroku: Professional hosting with easy scaling
  • Railway: Simple git-based deployment
  • PythonAnywhere: Budget-friendly Python hosting

📞 Support & Troubleshooting

  1. Run python test_bot.py to diagnose issues
  2. Check the /status endpoint for bot health
  3. Review console logs for detailed error information
  4. Verify environment variables are correctly set

🎉 Ready to Deploy!

Your Telegram OTP bot is complete and ready for production use. All components have been implemented according to your specifications with additional features for reliability and monitoring.

Next Steps:

  1. Install dependencies: pip install -r requirements.txt
  2. Run tests: python test_bot.py
  3. Start bot: python main.py
  4. Deploy to Replit for 24/7 operation
  5. Set up UptimeRobot monitoring

The bot will automatically:

  • Monitor IVASMS for new OTPs every 60 seconds
  • Send formatted messages to your Telegram group
  • Prevent duplicate OTP notifications
  • Provide a web dashboard for monitoring
  • Handle errors gracefully and continue running

This is a complete, professional-grade solution ready for immediate deployment! 🚀

About

Automated Telegram bot for IVASMS OTP monitoring and forwarding

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages