PHP code example of blacky0892 / laravel-max-bot

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

    

blacky0892 / laravel-max-bot example snippets


return [
    'token' => env('MAX_BOT_TOKEN'),

    'base_url' => env('MAX_BASE_URL', 'https://platform-api.max.ru'),

    'timeout' => (int) env('MAX_TIMEOUT', 30),

    'connect_timeout' => (int) env('MAX_CONNECT_TIMEOUT', 10),

    'retry_times' => (int) env('MAX_RETRY_TIMES', 0),

    'retry_sleep' => (int) env('MAX_RETRY_SLEEP', 200),

    'webhook_secret' => env('MAX_WEBHOOK_SECRET'),

    'route' => [
        'enabled' => (bool) env('MAX_ROUTE_ENABLED', true),
        'path' => env('MAX_ROUTE_PATH', '/max/webhook'),
        'middleware' => ['api'],
    ],

    'webhook' => [
        'handler' => env('MAX_WEBHOOK_HANDLER', 'App\\Services\\Max\\MaxWebhookHandler'),
    ],
];

use Blacky0892\Max\Facades\Max;

$me = Max::client()->getMe();

use Blacky0892\Max\Facades\Max;

Max::client()->sendMessageToUser(
    userId: 123456,
    text: 'Привет из Laravel-пакета!',
    format: 'markdown'
);

use Blacky0892\Max\Facades\Max;

Max::client()->sendMessageToChat(
    chatId: 987654,
    text: 'Сообщение в чат',
    format: 'html'
);

Max::client()->editMessage(
    messageId: 1001,
    text: 'Обновлённый текст',
    format: 'markdown'
);

Max::client()->deleteMessage(1001);

$messages = Max::client()->getMessages(
    chatId: 987654,
    count: 20
);

$upload = Max::client()->uploadFromPath(
    path: storage_path('app/public/file.pdf'),
    type: 'file'
);

$upload = Max::client()->uploadFromUploadedFile(
    file: $request->file('document'),
    type: 'file'
);

$upload = Max::client()->uploadFromPath(
    path: storage_path('app/public/video.mp4'),
    type: 'video'
);

Max::client()->sendVideoToChat(
    chatId: 987654,
    videoToken: $upload['token'],
    caption: 'Видео готово'
);

$subscriptions = Max::subscriptions()->all();

use Blacky0892\Max\Facades\Max;

Max::subscriptions()->create(
    url: 'https://example.com/max/webhook',
    updateTypes: ['message_created', 'message_callback'],
    secret: config('max.webhook_secret'),
    version: 1,
);

Max::subscriptions()->delete('https://example.com/max/webhook');

use Blacky0892\Max\Facades\Max;

Max::callbacks()->answer(
    callbackId: 'callback-id',
    notification: 'Действие выполнено'
);

$callbackId = Max::callbacks()->callbackIdFromUpdate($update);

$update->raw();
$update->type();
$update->timestamp();
$update->chatId();
$update->userId();
$update->text();
$update->callbackId();
$update->messageId();
$update->get('message.body.text');
$update->isMessageCreated();
$update->isMessageCallback();
bash
php artisan vendor:publish --tag=max-config
bash
php artisan config:clear
bash
php artisan make:max-webhook-handler
bash
php artisan make:max-webhook-handler Services/Bots/MainMaxHandler
bash
php artisan max:webhook-register
bash
php artisan max:webhook-register --dry-run