Replace Discord webhook notifications with Matrix (hookshot)

- Add helpers/NotificationHelper.php: shared Matrix webhook sender
  that reads MATRIX_WEBHOOK_URL and MATRIX_NOTIFY_USERS from config
- Remove sendDiscordWebhook() from TicketController; call
  NotificationHelper::sendTicketNotification() instead
- Replace 60-line Discord embed block in create_ticket_api.php
  with a single NotificationHelper call
- config/config.php: DISCORD_WEBHOOK_URL → MATRIX_WEBHOOK_URL +
  new MATRIX_NOTIFY_USERS key (comma-separated Matrix user IDs)
- .env.example: updated env var names and comments

Payload sent to hookshot includes notify_users array so the
JS transform can build proper @mention links for each user.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-21 19:17:46 -05:00
parent 13f0fab138
commit f59913910f
5 changed files with 83 additions and 172 deletions

View File

@@ -227,66 +227,12 @@ if ($stmt->execute()) {
$stmt->close();
$conn->close();
// Discord webhook notification
if (isset($envVars['DISCORD_WEBHOOK_URL']) && !empty($envVars['DISCORD_WEBHOOK_URL'])) {
$discord_webhook_url = $envVars['DISCORD_WEBHOOK_URL'];
// Map priorities to Discord colors (decimal format)
$priorityColors = [
"1" => 0xDC3545, // P1 Critical - Red
"2" => 0xFD7E14, // P2 High - Orange
"3" => 0x0DCAF0, // P3 Medium - Cyan
"4" => 0x198754, // P4 Low - Green
"5" => 0x6C757D // P5 Info - Gray
];
// Priority labels for display
$priorityLabels = [
"1" => "P1 - Critical",
"2" => "P2 - High",
"3" => "P3 - Medium",
"4" => "P4 - Low",
"5" => "P5 - Info"
];
// Create ticket URL using validated host
$ticketUrl = UrlHelper::ticketUrl($ticket_id);
// Extract hostname from title for cleaner display
preg_match('/^\[([^\]]+)\]/', $title, $hostnameMatch);
$sourceHost = $hostnameMatch[1] ?? 'Unknown';
$discord_data = [
"embeds" => [[
"title" => "New Ticket Created",
"description" => "**#{$ticket_id}** - {$title}",
"url" => $ticketUrl,
"color" => $priorityColors[$priority] ?? 0x6C757D,
"fields" => [
["name" => "Priority", "value" => $priorityLabels[$priority] ?? "P{$priority}", "inline" => true],
["name" => "Category", "value" => $category, "inline" => true],
["name" => "Type", "value" => $type, "inline" => true],
["name" => "Status", "value" => $status, "inline" => true],
["name" => "Source", "value" => $sourceHost, "inline" => true]
],
"footer" => [
"text" => "Tinker Tickets | Automated Alert"
],
"timestamp" => date('c')
]]
];
$ch = curl_init($discord_webhook_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($discord_data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$webhookResult = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode !== 204 && $httpCode !== 200) {
error_log("Discord webhook failed for ticket #{$ticket_id}. HTTP Code: {$httpCode}");
}
}
// Matrix webhook notification
require_once __DIR__ . '/helpers/NotificationHelper.php';
NotificationHelper::sendTicketNotification($ticket_id, [
'title' => $title,
'priority' => $priority,
'category' => $category,
'type' => $type,
'status' => $status,
], 'automated');