Add generic webhook notification channel

Introduces a new 'Webhook (Custom)' notification channel allowing users to send JSON payloads to any HTTP endpoint (e.g., n8n, Zapier, custom APIs). Updates the UI to support webhook configuration, adds backend validation, and implements the WebhookChannel for sending notifications. Documentation is updated with usage instructions and payload examples.
This commit is contained in:
Hosteroid
2025-10-17 11:13:25 +03:00
parent 6e8fef9b79
commit 2b783b7470
6 changed files with 219 additions and 82 deletions

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Services\Channels;
use GuzzleHttp\Client;
class WebhookChannel implements NotificationChannelInterface
{
private Client $httpClient;
public function __construct()
{
$this->httpClient = new Client(['timeout' => 10]);
}
public function send(array $config, string $message, array $data = []): bool
{
$url = trim($config['webhook_url'] ?? '');
if (empty($url)) {
return false;
}
// Build a sane, generic JSON payload for automation tools (n8n, Zapier, etc.)
$payload = [
'event' => 'domain_expiration_alert',
'message' => $message,
'data' => $data,
'sent_at' => date('c')
];
try {
$response = $this->httpClient->post($url, [
'headers' => [
'Content-Type' => 'application/json'
],
'json' => $payload
]);
$status = $response->getStatusCode();
return $status >= 200 && $status < 300;
} catch (\Exception $e) {
error_log('Webhook send failed: ' . $e->getMessage());
return false;
}
}
}