Created
February 19, 2025 10:29
-
-
Save stefanpejcic/87e306f452db9c3a664c2927c93f1204 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!defined('WHMCS')) { | |
die('You cannot access this file directly.'); | |
} | |
add_hook('TicketOpen', 1, function ($vars) { | |
// Your Discord webhook URL | |
$discordWebhookUrl = "PUT_HERE"; | |
// Extract ticket information | |
$ticketId = $vars['ticketid']; | |
$deptId = $vars['deptid']; | |
$userId = $vars['userid']; | |
$subject = $vars['subject']; | |
$message = $vars['message']; | |
// WHMCS Admin Panel Ticket URL | |
$ticketUrl = "https://WHMCS_ADDRESS/admin/supporttickets.php?action=view&id=$ticketId"; | |
// Format the message with a clickable link | |
$discordMessage = [ | |
"content" => "**NEW TICKET:** [{$subject}]({$ticketUrl})\n\n> " . str_replace("\n", "\n> ", $message) | |
]; | |
// Initialize cURL | |
$ch = curl_init($discordWebhookUrl); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($discordMessage)); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
// Execute cURL request | |
$response = curl_exec($ch); | |
$curlError = curl_error($ch); | |
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
curl_close($ch); | |
// Log request and response | |
$logFile = __DIR__ . '/discord_webhook_log.txt'; | |
$logData = "[" . date('Y-m-d H:i:s') . "]\n"; | |
$logData .= "Sent Data: " . json_encode($discordMessage, JSON_PRETTY_PRINT) . "\n"; | |
$logData .= "Response: $response\n"; | |
$logData .= "HTTP Code: $httpCode\n"; | |
$logData .= "cURL Error: $curlError\n"; | |
$logData .= "--------------------------------------\n"; | |
file_put_contents($logFile, $logData, FILE_APPEND); | |
return $response; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment