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

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

    

batyukovstudio / max-laravel-notification-channel example snippets


'max' => [
    'token' => env('MAX_BOT_TOKEN'),
    'base_uri' => env('MAX_API_BASE_URI', 'https://platform-api.max.ru'),
],

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('Оплата получена')
            ->toUser($notifiable->max_user_id)
            ->markdown()
            ->button('Открыть счёт', 'https://example.com/invoice/1');
    }
}

public function routeNotificationForMax(): int|array
{
    return $this->max_user_id;

    // или:
    // return ['chat_id' => $this->max_chat_id];
}

use NotificationChannels\Max\MaxClient;
use NotificationChannels\Max\MaxMessage;

$message = MaxMessage::create('Здравствуйте!')
    ->toUser(12345)
    ->html();

$response = app(MaxClient::class)->sendMessage($message);

MaxMessage::create('Проверка связи')
    ->toUser(12345)
    ->send();

use NotificationChannels\Max\MaxUpdates;

$updates = MaxUpdates::create()
    ->limit(100)
    ->timeout(30)
    ->types(['message_created', 'message_callback'])
    ->get();

use NotificationChannels\Max\MaxSubscription;

MaxSubscription::create('https://example.com/max/webhook')
    ->updateTypes(['message_created', 'bot_started'])
    ->secret('secret_12345')
    ->subscribe();

use NotificationChannels\Max\MaxCallbackAnswer;
use NotificationChannels\Max\MaxMessage;

MaxCallbackAnswer::create($callbackId)
    ->notification('Готово')
    ->message(
        MaxMessage::create('Сообщение обновлено')
            ->buttonWithCallback('Ещё раз', 'retry')
    )
    ->send();