wizardloop/broadcastmanager

High-performance Telegram broadcast manager for MadelineProto

Maintainers

Package info

github.com/WizardLoop/BroadcastManager

Documentation

pkg:composer/wizardloop/broadcastmanager

Fund package maintenance!

WizardLoop

wizardloop.t.me

Statistics

Installs: 151

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

3.1.0 2026-04-13 06:37 UTC

This package is auto-updated.

Last update: 2026-04-13 06:37:50 UTC


README

High-Performance Telegram Broadcast Manager for MadelineProto. Manage broadcasts efficiently: send messages, media albums, pin/unpin messages, control broadcasts in real-time, and track live progress with advanced features.

AGPL License Made with โค๏ธ Packagist Version Packagist Downloads CI

๐ŸŒŸ Features

  • ๐Ÿš€ High-Performance Broadcasts Send messages concurrently to thousands of users, groups, or channels with configurable concurrency.

  • โธ Pause / Resume / Cancel Broadcasts Control ongoing broadcasts in real-time without restarting.

  • ๐Ÿ“Œ Pin & Unpin Messages

    • Pin the last broadcasted message automatically.
    • Unpin all messages for all subscribers.
  • ๐Ÿงน Delete Last Broadcast

    • Remove previously sent messages from all users.
    • Retries failed deletions and handles Telegram API limits automatically.
  • โ™ป๏ธ Delete All Broadcasts

    • Remove previously all sent messages from all users.
    • Retries failed deletions and handles Telegram API limits automatically.
  • ๐Ÿ“Š Live Progress Tracking

    • Visual progress bars
    • Messages per second (TPS)
    • Sent, failed, and pending counts
    • Paused/cancelled indicators
  • ๐Ÿ–ผ Media Albums Support

    • Send multiple images/documents in a single broadcast using sendMultiMedia.
    • Supports captions and message entities.
  • ๐Ÿ’พ Saving & Reusing Albums
    Save albums to a JSON file for reuse in future broadcasts.
    Use album-bot as an example to store album files locally.

  • ๐Ÿ›ก FLOOD_WAIT Handling & Retries Automatically respects Telegram rate limits and retries failed messages.

  • ๐Ÿ”˜ Inline Buttons / Reply Markup

    • Include interactive buttons for links, commands, or actions.

โšก Installation

composer require wizardloop/broadcastmanager

Include autoload:

require 'vendor/autoload.php';

๐Ÿš€ Usage Example

Send Broadcast

1) live progress update in message to admin:

use BroadcastTool\BroadcastManager;

$manager = new BroadcastManager($api);

$manager->broadcastWithProgress($users, $messages, $adminChatId, true, 20);

2) track on progress without message:

This method returns an integer ID that can be used.

use BroadcastTool\BroadcastManager;

$manager = new BroadcastManager($api);

$broadcastId = $manager->broadcastWithProgress($users, $messages, null, true, 20);

/**
 * Get progress (can be polled)
 */
$progress = $manager->progress($broadcastId);

if ($progress !== null) {

    // ๐Ÿ“Š Core stats
    $processed = $progress['processed'];
    $success   = $progress['success'];
    $failed    = $progress['failed'];
    $pending   = $progress['pending'];
    $flood     = $progress['flood'];

    // ๐Ÿ“ˆ Progress %
    $progressPercent = $progress['progressPercent'];

    // ๐Ÿ“ฆ Breakdown
    $sent    = $progress['breakdown']['sent'];
    $deleted = $progress['breakdown']['deleted'];
    $unpin   = $progress['breakdown']['unpin'];

    // โš™๏ธ State
    $done    = $progress['done'];
    $paused  = $progress['paused'];
    $cancel  = $progress['cancel'];

    // โฑ Timing
    $startedAt = $progress['startedAt'];

    /**
     * Example usage
     */
    echo "Progress: {$progressPercent}%\n";
    echo "Sent: {$sent}\n";
    echo "Failed: {$failed}\n";

    if ($done) {
        echo "Broadcast finished!";
    }

    if ($paused) {
        echo "Broadcast paused...";
    }
}
* progress return array|null {
*   processed: int,           // total processed items (sent + deleted + unpin + failed)
*   success: int,             // successful operations (sent + deleted + unpin)
*   failed: int,              // failed operations count
*   pending: int,             // remaining items in queue
*   flood: int,               // FLOOD_WAIT occurrences
*
*   progressPercent: float,   // completion percentage (processed / total)
*
*   breakdown: array {
*      sent: int,
*      deleted: int,
*      unpin: int
*   },
*
*   done: bool,               // process finished
*   paused: bool,            // process paused
*   cancel: bool,            // process cancelled
*
*   startedAt: float         // microtime start timestamp
* }

Filer Peers

$filterSub = $manager->filterPeers($users, 'users');
$targets = $filterSub['targets']; # array
$failed = $filterSub['failed']; # int
$total = $filterSub['total']; # int

โธ Control Broadcasts

$manager->pause($broadcastId);
$manager->resume($broadcastId);
$manager->cancel($broadcastId);

Check state:

if ($manager->isActive($broadcastId));
if ($manager->isPaused($broadcastId));
if ($manager->isCancelled($broadcastId));
if (!$manager->hasLastBroadcast($broadcastId));
if (!$manager->hasAllBroadcast($broadcastId));
print_r($manager->progress($broadcastId));

Set data dir:

BroadcastManager::setDataDir(__DIR__ . '/data'); // default: __DIR__ . '/../data'

๐Ÿงน Delete Last Broadcast

$broadcastId = $manager->deleteLastBroadcastForAll($users, $adminChatId, 20);

โ™ป๏ธ Delete All Broadcast

$broadcastId = $manager->deleteAllBroadcastsForAll($users, $adminChatId, 20);

๐Ÿ“Š Get Last Broadcast Data

$broadcastId = $manager->lastBroadcastData();

๐Ÿ“Œ Pin / Unpin Messages

Pin last broadcast automatically:

$broadcastId = $manager->broadcastWithProgress(..., pin: true);

Unpin all messages:

$broadcastId = $manager->unpinAllMessagesForAll(...);

๐Ÿ”˜ Inline Buttons & Reply Markup

$message = [
    'message' => "Click a button below:",
    'buttons' => [
        [['text' => "Visit Website", 'url' => "https://example.com"]],
        [['text' => "Start", 'callback_data' => "start_action"]]
    ]
];

โš™๏ธ Advanced Options

  • Concurrency - Number of parallel workers.
  • Filter Types - 'users', 'groups', 'channels', 'all'
  • Album Handling - JSON-based albums with multiple media files.
  • Retries & Delays - Automatic retries with backoff.
  • Progress Tracking - Real-time broadcast stats with progress().

๐Ÿค Contributing

  1. Fork repo
  2. Create branch: git checkout -b feature/my-feature
  3. Commit changes: git commit -m "Add feature"
  4. Push branch: git push origin feature/my-feature
  5. Open Pull Request

๐Ÿ“„ License

GNU AGPL-3.0 - see LICENSE.

๐Ÿ“ Changelog

See [CHANGELOG.md] for updates.

โœ… Pro Tips

  • Use pin: true to pin important broadcasts.
  • Include buttons for interactive messages.
  • Adjust concurrency for optimal performance.
  • Use pause/resume/cancel for safe broadcast control.