Download the PHP package gruven/phpbotgram without Composer
On this page you can find all versions of the php package gruven/phpbotgram. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gruven/phpbotgram
More information about gruven/phpbotgram
Files in gruven/phpbotgram
Package phpbotgram
Short Description Modern PHP 8.5 port of the aiogram Telegram Bot framework. Fiber-based runtime, codegen-driven typed methods/types, FSM with scenes, webhook + long-polling.
License MIT
Homepage https://github.com/Gruven/phpbotgram
Informations about the package phpbotgram
phpbotgram
A modern PHP 8.5 port of the aiogram Telegram Bot framework.
phpbotgram keeps the layered architecture of the Python upstream — Bot, Session, Dispatcher, Router, filters, middlewares, FSM — but trades coroutines for amphp v3 fibers and uses native PHP 8.5 features (readonly classes, asymmetric visibility, property hooks, attributes, native enums) throughout.
Links
- API documentation — published at https://gruven.github.io/phpbotgram/ (GitHub Pages, rebuilt on every push to
master). Regenerate locally withcomposer docs-api(ormake docs-api); output lands inbuild/docs/api/index.html. - Narrative documentation: https://gruven.github.io/phpbotgram/en/dev/guide/ (tutorial, cookbook, concepts).
- Design spec —
docs/superpowers/specs/. - Implementation plan —
docs/superpowers/plans/2026-05-12-phpbotgram-implementation.md. - Changelog —
CHANGELOG.md. - Deployment templates —
deploy/(nginx, systemd, Docker compose). - Runnable examples —
examples/(see table below).
Requirements
- PHP 8.5+
- ext-sodium (Web App / Login Widget signature verification)
- HTTP transport —
amphp/http-client ^5(required), used by the defaultAmphpSessionadapter - Composer 2.5+
Install
Quickstart — echo bot
Run with BOT_TOKEN=… php echo_bot.php. The full example (with extra documentation) lives at examples/echo_bot.php.
Examples
All examples are runnable and self-contained. Set BOT_TOKEN before launching (and BOT_TOKEN_2 for examples/multibot.php, which adds a second bot to the dispatcher when present).
| Path | Demonstrates |
|---|---|
examples/echo_bot.php |
Long-polling echo bot |
examples/echo_bot_webhook.php |
amphp/http-server webhook via SimpleRequestHandler + AmphpServer::run |
examples/error_handling.php |
Global error observer that logs uncaught exceptions |
examples/finite_state_machine.php |
Inline FSM (no scenes) for a multi-step form |
examples/scene.php |
Scene-based FSM with SceneRegistry::add([Scene::class]) |
examples/quiz_scene.php |
Branching scene flow with conditional transitions |
examples/own_filter.php |
Custom Filter subclass plumbed into $dispatcher->message->register |
examples/specify_updates.php |
Restricting PollingOptions to a subset of update types |
examples/context_addition_from_filter.php |
Filter returning kwargs consumed by the handler |
examples/multibot.php |
One Dispatcher driving several Bot instances |
examples/without_dispatcher.php |
Raw getUpdates loop bypassing the dispatcher |
examples/stars_invoice.php |
Telegram Stars sendInvoice + PreCheckoutQuery flow |
examples/inline_keyboard.php |
Inline keyboard builder + typed CallbackData + callback auto-answer |
examples/deep_linking.php |
Deep-link /start payload generation and handling |
examples/file_download.php |
Downloading user-sent documents/photos via Bot::download() |
Core concepts
Bot and Session
Bot is a thin facade that builds typed API method DTOs (SendMessage, SendPhoto, …) and dispatches them through the BaseSession. The default session is AmphpSession, which builds an amphp/http-client instance via HttpClientBuilder, encodes form bodies, and surfaces Telegram error responses as typed exceptions (TelegramRetryAfter, TelegramServerException, TelegramBadRequestException, TelegramConflictException, TelegramForbiddenException, TelegramNetworkException, …). Polling-loop backoff on RetryAfter lives in the dispatcher, not the session itself.
Every typed API method returns its result directly (e.g. sendMessage(...) returns Types\Message). For deferred dispatch use the underlying method DTO directly via emit():
Dispatcher and Router
Dispatcher is a Router that owns the polling loop. Routers cascade — a parent router runs its own filters and middlewares before delegating to included child routers ($dispatcher->includeRouter($shopRouter)).
Filters and the F-DSL
Filter instances are invokable; they may return false, true, or a kwargs array merged into the handler arguments. Built-in filters cover commands (Command), magic field tests via the F constant (use const Gruven\PhpBotGram\F;), CallbackData::filter(), state predicates (StateFilter; a bare State instance is also directly usable as a filter), and combinators (Filter::all(), Filter::any(), Filter::invertOf()).
FSM scenes
Scenes are explicit (no metaclass auto-discovery): subclass Scene, declare state methods with #[OnMessage] / #[OnCallbackQuery], and register through SceneRegistry. Scene history, state, and storage isolation are all driven by FsmContext.
The framework injects ScenesManager $scenes as a handler kwarg when SceneRegistry has been attached to the dispatcher. While a scene state is active, router subtrees that contain that scene state are tried before broad parent catch-all handlers so free-text scene replies are not consumed by root fallbacks.
Webhook
Webhook\Server\AmphpServer::run() boots an amphp/http-server listener that routes inbound Update payloads through SimpleRequestHandler (single bot) or TokenBasedRequestHandler (multi-tenant). For full control over an existing amphp/http-server instance, use Webhook\Setup::register() to splice the bot lifecycle into your own startup/shutdown hooks.
amphp/http-server is a suggested dependency — install it explicitly before using webhook mode:
Testing
Equivalent make test / make stan / make lint / make coverage-gate / make docs-api targets exist for contributors who prefer the Makefile interface.
Tests against live external services are env-gated to keep CI offline by default:
| Variable | What it unlocks |
|---|---|
PHPBOTGRAM_TEST_REDIS_DSN |
RedisStorage integration cases |
PHPBOTGRAM_TEST_MONGO_DSN |
MongoStorage integration cases |
Project structure
License
MIT. See LICENSE.
Upstream
Tracks aiogram 3.29.0. Behaviour divergences from upstream are documented inline at the call site (search for # Divergence: in the source) and in docs/superpowers/specs/.
All versions of phpbotgram with dependencies
php-64bit Version ^8.5
ext-mbstring Version *
ext-json Version *
ext-sodium Version *
amphp/amp Version ^3
amphp/byte-stream Version ^2
amphp/http-client Version ^5
amphp/sync Version ^2
revolt/event-loop Version ^1