coolify/app/Livewire/Notifications/Telegram.php

75 lines
2.2 KiB
PHP
Raw Normal View History

2023-09-06 14:31:38 +02:00
<?php
2023-12-07 19:06:32 +01:00
namespace App\Livewire\Notifications;
2023-09-06 14:31:38 +02:00
use App\Models\Team;
use App\Notifications\Test;
use Livewire\Component;
class Telegram extends Component
2023-09-06 14:31:38 +02:00
{
public Team $team;
2024-06-10 22:43:34 +02:00
2023-09-06 14:31:38 +02:00
protected $rules = [
'team.telegram_enabled' => 'nullable|boolean',
'team.telegram_token' => 'required|string',
'team.telegram_chat_id' => 'required|string',
'team.telegram_notifications_test' => 'nullable|boolean',
'team.telegram_notifications_deployments' => 'nullable|boolean',
'team.telegram_notifications_status_changes' => 'nullable|boolean',
'team.telegram_notifications_database_backups' => 'nullable|boolean',
'team.telegram_notifications_scheduled_tasks' => 'nullable|boolean',
2023-09-08 14:15:28 +02:00
'team.telegram_notifications_test_message_thread_id' => 'nullable|string',
'team.telegram_notifications_deployments_message_thread_id' => 'nullable|string',
'team.telegram_notifications_status_changes_message_thread_id' => 'nullable|string',
'team.telegram_notifications_database_backups_message_thread_id' => 'nullable|string',
'team.telegram_notifications_scheduled_tasks_thread_id' => 'nullable|string',
2023-09-06 14:31:38 +02:00
];
2024-06-10 22:43:34 +02:00
2023-09-06 14:31:38 +02:00
protected $validationAttributes = [
'team.telegram_token' => 'Token',
'team.telegram_chat_id' => 'Chat ID',
];
public function mount()
{
$this->team = auth()->user()->currentTeam();
}
2024-06-10 22:43:34 +02:00
2023-09-06 14:31:38 +02:00
public function instantSave()
{
try {
$this->submit();
2023-09-11 17:36:30 +02:00
} catch (\Throwable $e) {
2023-09-06 14:31:38 +02:00
ray($e->getMessage());
$this->team->telegram_enabled = false;
$this->validate();
}
}
public function submit()
{
$this->resetErrorBag();
$this->validate();
$this->saveModel();
}
public function saveModel()
{
$this->team->save();
2023-09-15 17:30:26 +02:00
refreshSession();
2023-12-07 19:06:32 +01:00
$this->dispatch('success', 'Settings saved.');
2023-09-06 14:31:38 +02:00
}
public function sendTestNotification()
{
2023-12-13 12:01:27 +01:00
$this->team?->notify(new Test());
2023-12-07 19:06:32 +01:00
$this->dispatch('success', 'Test notification sent.');
2023-09-06 14:31:38 +02:00
}
2024-06-10 22:43:34 +02:00
public function render()
{
return view('livewire.notifications.telegram');
}
2023-09-06 14:31:38 +02:00
}