PHPackages                             morfeditorial/telegram-bot-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. morfeditorial/telegram-bot-bundle

ActiveSymfony-bundle[API Development](/categories/api)

morfeditorial/telegram-bot-bundle
=================================

A universal Symfony Bundle for building Telegram bots with screens and commands routing.

00PHPCI passing

Since Jul 2Pushed todayCompare

[ Source](https://github.com/ChernegaSergiy/telegram-bot-bundle)[ Packagist](https://packagist.org/packages/morfeditorial/telegram-bot-bundle)[ RSS](/packages/morfeditorial-telegram-bot-bundle/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-direct.svg)](https://stand-with-ukraine.pp.ua)

Telegram Bot Bundle
===================

[](#telegram-bot-bundle)

[![Latest Stable Version](https://camo.githubusercontent.com/d22897932ee2fb6ce358610da35d1133bc91b7acab2405de6958c46a539387d0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6f7266656469746f7269616c2f74656c656772616d2d626f742d62756e646c652e7376673f6c6162656c3d5061636b6167697374266c6f676f3d7061636b6167697374)](https://packagist.org/packages/morfeditorial/telegram-bot-bundle)[![Total Downloads](https://camo.githubusercontent.com/e5d54c115b52fe42d4abd0df599247a1d3f5ae3a02c69aedb3dc1098f4cd70da/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6f7266656469746f7269616c2f74656c656772616d2d626f742d62756e646c652e7376673f6c6162656c3d446f776e6c6f616473266c6f676f3d7061636b6167697374)](https://packagist.org/packages/morfeditorial/telegram-bot-bundle)[![License](https://camo.githubusercontent.com/2f959f435598a74aed17e8e7b53fab8d0395e2031f8531424619fb99855b8a77/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d6f7266656469746f7269616c2f74656c656772616d2d626f742d62756e646c652e7376673f6c6162656c3d4c6963656e6365266c6f676f3d6f70656e2d736f757263652d696e6974696174697665)](https://packagist.org/packages/morfeditorial/telegram-bot-bundle)

A powerful, object-oriented, and highly extensible Telegram Bot integration bundle for Symfony applications. This bundle provides a robust architecture for building complex Telegram bots using state machines, modular screens, and dependency injection, moving away from monolithic switch-case handlers to clean, maintainable classes.

Features
--------

[](#features)

- **Object-Oriented Screen Architecture**: Build bots using individual Screen classes that handle specific states and actions.
- **State Management**: Flexible architecture allowing you to track user progression through complex multi-step flows (e.g., forms, wizards) using your own persistence layer.
- **Standardized Payload Routing**: Automatically route `callback_query` data using a structured payload format (`domain:action:args`).
- **Seamless Symfony Integration**: Full support for Symfony Dependency Injection, autowiring, and event dispatching.
- **Support for Long Polling &amp; Webhooks**: Flexible transport layer adapting to your deployment environment.
- **Asynchronous Ready**: Built with non-blocking architectures in mind (compatible with AsyncHttp and ReactPHP).

Installation
------------

[](#installation)

To install the Telegram Bot Bundle, run the following command in your terminal:

```
composer require morfeditorial/telegram-bot-bundle
```

Configuration
-------------

[](#configuration)

Add your Telegram Bot credentials to your `.env` file:

```
TELEGRAM_BOT_TOKEN=your_bot_token_here
TELEGRAM_BOT_USERNAME=your_bot_username
```

If the bundle is not automatically registered, add it to `config/bundles.php`:

```
return [
    // ...
    Morfeditorial\TelegramBotBundle\TelegramBotBundle::class => ['all' => true],
];
```

Core Concepts
-------------

[](#core-concepts)

### 1. The Screen System (`AbstractScreen`)

[](#1-the-screen-system-abstractscreen)

Instead of one massive loop handling all updates, this bundle uses "Screens". A Screen is a dedicated class that answers two questions:

- **Can I handle this update?** — Implemented via `supports()`
- **How do I handle this update?** — Implemented via `handle()`

Screens are automatically discovered and registered by the bundle.

### 2. Payload Routing

[](#2-payload-routing)

The bundle encourages using a standard payload structure for inline keyboards: `domain:action:args`. For example, `feedback:delete:42`. This allows your screens to precisely intercept events meant for them.

### 3. State Management

[](#3-state-management)

When asking a user for input (e.g., "Please type your feedback"), you can track their state in your application's database or cache. Your screen can then intercept their next text message based on this state.

Usage
-----

[](#usage)

### Creating a Screen

[](#creating-a-screen)

Create a new class extending `AbstractScreen` (or your project's BaseScreen).

```
namespace App\Screen\Feedback;

use Morfeditorial\TelegramBotBundle\Screen\AbstractScreen;

class FeedbackViewScreen extends AbstractScreen
{
    public function supports(array $update): bool
    {
        $data = $update['callback_query']['data'] ?? '';

        // This screen intercepts any payload starting with 'feedback:view:'
        return str_starts_with($data, 'feedback:view:');
    }

    public function handle(array $update): void
    {
        $chatId = $update['callback_query']['message']['chat']['id'] ?? $update['message']['chat']['id'] ?? 0;
        $data = $update['callback_query']['data'] ?? '';

        // Extract arguments
        $parts = explode(':', $data);
        $feedbackId = $parts[2] ?? null;

        // Use the injected client to send a message
        $this->client->sendMessage([
            'chat_id' => $chatId,
            'text' => "Viewing feedback #" . $feedbackId,
        ]);
    }
}
```

### Handling Multi-Step Forms (State Machine)

[](#handling-multi-step-forms-state-machine)

To handle user input sequentially, you can inject your own state tracking service (e.g., a Doctrine Repository or Redis Cache):

```
namespace App\Screen\Feedback;

use Morfeditorial\TelegramBotBundle\Screen\AbstractScreen;
use App\Service\MyStateService; // Example custom service

class FeedbackCreateScreen extends AbstractScreen
{
    private MyStateService $stateService;

    public function __construct(MyStateService $stateService)
    {
        $this->stateService = $stateService;
    }

    public function supports(array $update): bool
    {
        $userId = $update['message']['from']['id'] ?? 0;

        return ($update['callback_query']['data'] ?? '') === 'feedback:create' ||
               $this->stateService->getState($userId) === 'awaiting_feedback_text';
    }

    public function handle(array $update): void
    {
        $chatId = $update['message']['chat']['id'] ?? $update['callback_query']['message']['chat']['id'] ?? 0;
        $userId = $update['message']['from']['id'] ?? $update['callback_query']['from']['id'] ?? 0;

        if (isset($update['callback_query'])) {
            // Step 1: Start creation
            $this->stateService->setState($userId, 'awaiting_feedback_text');
            $this->client->sendMessage(['chat_id' => $chatId, 'text' => "Please type your feedback:"]);
            return;
        }

        // Step 2: Receive input
        if ($this->stateService->getState($userId) === 'awaiting_feedback_text') {
            $feedbackText = $update['message']['text'];
            // Save to DB...

            $this->stateService->clearState($userId);
            $this->client->sendMessage(['chat_id' => $chatId, 'text' => "Thank you for your feedback!"]);
        }
    }
}
```

Contributing
------------

[](#contributing)

Contributions are welcome and appreciated! Here's how you can contribute:

1. Fork the project
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

Please make sure to update tests as appropriate and adhere to the existing coding style.

License
-------

[](#license)

This library is licensed under the CSSM Unlimited License v2.0 (CSSM-ULv2). See the [LICENSE](LICENSE) file for details.

###  Health Score

20

↑

LowBetter than 13% of packages

Maintenance65

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/e2471bdadcf4a5ea969fe763a72d03fb46525b59a7e4cedc3ed4d855029e7785?d=identicon)[ChernegaSergiy](/maintainers/ChernegaSergiy)

---

Top Contributors

[![ChernegaSergiy](https://avatars.githubusercontent.com/u/60980650?v=4)](https://github.com/ChernegaSergiy "ChernegaSergiy (50 commits)")

---

Tags

async-phpbot-frameworkphp8state-machinesymfony-bundletelegram-bottelegram-bot-api

### Embed Badge

![Health badge](/badges/morfeditorial-telegram-bot-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/morfeditorial-telegram-bot-bundle/health.svg)](https://phpackages.com/packages/morfeditorial-telegram-bot-bundle)
```

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35916.4M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24016.2M19](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172445.0k12](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

93459.5k6](/packages/botman-driver-telegram)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
