PHPackages                             okaufmann/telegram-bot-dialogs - 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. okaufmann/telegram-bot-dialogs

AbandonedArchivedLibrary[API Development](/categories/api)

okaufmann/telegram-bot-dialogs
==============================

Telegram Bot API PHP SDK extension that allows to implement dialogs in bots

v1.0.1(5y ago)0492MITPHPPHP ^7.4

Since Jun 20Pushed 5y agoCompare

[ Source](https://github.com/okaufmann/telegram-bot-dialogs)[ Packagist](https://packagist.org/packages/okaufmann/telegram-bot-dialogs)[ RSS](/packages/okaufmann-telegram-bot-dialogs/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (5)Versions (6)Used By (0)

Dialogs for Telegram Bot SDK
============================

[](#dialogs-for-telegram-bot-sdk)

[![Latest Version](https://camo.githubusercontent.com/f03370de3b237c1b75466605a7c01085ba621a97988530f944a9ca606417e1c4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6f6b6175666d616e6e2f74656c656772616d2d626f742d6469616c6f67732e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/okaufmann/telegram-bot-dialogs/releases)[![Total Downloads](https://camo.githubusercontent.com/5309ce0011df73a48801761031d6a4e65c54680fcbcd9aef91c0f18b1af288b2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f6b6175666d616e6e2f74656c656772616d2d626f742d6469616c6f67732e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/okaufmann/telegram-bot-dialogs)

The extension for Telegram Bot API PHP SDK that allows to implement dialogs in bots

This library allows to make simple dialogs for your Telegram bots that based on the [Telegram Bot SDK](https://github.com/irazasyed/telegram-bot-sdk).

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

[](#installation)

You can easy install the package using Composer:

```
composer require okaufmann/telegram-bot-dialogs

```

You can publish the config-file with:

```
php artisan vendor:publish --provider="BotDialogs\DialogsServiceProvider" --tag="config"

```

Each dialog should be implemented as class that extends basic Dialog as you can see in example bellow:

```
use BotDialogs\Dialog;

class HelloDialog extends Dialog
{
    // Array with methods that contains logic of dialog steps.
    // The order in this array defines the sequence of execution.
    protected $steps = ['hello', 'fine', 'bye'];

    public function hello()
    {
        $this->telegram->sendMessage([
            'chat_id' => $this->getChat()->getId(),
            'text' => 'Hello! How are you?'
        ]);
    }

    public function bye()
    {
        $this->telegram->sendMessage([
            'chat_id' => $this->getChat()->getId(),
            'text' => 'Bye!'
        ]);
        $this->jump('hello');
    }

    public function fine()
    {
        $this->telegram->sendMessage([
            'chat_id' => $this->getChat()->getId(),
            'text' => 'I\'m OK :)'
        ]);
    }
}
```

For initiate new dialog you have to use Dialogs class instance to add new dialog implementation. And for execute the first and next steps you have to call Dialogs::proceed() method with update object as an argument. Also it is possible to use dialogs with Telegram commands and DI through type hinting.

```
use Telegram\Bot\Commands\Command;
use BotDialogs\Dialogs;
use App\Dialogs\HelloDialog;

class HelloCommand extends Command
{
    protected $name = 'hello';

    protected $description = 'Just say "Hello" and ask few questions';

    public function __construct(Dialogs $dialogs)
    {
        $this->dialogs = $dialogs;
    }

    public function handle($arguments)
    {
        $this->dialogs->add(new HelloDialog($this->update));
    }
}
```

And code in the webhook controller

```
use Telegram\Bot\Api;
use BotDialogs\Dialogs;

// ...

public function __construct(Api $telegram, Dialogs $dialogs)
{
  $this->telegram = $telegram;
  $this->dialogs = $dialogs;
}

// ...

$update = $this->telegram->commandsHandler(true);

if (!$this->dialogs->exists($update)) {
  // Do something if there are no existing dialogs
} else {
  // Call the next step of the dialog
  $this->dialogs->proceed($update);
}
```

For storing dialog information(also for the data that pushed by the Dialog::remember() method) using Redis.

Advanced definition of the dialog steps
---------------------------------------

[](#advanced-definition-of-the-dialog-steps)

You can define default text answers for your dialog steps. For this you have to define the step as an array with name and response fields.

```
class HelloDialog extends Dialog
{
    protected $steps = [
        [
            'name' => 'hello',
            'response' => 'Hello my friend!'
        ],
        'fine',
        'bye'
    ];

    // ...
}
```

In this case, if you don't need any logic inside the step handler - you can don't define it. Just put the response inside the step definition. It works good for welcome messages, messages with tips/advices and so on. If you want format response with markdown, just set `markdown` field to `true`.

Also, you can control dialog direction in step by defining `jump` and `end` fields. `jump` acts as `jump()` method - dialog jumps to particular step. `end` field, is set to `true`, ends dialog after current step.

Also, you can use `is_dich` (is it a dichotomous question) option of the step. If this option set to true, you can use `yes` and `no` fields of the Dialog instance to check user answer. For example:

```
class HelloDialog extends Dialog
{
    protected $steps = [
        [
            'name' => 'hello',
            'response' => 'Hello my friend! Are you OK?'
        ],
        [
            'name' => 'answer',
            'is_dich' => true
        ],
        'bye'
    ];

    public function answer()
    {
        if ($this->yes) {
            // Send message "I am fine, thank you!"
        } elseif ($this->no) {
            // Send message "No, I am got a sick :("
        }
    }
}
```

In the `config/dialogs.php` you can modify aliases for yes/no meanings.

Often in dichotomous question you only need to send response and jump to another step. In this case, you can define steps with responses and set their names as values of 'yes', 'no' or 'default' keys of dichotomous step. For example:

```
class HelloDialog extends Dialog
{
    protected $steps = [
        [
            'name' => 'hello',
            'response' => 'Hello my friend! Are you OK?'
        ],
        [
            'name' => 'answer',
            'is_dich' => true,
            'yes' => 'fine',
            'no' => 'sick',
            'default' => 'bye'
        ],
        [
            'name' => 'fine',
            'response' => 'I am fine, thank you!',
            'jump' => 'bye',
        ],
        [
            'name' => 'sick',
            'response' => 'No, I am got a sick :(',
        ],
        'bye'
    ];
}
```

Access control with in dialogs
------------------------------

[](#access-control-with-in-dialogs)

You can inherit AuthorizedDialog class and put Telegram usernames into $allowedUsers property. After that just for users in the list will be allowed to start the dialog.

Available methods of the *Dialog* class
---------------------------------------

[](#available-methods-of-the-dialog-class)

- `start()` - Start the dialog from the first step
- `proceed()` - Proceed the dialog to the next step
- `end()` - End dialog
- `jump($step)` - Jump to the particular step
- `remember($value)` - Remember some information for the next step usage (For now just a "short" memory works, just for one step)
- `isEnd()` - Check the end of the dialog

Available methods of the *Dialogs* class
----------------------------------------

[](#available-methods-of-the-dialogs-class)

- `add(Dialog $dialog)` - Add the new dialog
- `get(Telegram\Bot\Objects\Update $update)` - Returns the dialog object for the existing dialog
- `proceed(Telegram\Bot\Objects\Update $update)` - Run the next step handler for the existing dialog
- `exists(Telegram\Bot\Objects\Update $update)` - Check for existing dialog

Steps configuration in separate files
-------------------------------------

[](#steps-configuration-in-separate-files)

You can define dialog configuration in separate yaml or php files. To do this, set `scenarios` in dialogs configuration file, using dialog class name as key and path to config file as value, for example:

```
'scenarios' => [
        HelloDialog::class => base_path('config/dialogs/hello.yml')
],
```

Configuration from files in production environment stored in default cache instance. Because of this, you shall add `php artisan cache:clear` to your deployment script.

###  Health Score

30

—

LowBetter than 65% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 59.6% 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.

###  Release Activity

Cadence

Every ~492 days

Total

4

Last Release

2135d ago

Major Versions

0.2.0 → v1.0.02020-07-04

PHP version history (2 changes)0.1.0PHP &gt;=5.5.9

v1.0.0PHP ^7.4

### Community

Maintainers

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

---

Top Contributors

[![zarincheg](https://avatars.githubusercontent.com/u/1607662?v=4)](https://github.com/zarincheg "zarincheg (31 commits)")[![okaufmann](https://avatars.githubusercontent.com/u/4414498?v=4)](https://github.com/okaufmann "okaufmann (20 commits)")[![imanghafoori1](https://avatars.githubusercontent.com/u/6961695?v=4)](https://github.com/imanghafoori1 "imanghafoori1 (1 commits)")

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/okaufmann-telegram-bot-dialogs/health.svg)

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

###  Alternatives

[andreaselia/laravel-api-to-postman

Generate a Postman collection automatically from your Laravel API

1.0k586.2k3](/packages/andreaselia-laravel-api-to-postman)[mll-lab/laravel-graphiql

Easily integrate GraphiQL into your Laravel project

683.2M9](/packages/mll-lab-laravel-graphiql)[spatie/laravel-route-discovery

Auto register routes using PHP attributes

23645.0k2](/packages/spatie-laravel-route-discovery)[neuron-core/neuron-laravel

Official Neuron AI Laravel SDK.

10710.0k](/packages/neuron-core-neuron-laravel)[simplestats-io/laravel-client

Client for SimpleStats!

4515.5k](/packages/simplestats-io-laravel-client)[dragon-code/laravel-json-response

Automatically always return a response in JSON format

1118.6k1](/packages/dragon-code-laravel-json-response)

PHPackages © 2026

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