Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

feat: implement actual webhook delivery

Andras Bacsai413dee5d8c97
diff --git a/app/Jobs/SendWebhookJob.php b/app/Jobs/SendWebhookJob.php
new file mode 100644
index 0000000000..865dd94935
--- /dev/null
+++ b/app/Jobs/SendWebhookJob.php
@@ -0,0 +1,45 @@
+<?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;
+
+class SendWebhookJob implements ShouldBeEncrypted, ShouldQueue
+{
+ use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+
+ /**
+ * The number of times the job may be attempted.
+ *
+ * @var int
+ */
+ public $tries = 5;
+
+ public $backoff = 10;
+
+ /**
+ * The maximum number of unhandled exceptions to allow before failing.
+ */
+ public int $maxExceptions = 5;
+
+ public function __construct(
+ public array $payload,
+ public string $webhookUrl
+ ) {
+ $this->onQueue('high');
+ }
+
+ /**
+ * Execute the job.
+ */
+ public function handle(): void
+ {
+ Http::post($this->webhookUrl, $this->payload);
+ }
+}
diff --git a/app/Notifications/Channels/WebhookChannel.php b/app/Notifications/Channels/WebhookChannel.php
index 53524e4f54..757e5e934a 100644
--- a/app/Notifications/Channels/WebhookChannel.php
+++ b/app/Notifications/Channels/WebhookChannel.php
@@ -2,8 +2,8 @@
namespace App\Notifications\Channels;
+use App\Jobs\SendWebhookJob;
use Illuminate\Notifications\Notification;
-use Illuminate\Support\Facades\Log;
class WebhookChannel
{
@@ -18,16 +18,8 @@ class WebhookChannel
return;
}
- // TODO: Implement actual webhook delivery
- // This is a placeholder implementation
- // You'll need to:
- // 1. Get the webhook payload from $notification->toWebhook()
- // 2. Create a job to send the HTTP POST request to $webhookSettings->webhook_url
- // 3. Handle retries and errors appropriately
+ $payload = $notification->toWebhook();
- Log::info('Webhook notification would be sent', [
- 'url' => $webhookSettings->webhook_url,
- 'notification' => get_class($notification),
- ]);
+ SendWebhookJob::dispatch($payload, $webhookSettings->webhook_url);
}
}
diff --git a/app/Notifications/Test.php b/app/Notifications/Test.php
index 5a635a601d..60bc8a0ee5 100644
--- a/app/Notifications/Test.php
+++ b/app/Notifications/Test.php
@@ -116,8 +116,9 @@ class Test extends Notification implements ShouldQueue
public function toWebhook(): array
{
return [
- 'event' => 'test',
+ 'success' => true,
'message' => 'This is a test webhook notification from Coolify.',
+ 'event' => 'test',
'url' => base_url(),
];
}