Skip to content

Upgrading from 3.x to 4.x

Updating dependencies

You should update the following dependencies in your application's composer.json file:

  • westacks/telebot to ^4.0

Updating configuration

Some configuration values were changed or deprecated. See the reference table:

Old keyNew keyDescription
storagestorageJsonStorage is deprecated. Use FileStorage instead.
handlerskernelUsing bot Kernel is now a preferred way to manage update handlers, instead of array. Config key was renamed for convenience.
exceptions---Deprecated. Exceptions always thrown by default now.
async---Deprecated. Methods always called synchronously now.

Creating BotManager

Now BotManager constructor requires 2 parameters instead array of parameter

php
$bot = new BotManager([
    'default' => 'primary',
    'bots' => [
        'primary' => new TeleBot('YOUR_BOT1_TOKEN'),
        'secondary' => [
            'token' => 'YOUR_BOT2_TOKEN',
            'name' => 'MyBot2'
        ]
    ]
]);

Namespace changes

Following classes/traits/interfaces changed namespaces:

Old namespaceNew namespace
WeStacks\TeleBot\Handlers\UpdateHandlerWeStacks\TeleBot\Foundation\UpdateHandler
WeStacks\TeleBot\Handlers\RequestInputHandlerWeStacks\TeleBot\Foundation\RequestInputHandler
WeStacks\TeleBot\Handlers\CommandHandlerWeStacks\TeleBot\Foundation\CommandHandler
WeStacks\TeleBot\Handlers\CallbackHandlerWeStacks\TeleBot\Foundation\CallbackHandler
WeStacks\TeleBot\Contracts\StorageContractWeStacks\TeleBot\Foundation\StorageContract

TeleBot and BotManager methods changes

TeleBot

Old methodNew methodDescription
handleUpdatehandleRenamed
addHandlerhandlerRenamed
clearHandlerspurgeRenamed
config---Deprecated. Now you may access bot configuration as read-only property
async---Deprecated. Use new method syntax instead
exceptions---Deprecated. Use new method syntax instead

BotManager

Old methodNew methodDescription
deleteremoveRenamed

UpdateHandler::trigger is strictly typed

php
<?php

namespace App;

use WeStacks\TeleBot\Handlers\UpdateHandler;

class YourUpdateHandler extends UpdateHandler
{
    public function trigger(): bool
    {
        //
    }

    public function handle()
    {
        //
    }
}

RequestInputHandler methods changes

Old methodNew methodDescription
requestInputrequest---
acceptInputaccept---

CommandHandler aliases and description are now methods

php
<?php

namespace App;

use WeStacks\TeleBot\Handlers\CommandHandler;

class YourUpdateHandler extends CommandHandler
{
    protected static function aliases(): array
    {
        return ['/start'];
    }

    protected static function description(?string $locale = null): string
    {
        return trans('Start command', locale: $locale);
    }

    public function handle()
    {
        return $this->sendMessage([
            'text' => 'Hello, World!'
        ]);
    }
}