2024-12-11 14:54:11 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace App\Notifications\Dto;
|
|
|
|
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
|
|
|
|
|
|
class PushoverMessage
|
|
|
|
|
|
{
|
|
|
|
|
|
public function __construct(
|
|
|
|
|
|
public string $title,
|
|
|
|
|
|
public string $message,
|
|
|
|
|
|
public array $buttons = [],
|
|
|
|
|
|
public string $level = 'info',
|
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
|
|
public function getLevelIcon(): string
|
|
|
|
|
|
{
|
|
|
|
|
|
return match ($this->level) {
|
|
|
|
|
|
'info' => 'ℹ️',
|
2024-12-11 17:37:12 +00:00
|
|
|
|
'error' => '❌',
|
|
|
|
|
|
'success' => '✅ ',
|
2024-12-11 14:54:11 +00:00
|
|
|
|
'warning' => '⚠️',
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function toPayload(string $token, string $user): array
|
|
|
|
|
|
{
|
|
|
|
|
|
$levelIcon = $this->getLevelIcon();
|
|
|
|
|
|
$payload = [
|
|
|
|
|
|
'token' => $token,
|
|
|
|
|
|
'user' => $user,
|
|
|
|
|
|
'title' => "{$levelIcon} {$this->title}",
|
|
|
|
|
|
'message' => $this->message,
|
|
|
|
|
|
'html' => 1,
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($this->buttons as $button) {
|
|
|
|
|
|
$buttonUrl = data_get($button, 'url');
|
|
|
|
|
|
$text = data_get($button, 'text', 'Click here');
|
|
|
|
|
|
if ($buttonUrl && str_contains($buttonUrl, 'http://localhost')) {
|
|
|
|
|
|
$buttonUrl = str_replace('http://localhost', config('app.url'), $buttonUrl);
|
|
|
|
|
|
}
|
2025-02-27 10:29:04 +00:00
|
|
|
|
$payload['message'] .= " <a href='".$buttonUrl."'>".$text.'</a>';
|
2024-12-11 14:54:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Log::info('Pushover message', $payload);
|
|
|
|
|
|
|
|
|
|
|
|
return $payload;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|