Fixed Discord issue

Enhanced error messages for missing channel configuration fields in NotificationGroupController. Updated Discord and Slack webhook input handling to use distinct field names, improved form validation and required field logic in the edit group view, and added user guidance for webhook URLs.
This commit is contained in:
Hosteroid
2025-10-09 16:38:52 +03:00
parent 5d541e8021
commit adc28b97f0
2 changed files with 114 additions and 16 deletions

View File

@@ -131,7 +131,21 @@ class NotificationGroupController extends Controller
$config = $this->buildChannelConfig($channelType, $_POST);
if (!$config) {
$_SESSION['error'] = 'Invalid channel configuration';
$missingField = '';
switch ($channelType) {
case 'email':
$missingField = 'email address';
break;
case 'telegram':
$missingField = empty($_POST['bot_token']) ? 'bot token' : 'chat ID';
break;
case 'discord':
case 'slack':
$missingField = 'webhook URL';
break;
}
$_SESSION['error'] = "Invalid channel configuration: Missing {$missingField}";
$this->redirect("/groups/edit?id=$groupId");
return;
}
@@ -179,12 +193,14 @@ class NotificationGroupController extends Controller
];
case 'discord':
if (empty($data['webhook_url'])) return null;
return ['webhook_url' => $data['webhook_url']];
$webhookUrl = $data['discord_webhook_url'] ?? '';
if (empty($webhookUrl)) return null;
return ['webhook_url' => $webhookUrl];
case 'slack':
if (empty($data['webhook_url'])) return null;
return ['webhook_url' => $data['webhook_url']];
$webhookUrl = $data['slack_webhook_url'] ?? '';
if (empty($webhookUrl)) return null;
return ['webhook_url' => $webhookUrl];
default:
return null;