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:
48
app/Services/Channels/WebhookChannel.php
Normal file
48
app/Services/Channels/WebhookChannel.php
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user