Download the PHP package afaztech/reactor-broadcast without Composer
On this page you can find all versions of the php package afaztech/reactor-broadcast. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download afaztech/reactor-broadcast
More information about afaztech/reactor-broadcast
Files in afaztech/reactor-broadcast
Package reactor-broadcast
Short Description Broadcast (send / copy / forward) with progress statistics for Reactor bots.
License MIT
Informations about the package reactor-broadcast
Reactor Broadcast
Broadcast (send / copy / forward) with progress statistics for Reactor bots.
This package is built specifically for the Reactor PHP framework. It requires
afaztech/reactor-framework ^0.5.0and will not work standalone.
Overview
Reactor Broadcast delivers mass messages to every user of a Telegram bot without blocking the bot's main loop. Jobs are processed asynchronously through the Reactor queue, progress is tracked per recipient, and the whole flow can be paused, resumed or cancelled at any time.
Three delivery strategies are available:
| Strategy | Description |
|---|---|
send |
Send a fresh text message (optional inline/reply keyboard). |
copy |
Copy an existing message from any chat. No "Forwarded from" label. |
forward |
Forward an existing message from any chat, with the "Forwarded from" label. |
Every recipient is recorded in a dedicated table with one of four states: pending, sent, failed, or blocked. Aggregate counters are updated live so the operator can watch progress in real time.
Requirements
- PHP >= 8.1
afaztech/reactor-framework^0.5.0- A Reactor application with migrations and the queue worker configured
- A running queue worker:
php reactor.php queue:work --queue=broadcast
Installation
Install the package through Composer. The service provider is auto-discovered through Composer metadata (extra.reactor.providers), so no manual registration is required.
Run the migrations to create the broadcasts and broadcast_recipients tables:
Start the queue worker that will process the broadcasts:
In production, run the worker under a supervisor (systemd, supervisord, ...) so it restarts automatically after a crash.
Configuration
The package is configured programmatically through the fluent BroadcastConfig value object. There is no config file to publish.
Bind BroadcastConfig in your application's service provider. The package registers an empty default when the application does not override it, so a bare setup works out of the box:
Available setters
| Method | Default | Description |
|---|---|---|
table(string $name) |
users |
Table that stores your users. |
column(string $name) |
user_id |
Column holding the Telegram user ID. |
onlyActive(string $column, mixed $value) |
disabled | Only include rows where $column = $value. |
withoutActiveFilter() |
— | Disable the active-user filter. |
onlyRecent(string $column, int $days) |
disabled | Only include rows newer than $days. |
withoutRecentFilter() |
— | Disable the recent-interaction filter. |
where(string $col, string $op, mixed $val) |
— | Add a raw WHERE clause. Callable multiple times. |
withoutRawFilters() |
— | Clear all raw filters. |
chunkSize(int $size) |
500 |
Recipients per batch when collecting IDs. |
batchDelayMs(int $ms) |
200 |
Delay between batches in milliseconds. |
cancelCheckEvery(int $n) |
50 |
Check pause/cancel status every N messages. |
queue(string $name) |
broadcast |
Queue name used by the processing job. |
Usage
Getting the manager
Start a text broadcast
Copy an existing message
The message will be delivered to every recipient without the "Forwarded from" label.
Forward an existing message
The message will be delivered with the "Forwarded from" label.
Send to a custom list of recipients
Pass $recipientIds to bypass the configured RecipientProviderInterface and target a specific set of users.
Get progress
Control a running broadcast
A paused broadcast keeps its progress. Resuming re-queues the processing job and continues from the first pending recipient, so no user receives a message twice.
Status lifecycle
Example handlers
Two ready-to-use handlers for a test bot. No access control is applied — add an admin check before deploying to production.
Start a broadcast by replying to a message
Check broadcast progress
Custom recipient providers
If your users are not stored in a single table, or require logic that the ConfigurableRecipientProvider cannot express, implement RecipientProviderInterface and bind it in your application's service provider. The binding overrides the package default.
Then in AppServiceProvider:
Error handling
The processing job classifies every failure automatically:
| Exception | Behavior |
|---|---|
RateLimitException |
Waits exactly retry_after seconds, then retries the same recipient. |
PermanentException with "blocked" / "deactivated" / "kicked" |
Marks recipient as blocked. Increments the blocked counter. |
PermanentException (other) |
Marks recipient as failed. Stores the error message. |
TransientException |
Marks recipient as failed. |
Any other Throwable |
Marks recipient as failed and logs the error. |
Testing the package locally
To develop against a local checkout, add a path repository in your application's composer.json:
The framework must also be a path repository or a tagged release of ^0.5.0. When the framework is checked out locally, add a branch-alias to its composer.json so dev-main is treated as 0.5.x-dev:
License
MIT. See LICENSE.