1. Go to this page and download the library: Download govorun/framework 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/ */
use Govorun\Routing\Controller;
class StartController extends Controller
{
public function handle(): void
{
$name = $this->message->user->firstName;
$this->reply("Привет, {$name}!");
}
}
use Govorun\Messaging\Message;
$msg = Message::make('Текст')
->keyboard($keyboard)
->parseMode('HTML');
use Govorun\State\Flow;
use Govorun\State\Step;
use Govorun\Messaging\Keyboard;
use Govorun\Messaging\Button;
use Govorun\Messaging\IncomingMessage;
class OrderFlow extends Flow
{
protected array $steps = ['product', 'quantity', 'confirm'];
protected array $interruptCommands = ['/start', '/cancel'];
protected bool $interruptOnEvent = true;
public function productStep(Step $step): void
{
$step->ask('Какой товар вас интересует?');
$step->receive(function (IncomingMessage $msg) {
if ($this->validator($msg->text)->;
$qty = $this->state->get('quantity');
$step->ask(
"Заказ: {$product} x {$qty}. Подтвердить?",
Keyboard::make()->buttons([[
Button::make('Да')->action('yes'),
Button::make('Нет')->action('no'),
]]),
);
$step->receive(function (IncomingMessage $msg) {
if ($msg->action === 'yes') {
$this->reply('Заказ принят!');
}
$this->nextStep(); // обязателен — завершает flow и чистит state
});
}
public function onComplete(): void {}
public function onCancel(): void { $this->reply('Заказ отменён.'); }
}
$step->ask(
string|OutgoingMessage $message,
Closure|Keyboard|null $keyboard = null, // прямой Keyboard или Closure-билдер
);
$step->receive(Closure $callback); // function (IncomingMessage $msg): void
interface StateStorage
{
public function get(string $chatId, string $driver): ?array;
public function set(string $chatId, string $driver, array $data): void;
public function delete(string $chatId, string $driver): void;
}
use Govorun\Http\ApiClient;
class PaymentClient extends ApiClient
{
protected int $timeout = 10;
protected int $retries = 2;
public function baseUrl(): string
{
return 'https://api.payment.com/v1';
}
public function headers(): array
{
return ['Authorization' => 'Bearer ' . env('PAYMENT_KEY')];
}
}
use Govorun\Support\Validator;
$error = Validator::make($msg->text)
-> — null если ок
if ($error !== null) {
$this->reply($error);
return;
}
if ($this->validator($msg->text)->
use Govorun\Routing\Middleware;
use Govorun\Messaging\IncomingMessage;
class LogMiddleware implements Middleware
{
public function handle(IncomingMessage $message, \Closure $next): void
{
logger()->info("Message from {$message->user->id}: {$message->text}");
$next($message);
}
}
use Govorun\Foundation\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function register(): void { /* привязки контейнера */ }
public function boot(): void { /* после регистрации всех провайдеров */ }
}