mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-01 05:56:16 +00:00
WIP notifications and other refactors (#88)
* WIP notifications and other refactors - refactor notification channels - send notifications on events related to the servers and sites - delete server log files on server deletion - add telegram notification channel - add new icons - cache configs and icons on installation and updates - new navbar for dark mode and settings * discord channel * build assets * pint
This commit is contained in:
@ -2,21 +2,34 @@
|
||||
|
||||
namespace App\NotificationChannels;
|
||||
|
||||
use App\Contracts\Notification;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class Slack extends AbstractProvider
|
||||
class Slack extends AbstractNotificationChannel
|
||||
{
|
||||
public function validationRules(): array
|
||||
public function channel(): string
|
||||
{
|
||||
return 'slack';
|
||||
}
|
||||
|
||||
public function createRules(array $input): array
|
||||
{
|
||||
return [
|
||||
'webhook_url' => 'required|url',
|
||||
];
|
||||
}
|
||||
|
||||
public function data(array $input): array
|
||||
public function createData(array $input): array
|
||||
{
|
||||
return [
|
||||
'webhook_url' => $input['webhook_url'],
|
||||
'webhook_url' => $input['webhook_url'] ?? '',
|
||||
];
|
||||
}
|
||||
|
||||
public function data(): array
|
||||
{
|
||||
return [
|
||||
'webhook_url' => $this->notificationChannel->data['webhook_url'] ?? '',
|
||||
];
|
||||
}
|
||||
|
||||
@ -24,35 +37,37 @@ public function connect(): bool
|
||||
{
|
||||
$connect = $this->checkConnection(
|
||||
__('Congratulations! 🎉'),
|
||||
__("You've connected your Slack to Vito")."\n".
|
||||
__("You've connected your Slack to :app", ['app' => config('app.name')])."\n".
|
||||
__('Manage your notification channels')."\n".
|
||||
route('notification-channels')
|
||||
);
|
||||
|
||||
if (! $connect) {
|
||||
$this->notificationChannel->delete();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->notificationChannel->connected = true;
|
||||
$this->notificationChannel->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function sendMessage(string $subject, string $text): void
|
||||
{
|
||||
dispatch(function () use ($subject, $text) {
|
||||
$data = $this->notificationChannel->data;
|
||||
Http::post($data['webhook_url'], [
|
||||
'text' => '*'.$subject.'*'."\n".$text,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
private function checkConnection(string $subject, string $text): bool
|
||||
{
|
||||
$data = $this->notificationChannel->data;
|
||||
$connect = Http::post($data['webhook_url'], [
|
||||
$connect = Http::post($this->data()['webhook_url'], [
|
||||
'text' => '*'.$subject.'*'."\n".$text,
|
||||
]);
|
||||
|
||||
return $connect->ok();
|
||||
}
|
||||
|
||||
public function send(object $notifiable, Notification $notification): void
|
||||
{
|
||||
$data = $this->notificationChannel->data;
|
||||
Http::post($data['webhook_url'], [
|
||||
'text' => $notification->toSlack($notifiable),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user