feat: implement actual webhook delivery
Implement full webhook delivery functionality:
- Create SendWebhookJob to handle HTTP POST requests
- Update WebhookChannel to dispatch webhook jobs
- Configure retry logic (5 attempts, 10s backoff)
- Update Test notification payload with success/message structure
Webhook payload structure:
{
"success": true/false,
"message": "notification message",
"event": "event_type",
"url": "coolify_dashboard_url"
}
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
729c891542
commit
413dee5d8c
3 changed files with 50 additions and 12 deletions
45
app/Jobs/SendWebhookJob.php
Normal file
45
app/Jobs/SendWebhookJob.php
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
namespace App\Notifications\Channels;
|
namespace App\Notifications\Channels;
|
||||||
|
|
||||||
|
use App\Jobs\SendWebhookJob;
|
||||||
use Illuminate\Notifications\Notification;
|
use Illuminate\Notifications\Notification;
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
|
|
||||||
class WebhookChannel
|
class WebhookChannel
|
||||||
{
|
{
|
||||||
|
|
@ -18,16 +18,8 @@ public function send(SendsWebhook $notifiable, Notification $notification): void
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement actual webhook delivery
|
$payload = $notification->toWebhook();
|
||||||
// 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
|
|
||||||
|
|
||||||
Log::info('Webhook notification would be sent', [
|
SendWebhookJob::dispatch($payload, $webhookSettings->webhook_url);
|
||||||
'url' => $webhookSettings->webhook_url,
|
|
||||||
'notification' => get_class($notification),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -116,8 +116,9 @@ public function toSlack(): SlackMessage
|
||||||
public function toWebhook(): array
|
public function toWebhook(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'event' => 'test',
|
'success' => true,
|
||||||
'message' => 'This is a test webhook notification from Coolify.',
|
'message' => 'This is a test webhook notification from Coolify.',
|
||||||
|
'event' => 'test',
|
||||||
'url' => base_url(),
|
'url' => base_url(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue