1. Go to this page and download the library: Download afaztech/reactor library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
afaztech / reactor example snippets
namespace App\Handlers;
use Reactor\Attributes\Text;
use Reactor\Attributes\OnUpdate;
use Reactor\Attributes\Group;
#[Group('private')]
#[Text(name: '/start', isCommand: true, priority: 100)]
#[Text(name: '/restart', isCommand: true, priority: 90)]
#[OnUpdate('message')]
class StartHandler extends BaseHandler
{
protected function handle(array $params = []): void
{
$user = $this->extractUser($this->update);
if (!$user) {
return;
}
$lang = $this->getUserLanguage();
$text = $this->language->get('start_message', $lang);
$keyboard = (new \App\Keyboard($this->language))->mainMenu($lang);
$this->reply($text, $keyboard);
}
}
namespace App\Handlers;
use Reactor\Attributes\Text;
use Reactor\Attributes\OnUpdate;
use Reactor\Attributes\Group;
#[Group('private')]
#[Text(name: 'about', priority: 5)]
#[OnUpdate('message')]
class AboutHandler extends BaseHandler
{
protected function handle(array $params = []): void
{
$lang = $this->getUserLanguage();
$text = $this->language->get('about_text', $lang);
$keyboard = (new \App\Keyboard($this->language))->mainMenu($lang);
$this->reply($text, $keyboard);
}
}
namespace App\Handlers;
use Reactor\Attributes\Callback;
use Reactor\Attributes\OnUpdate;
use Reactor\Attributes\Group;
#[Group('private')]
#[Callback(data: 'cancel', priority: 10)]
#[OnUpdate('callback_query')]
class CancelHandler extends BaseHandler
{
protected function handle(array $params = []): void
{
$this->reply('Cancelled.');
}
}
namespace App\Migrations;
use Reactor\Database\Migrations\Migration;
use Reactor\Contracts\DatabaseManagerInterface;
class CreateUsersTable extends Migration
{
public function __construct(DatabaseManagerInterface $db)
{
parent::__construct($db);
}
public function up(): void
{
if (!$this->db->schema()->hasTable('users')) {
$this->db->schema()->create('users', function ($table) {
$table->increments('id');
$table->bigInteger('user_id')->unique();
$table->string('username', 64)->nullable();
$table->string('first_name', 64)->nullable();
$table->string('last_name', 64)->nullable();
$table->boolean('status')->default(true);
$table->string('step', 255)->nullable();
$table->json('temp')->nullable();
$table->string('language', 10)->default('en');
$table->timestamps();
});
}
}
public function down(): void
{
$this->db->schema()->dropIfExists('users');
}
}
namespace Reactor\Seeders;
use Reactor\Database\Seeders\Seeder;
class DatabaseSeeder extends Seeder
{
public function run(): void
{
// Insert initial data.
}
}