Add webhook formats and Google Chat support
Introduce selectable webhook payload formats and Google Chat rich-card support. NotificationGroupController now reads and validates a webhook_format option (generic, google_chat, simple_text) and logs a warning if Google Chat format is chosen but the URL does not look like chat.googleapis.com. WebhookChannel gains format constants, a payload builder (generic/simple text/Google Chat card), improved Content-Type header, enhanced logging with masked URLs, response truncation, payload previews, and better RequestException handling. Views updated to expose a Webhook Format dropdown, contextual help (including Google Chat setup instructions), dynamic placeholders/help text, and include the selected format when testing/saving webhooks. These changes add format flexibility and improve observability and safety when sending webhook notifications.
This commit is contained in:
@@ -591,7 +591,26 @@ class NotificationGroupController extends Controller
|
||||
if (!str_starts_with($webhookUrl, 'https://') && !str_starts_with($webhookUrl, 'http://')) {
|
||||
return null;
|
||||
}
|
||||
return ['webhook_url' => $webhookUrl];
|
||||
|
||||
$config = ['webhook_url' => $webhookUrl];
|
||||
|
||||
// Add format option (generic, google_chat, simple_text)
|
||||
$format = trim($data['webhook_format'] ?? 'generic');
|
||||
$validFormats = ['generic', 'google_chat', 'simple_text'];
|
||||
if (in_array($format, $validFormats)) {
|
||||
$config['format'] = $format;
|
||||
}
|
||||
|
||||
// Validate Google Chat webhook URL format if that format is selected
|
||||
if ($format === 'google_chat' && !str_contains($webhookUrl, 'chat.googleapis.com')) {
|
||||
// Allow it but log a warning - user might have a proxy
|
||||
$logger = new \App\Services\Logger();
|
||||
$logger->warning('Google Chat format selected but URL does not appear to be a Google Chat webhook', [
|
||||
'url' => $webhookUrl
|
||||
]);
|
||||
}
|
||||
|
||||
return $config;
|
||||
|
||||
default:
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user