Skip to content

AmarnathCJD/GroupSwitch

Repository files navigation

GroupSwitch

A professional Telegram bot for automated rotation of collectible usernames on channels and groups. GroupSwitch enables interval-based username swapping, allowing you to cycle through multiple purchased usernames on a scheduled basis.

Project Concept

Telegram allows channels and groups to have multiple collectible usernames. GroupSwitch automates the process of rotating these usernames at configurable intervals, making it easy to:

  • Showcase Multiple Brands: Rotate between different username identities for your channel
  • Maximize Username Visibility: Display different collectible usernames to your audience over time
  • Automated Management: Set custom intervals (minutes, hours, days) for automatic username rotation
  • Multi-Channel Support: Manage username rotation across multiple channels from different Telegram accounts

The bot continuously monitors your configured channels and automatically swaps the active username according to your schedule, while preserving your primary (non-collectible) username.

Features

  • Automated Username Rotation: Schedule automatic swapping of collectible usernames for channels and groups
  • Multi-Session Management: Handle multiple Telegram accounts simultaneously
  • Interval-Based Swapping: Configure custom swap intervals (minutes, hours, days) per channel
  • Dual Authentication: Support for both phone number and Telegram Desktop session file import
  • Smart Caching: 15-minute username cache to minimize API calls and improve performance
  • Bulk Operations: Enable or disable swapping for all channels at once
  • Real-time Status: Monitor swap progress with countdown timers and next swap information
  • Primary Username Protection: Automatically detect and preserve primary (non-collectible) usernames
  • Flexible Configuration: Different intervals for different channels based on your needs

Prerequisites

  • Go 1.21 or higher
  • MongoDB instance (local or cloud)
  • Telegram Bot Token from @BotFather
  • Telegram API credentials (APP_ID and APP_HASH) from my.telegram.org

Installation

  1. Clone the repository:
git clone github.com/AmarnathCJD/GroupSwitch
cd GroupSwitch
  1. Install dependencies:
go mod download
  1. Configure environment variables:
cp .env.example .env
  1. Edit .env with your credentials:
BOT_TOKEN=your_bot_token_here
APP_ID=your_app_id_here
APP_HASH=your_app_hash_here
MONGO_URI=your_mongodb_connection_string
LOGS_CHANNEL=0

Usage

Starting the Bot

go run .

Or build and run:

go build -o groupswitch
./groupswitch

Bot Commands

Command Description
/start Display welcome message and available commands
/addsession Add a new Telegram session (phone or file)
/sessions List all active sessions with statistics
/manage Manage sessions and channel configurations
/status View current swap status and countdown timers

Adding a Session

Via Phone Number:

  1. Use /addsession and select "📱 Via Phone Number"
  2. Enter your phone number
  3. Enter the verification code
  4. Enter 2FA password if enabled

Via Telegram Desktop Session:

  1. Export your Telegram Desktop tdata folder
  2. Compress it into a ZIP file
  3. Use /addsession and select "📁 Via Session File"
  4. Upload the ZIP file

Managing Channels

  1. Use /manage to view your sessions
  2. Select a session to view its channels
  3. Use "➕ Add Channel" to add channels/groups from your account
  4. Click on any channel to configure:
    • Toggle username swapping on/off
    • Set custom swap intervals for rotation
    • Remove channel from rotation

Note: Channels must have at least 2 usernames (collectible usernames) to enable swapping. The primary username is automatically excluded from rotation.

Swap Intervals

Specify intervals in the following formats:

  • Minutes: 5m, 10m, 30m
  • Hours: 1h, 2h, 12h
  • Days: 1d, 7d

Minimum interval: 5 minutes

The bot will rotate through all collectible usernames sequentially, changing the active username at each interval.

Architecture

GroupSwitch/
├── main.go           # Application entry point
├── config.go         # Environment configuration
├── bot.go           # Bot initialization and handlers
├── sessions.go      # Session and channel management
├── database.go      # MongoDB operations
├── swapper.go       # Background username rotation engine
├── tdata.go         # Telegram Desktop session parser
└── utils.go         # Utility functions

Technical Details

Session Storage

All session data is securely stored in MongoDB with the following structure:

  • User credentials (encrypted string sessions)
  • Channel configurations
  • Swap schedules and intervals
  • Username cache with 15-minute TTL

Username Rotation Algorithm

  1. Check if swap interval has elapsed for each channel
  2. Retrieve cached usernames or fetch from Telegram API if cache expired
  3. Identify primary username (non-editable/non-collectible) and skip it from rotation
  4. Deactivate all collectible usernames
  5. Activate next collectible username in sequential rotation
  6. Update last swap time and continue cycle

Performance Optimizations

  • Username caching reduces API calls by ~30x
  • Background goroutine prevents blocking operations
  • Panic recovery ensures continuous operation
  • Efficient MongoDB queries with proper indexing

Security

  • Environment-based configuration prevents credential exposure
  • .env file excluded from version control
  • Secure session string storage in MongoDB
  • Input validation for file uploads (ZipSlip protection)

Error Handling

The bot implements comprehensive error handling:

  • Graceful recovery from panics in background workers
  • User-friendly error messages with emoji indicators
  • Automatic retry logic for transient failures
  • Detailed logging for debugging

Contributing

Contributions are welcome! Please follow these guidelines:

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

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

Support

For issues, questions, or feature requests, please open an issue on GitHub.

Acknowledgments

  • Built with gogram - MTProto implementation in Go
  • MongoDB driver for Go
  • godotenv for environment configuration

Note: This bot is designed for managing collectible usernames on Telegram channels and groups. Users are responsible for complying with Telegram's Terms of Service and username policies.

About

A bot based system to automate collectible usernames swapping of a telegram channel

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages