feat(notifications): add discord ping functionality and settings
This commit is contained in:
@@ -56,6 +56,9 @@ class Discord extends Component
|
|||||||
#[Validate(['boolean'])]
|
#[Validate(['boolean'])]
|
||||||
public bool $serverUnreachableDiscordNotifications = true;
|
public bool $serverUnreachableDiscordNotifications = true;
|
||||||
|
|
||||||
|
#[Validate(['boolean'])]
|
||||||
|
public bool $discordPingEnabled = true;
|
||||||
|
|
||||||
public function mount()
|
public function mount()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@@ -87,6 +90,8 @@ class Discord extends Component
|
|||||||
$this->settings->server_reachable_discord_notifications = $this->serverReachableDiscordNotifications;
|
$this->settings->server_reachable_discord_notifications = $this->serverReachableDiscordNotifications;
|
||||||
$this->settings->server_unreachable_discord_notifications = $this->serverUnreachableDiscordNotifications;
|
$this->settings->server_unreachable_discord_notifications = $this->serverUnreachableDiscordNotifications;
|
||||||
|
|
||||||
|
$this->settings->discord_ping_enabled = $this->discordPingEnabled;
|
||||||
|
|
||||||
$this->settings->save();
|
$this->settings->save();
|
||||||
refreshSession();
|
refreshSession();
|
||||||
} else {
|
} else {
|
||||||
@@ -105,12 +110,30 @@ class Discord extends Component
|
|||||||
$this->serverDiskUsageDiscordNotifications = $this->settings->server_disk_usage_discord_notifications;
|
$this->serverDiskUsageDiscordNotifications = $this->settings->server_disk_usage_discord_notifications;
|
||||||
$this->serverReachableDiscordNotifications = $this->settings->server_reachable_discord_notifications;
|
$this->serverReachableDiscordNotifications = $this->settings->server_reachable_discord_notifications;
|
||||||
$this->serverUnreachableDiscordNotifications = $this->settings->server_unreachable_discord_notifications;
|
$this->serverUnreachableDiscordNotifications = $this->settings->server_unreachable_discord_notifications;
|
||||||
|
|
||||||
|
$this->discordPingEnabled = $this->settings->discord_ping_enabled;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function instantSaveDiscordPingEnabled()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$original = $this->discordPingEnabled;
|
||||||
|
$this->validate([
|
||||||
|
'discordPingEnabled' => 'required',
|
||||||
|
]);
|
||||||
|
$this->saveModel();
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
$this->discordPingEnabled = $original;
|
||||||
|
|
||||||
|
return handleError($e, $this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function instantSaveDiscordEnabled()
|
public function instantSaveDiscordEnabled()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
$original = $this->discordEnabled;
|
||||||
$this->validate([
|
$this->validate([
|
||||||
'discordWebhookUrl' => 'required',
|
'discordWebhookUrl' => 'required',
|
||||||
], [
|
], [
|
||||||
@@ -118,7 +141,7 @@ class Discord extends Component
|
|||||||
]);
|
]);
|
||||||
$this->saveModel();
|
$this->saveModel();
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
$this->discordEnabled = false;
|
$this->discordEnabled = $original;
|
||||||
|
|
||||||
return handleError($e, $this);
|
return handleError($e, $this);
|
||||||
}
|
}
|
||||||
|
@@ -28,6 +28,7 @@ class DiscordNotificationSettings extends Model
|
|||||||
'server_disk_usage_discord_notifications',
|
'server_disk_usage_discord_notifications',
|
||||||
'server_reachable_discord_notifications',
|
'server_reachable_discord_notifications',
|
||||||
'server_unreachable_discord_notifications',
|
'server_unreachable_discord_notifications',
|
||||||
|
'discord_ping_enabled',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
@@ -45,6 +46,7 @@ class DiscordNotificationSettings extends Model
|
|||||||
'server_disk_usage_discord_notifications' => 'boolean',
|
'server_disk_usage_discord_notifications' => 'boolean',
|
||||||
'server_reachable_discord_notifications' => 'boolean',
|
'server_reachable_discord_notifications' => 'boolean',
|
||||||
'server_unreachable_discord_notifications' => 'boolean',
|
'server_unreachable_discord_notifications' => 'boolean',
|
||||||
|
'discord_ping_enabled' => 'boolean',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function team()
|
public function team()
|
||||||
@@ -56,4 +58,9 @@ class DiscordNotificationSettings extends Model
|
|||||||
{
|
{
|
||||||
return $this->discord_enabled;
|
return $this->discord_enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isPingEnabled()
|
||||||
|
{
|
||||||
|
return $this->discord_ping_enabled;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,6 +20,10 @@ class DiscordChannel
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! $discordSettings->discord_ping_enabled) {
|
||||||
|
$message->isCritical = false;
|
||||||
|
}
|
||||||
|
|
||||||
SendMessageToDiscordJob::dispatch($message, $discordSettings->discord_webhook_url);
|
SendMessageToDiscordJob::dispatch($message, $discordSettings->discord_webhook_url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -22,7 +22,7 @@ class Test extends Notification implements ShouldQueue
|
|||||||
|
|
||||||
public $tries = 5;
|
public $tries = 5;
|
||||||
|
|
||||||
public function __construct(public ?string $emails = null, public ?string $channel = null)
|
public function __construct(public ?string $emails = null, public ?string $channel = null, public ?bool $ping = false)
|
||||||
{
|
{
|
||||||
$this->onQueue('high');
|
$this->onQueue('high');
|
||||||
}
|
}
|
||||||
@@ -68,6 +68,7 @@ class Test extends Notification implements ShouldQueue
|
|||||||
title: ':white_check_mark: Test Success',
|
title: ':white_check_mark: Test Success',
|
||||||
description: 'This is a test Discord notification from Coolify. :cross_mark: :warning: :information_source:',
|
description: 'This is a test Discord notification from Coolify. :cross_mark: :warning: :information_source:',
|
||||||
color: DiscordMessage::successColor(),
|
color: DiscordMessage::successColor(),
|
||||||
|
isCritical: $this->ping,
|
||||||
);
|
);
|
||||||
|
|
||||||
$message->addField(name: 'Dashboard', value: '[Link]('.base_url().')', inline: true);
|
$message->addField(name: 'Dashboard', value: '[Link]('.base_url().')', inline: true);
|
||||||
|
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('discord_notification_settings', function (Blueprint $table) {
|
||||||
|
$table->boolean('discord_ping_enabled')->default(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('discord_notification_settings', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('discord_ping_enabled');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
@@ -20,12 +20,15 @@
|
|||||||
</x-forms.button>
|
</x-forms.button>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
<div class="w-32">
|
<div class="w-48">
|
||||||
<x-forms.checkbox instantSave="instantSaveDiscordEnabled" id="discordEnabled" label="Enabled" />
|
<x-forms.checkbox instantSave="instantSaveDiscordEnabled" id="discordEnabled" label="Enabled" />
|
||||||
|
<x-forms.checkbox instantSave="instantSaveDiscordPingEnabled" id="discordPingEnabled"
|
||||||
|
helper="If enabled, a ping (@here) will be sent to the notification when a critical event happens."
|
||||||
|
label="Ping Enabled" />
|
||||||
</div>
|
</div>
|
||||||
<x-forms.input type="password"
|
<x-forms.input type="password"
|
||||||
helper="Create a Discord Server and generate a Webhook URL. <br><a class='inline-block underline dark:text-white' href='https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks' target='_blank'>Webhook Documentation</a>" required
|
helper="Create a Discord Server and generate a Webhook URL. <br><a class='inline-block underline dark:text-white' href='https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks' target='_blank'>Webhook Documentation</a>"
|
||||||
id="discordWebhookUrl" label="Webhook" />
|
required id="discordWebhookUrl" label="Webhook" />
|
||||||
</form>
|
</form>
|
||||||
<h2 class="mt-4">Notification Settings</h2>
|
<h2 class="mt-4">Notification Settings</h2>
|
||||||
<p class="mb-4">
|
<p class="mb-4">
|
||||||
|
Reference in New Issue
Block a user