<?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],
],
]);
}
}
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();