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 key | New key | Description |
---|---|---|
storage | storage | JsonStorage is deprecated. Use FileStorage instead. |
handlers | kernel | Using 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 namespace | New namespace |
---|---|
WeStacks\TeleBot\Handlers\UpdateHandler | WeStacks\TeleBot\Foundation\UpdateHandler |
WeStacks\TeleBot\Handlers\RequestInputHandler | WeStacks\TeleBot\Foundation\RequestInputHandler |
WeStacks\TeleBot\Handlers\CommandHandler | WeStacks\TeleBot\Foundation\CommandHandler |
WeStacks\TeleBot\Handlers\CallbackHandler | WeStacks\TeleBot\Foundation\CallbackHandler |
WeStacks\TeleBot\Contracts\StorageContract | WeStacks\TeleBot\Foundation\StorageContract |
TeleBot
and BotManager
methods changes
TeleBot
Old method | New method | Description |
---|---|---|
handleUpdate | handle | Renamed |
addHandler | handler | Renamed |
clearHandlers | purge | Renamed |
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 method | New method | Description |
---|---|---|
delete | remove | Renamed |
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 method | New method | Description |
---|---|---|
requestInput | request | --- |
acceptInput | accept | --- |
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!'
]);
}
}