PHP code example of letoceiling-coder / max

1. Go to this page and download the library: Download letoceiling-coder/max 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/ */

    

letoceiling-coder / max example snippets


use LetoceilingCoder\Max\Max;

Max::send(123456789, 'Привет!');

Max::bot()->sendMessage(123456789, '**Жирный** текст', ['format' => 'markdown']);

Max::sendToUser(42, 'Сообщение пользователю напрямую');

use LetoceilingCoder\Max\Max;

$kb = Max::keyboard()
    ->row()
        ->callback('Кнопка 1', 'btn1')
        ->callback('Кнопка 2', 'btn2')
    ->row()
        ->link('Открыть сайт', 'https://example.com')
        ->openApp('Открыть Mini App', 'https://app.example.com')
    ->row()
        ->clipboard('Скопировать промокод', 'PROMO2025')
    ->get();

Max::bot()->sendMessage($chatId, 'Выберите:', ['attachments' => [$kb]]);

use LetoceilingCoder\Max\Max;

$initData = $request->header('X-Max-Init-Data');

if (Max::validateMiniApp($initData)) {
    $user = Max::getMiniAppUser($initData);
    $userId = $user['id'];
}

// routes/api.php
Route::middleware(['max.auth'])->group(function () {
    Route::post('/api/me', function (\Illuminate\Http\Request $r) {
        return $r->input('max_user');
    });
});

use LetoceilingCoder\Max\Max;

Max::bot()->subscribe(
    url: 'https://your-domain.com/api/max/webhook',
    updateTypes: ['message_created', 'message_callback', 'bot_started'],
    secret: env('MAX_WEBHOOK_SECRET'),
);

use LetoceilingCoder\Max\Types\Update;

public function handle(\Illuminate\Http\Request $request)
{
    $update = Update::fromArray($request->all());

    if ($update->isMessageCreated() && $update->message?->hasText()) {
        // ...
    }
    if ($update->isCallback() && $update->callback) {
        \LetoceilingCoder\Max\Max::bot()->answerCallback(
            $update->callback->callbackId,
            ['notification' => 'Готово']
        );
    }

    return response()->json(['success' => true]);
}

use LetoceilingCoder\Max\Max;

$result = Max::bot()->uploadImage('/path/to/photo.jpg');

Max::bot()->sendMessage($chatId, 'Фото', [
    'attachments' => [[
        'type' => 'image',
        'payload' => ['token' => $result['token']],
    ]],
]);

use LetoceilingCoder\Max\Max;

$url = Max::deeplink('SupportBot', 'ref_summer2025');
// https://max.ru/SupportBot?start=ref_summer2025

use LetoceilingCoder\Max\Exceptions\MaxException;

try {
    Max::send($chatId, 'Hello');
} catch (MaxException $e) {
    report($e);
    if ($e->isRateLimited()) {
        // 429
    }
    logger()->error('Max API', [
        'status'  => $e->getStatusCode(),
        'code'    => $e->getErrorCode(),
        'message' => $e->getMessage(),
        'body'    => $e->getResponse(),
    ]);
}
bash
php artisan vendor:publish --tag=max-config
bash
php artisan max:test
php artisan max:set-webhook https://example.com/webhook --types=message_created,bot_started --secret=...
php artisan max:webhook-info
php artisan max:delete-webhook