forked from coollabsio/coolify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
489 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldBeEncrypted; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
use Illuminate\Support\Facades\Http; | ||
use Illuminate\Support\Str; | ||
|
||
class SendMessageToPushoverJob implements ShouldQueue, ShouldBeEncrypted | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
/** | ||
* The number of times the job may be attempted. | ||
* | ||
* @var int | ||
*/ | ||
public $tries = 5; | ||
|
||
/** | ||
* The maximum number of unhandled exceptions to allow before failing. | ||
*/ | ||
public int $maxExceptions = 3; | ||
|
||
public function __construct( | ||
public string $text, | ||
public array $buttons, | ||
public string $token, | ||
public string $user, | ||
) { | ||
} | ||
|
||
/** | ||
* Execute the job. | ||
*/ | ||
public function handle(): void | ||
{ | ||
$message = "<p>".$this->text."</p>"; | ||
|
||
if (!empty($this->buttons)) { | ||
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); | ||
} | ||
$message .= " <a href='".$buttonUrl."'>".$text."</a>"; | ||
} | ||
} | ||
|
||
$payload = [ | ||
'token' => $this->token, | ||
'user' => $this->user, | ||
'message' => $message, | ||
'html' => 1 | ||
]; | ||
ray($payload); | ||
Http::post("https://api.pushover.net/1/messages.json", $payload); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Notifications; | ||
|
||
use App\Models\Team; | ||
use App\Notifications\Test; | ||
use Livewire\Component; | ||
use Illuminate\Support\Facades\Log; | ||
|
||
class Pushover extends Component | ||
{ | ||
|
||
public Team $team; | ||
protected $rules = [ | ||
'team.pushover_enabled' => 'nullable|boolean', | ||
'team.pushover_token' => 'required|string', | ||
'team.pushover_user' => 'required|string', | ||
'team.pushover_notifications_test' => 'nullable|boolean', | ||
'team.pushover_notifications_deployments' => 'nullable|boolean', | ||
'team.pushover_notifications_status_changes' => 'nullable|boolean', | ||
'team.pushover_notifications_database_backups' => 'nullable|boolean', | ||
]; | ||
protected $validationAttributes = [ | ||
'team.pushover_token' => 'Token', | ||
'team.pushover_user' => 'User Key', | ||
]; | ||
|
||
public function mount() | ||
{ | ||
$this->team = auth()->user()->currentTeam(); | ||
} | ||
public function instantSave() | ||
{ | ||
try { | ||
$this->submit(); | ||
} catch (\Throwable $e) { | ||
ray($e->getMessage()); | ||
$this->team->pushover_enabled = false; | ||
$this->validate(); | ||
} | ||
} | ||
|
||
public function submit() | ||
{ | ||
$this->resetErrorBag(); | ||
$this->validate(); | ||
$this->saveModel(); | ||
} | ||
|
||
public function saveModel() | ||
{ | ||
$this->team->save(); | ||
refreshSession(); | ||
$this->dispatch('success', 'Settings saved.'); | ||
} | ||
|
||
public function sendTestNotification() | ||
{ | ||
$this->team?->notify(new Test()); | ||
$this->dispatch('success', 'Test notification sent.'); | ||
} | ||
public function render() | ||
{ | ||
return view('livewire.notifications.pushover'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace App\Notifications\Channels; | ||
|
||
use App\Jobs\SendMessageToPushoverJob; | ||
use Illuminate\Notifications\Notification; | ||
|
||
class PushoverChannel | ||
{ | ||
public function send(SendsDiscord $notifiable, Notification $notification): void | ||
{ | ||
$data = $notification->toPushover($notifiable); | ||
$pushoverData = $notifiable->routeNotificationForPushover(); | ||
$message = data_get($data, 'message'); | ||
$buttons = data_get($data, 'buttons', []); | ||
$pushoverToken = data_get($pushoverData, 'token'); | ||
$pushoverUser = data_get($pushoverData, 'user'); | ||
|
||
if (!$pushoverToken || !$pushoverUser || !$message) { | ||
return; | ||
} | ||
dispatch(new SendMessageToPushoverJob($message, $buttons, $pushoverToken, $pushoverUser)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace App\Notifications\Channels; | ||
|
||
interface SendsPushover | ||
{ | ||
public function routeNotificationForPushover(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.