PHP code example of alexwebprog / laravel-notification-channel-max

1. Go to this page and download the library: Download alexwebprog/laravel-notification-channel-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/ */

    

alexwebprog / laravel-notification-channel-max example snippets


class User extends Authenticatable
{
    use Notifiable;

    /**
     * Куда отправлять уведомления MAX.
     */
    public function routeNotificationForMax(): int|array
    {
        // Вариант A: отправка пользователю по user_id
        return $this->max_user_id;

        // Вариант B: отправка в чат
        // return ['chat_id' => $this->max_chat_id];
    }
}

use Illuminate\Notifications\Notification;
use NotificationChannels\Max\MaxChannel;
use NotificationChannels\Max\MaxMessage;

class InvoicePaid extends Notification
{
    public function via($notifiable): array
    {
        return [MaxChannel::class];
    }

    public function toMax($notifiable): MaxMessage
    {
        return MaxMessage::create("Оплата получена: {$this->invoice->amount} ₽")
            ->markdown()
            ->inlineKeyboard([
                [
                    ['type' => 'link', 'text' => 'Открыть счёт', 'url' => $this->invoice->url],
                ],
            ]);
    }
}

$user->notify(new InvoicePaid($invoice));

use NotificationChannels\Max\MaxMessage;

MaxMessage::create('Здравствуйте! Нажмите кнопку ниже.')
    ->to(123456)
    ->inlineKeyboard([
        [
            ['type' => 'request_contact', 'text' => 'Отправить мой номер телефона'],
        ],
    ])
    ->send();

use NotificationChannels\Max\MaxApi;
use NotificationChannels\Max\MaxMessage;

public function sendWelcome(MaxApi $api): void
{
    $message = MaxMessage::create('Добро пожаловать!')
        ->to($user->max_user_id);

    $response = $api->sendMessage($message);
}

app(MaxApi::class)->sendMessage($message);

// Изображение с текстом и кнопкой
MaxMessage::create('Расчёт стоимости ремонта')
    ->toChat(-123456)
    ->photo(storage_path('app/images/banner.jpg'))
    ->inlineKeyboard([
        [
            ['type' => 'link', 'text' => 'Рассчитать стоимость', 'url' => 'https://example.com/calc'],
        ],
    ])
    ->send();

// Отправка документа пользователю
MaxMessage::create('Ваш отчёт готов')
    ->to($user->max_user_id)
    ->file(storage_path('app/reports/report.pdf'))
    ->send();

// Видео
MaxMessage::create('Видеоинструкция')
    ->toChat($chatId)
    ->video(storage_path('app/videos/tutorial.mp4'))
    ->send();

MaxMessage::create('Выберите действие:')
    ->inlineKeyboard([
        // Первый ряд
        [
            ['type' => 'callback', 'text' => 'Подтвердить', 'payload' => 'confirm'],
            ['type' => 'callback', 'text' => 'Отмена', 'payload' => 'cancel'],
        ],
        // Второй ряд
        [
            ['type' => 'link', 'text' => 'Подробнее', 'url' => 'https://example.com'],
        ],
    ]);

MaxMessage::create('<b>Внимание!</b> Обновление системы в 03:00')
    ->html()
    ->silent();
bash
php artisan vendor:publish --tag=max-notification-config