Add Discord allowed mentions configuration

This commit is contained in:
2026-04-24 17:01:34 +00:00
parent 9958db10b9
commit 55db0ac642
6 changed files with 300 additions and 1 deletions
@@ -21,6 +21,11 @@ class DeliverNotificationAction implements ShouldQueue
private const int DISCORD_CONTENT_LIMIT = 2000;
/**
* @var list<string>
*/
private const array DISCORD_ALLOWED_MENTION_TYPES = ['everyone', 'roles', 'users'];
public int $tries = 3;
public int $timeout = 15;
@@ -280,11 +285,53 @@ class DeliverNotificationAction implements ShouldQueue
->post($notificationAction->delivery_url, [
'content' => $message,
'allowed_mentions' => [
'parse' => [],
'parse' => $this->discordAllowedMentions($notificationAction),
],
]);
}
/**
* @return list<string>
*/
private function discordAllowedMentions(NotificationAction $notificationAction): array
{
$configuredAllowedMentions = data_get(
$notificationAction->channel_configuration,
'allowed_mentions',
[],
);
if (! is_array($configuredAllowedMentions)) {
return [];
}
$allowedMentions = [];
foreach ($configuredAllowedMentions as $allowedMention) {
if (! is_string($allowedMention)) {
continue;
}
$allowedMention = Str::lower(trim($allowedMention));
if ($allowedMention === '') {
continue;
}
if (! in_array($allowedMention, self::DISCORD_ALLOWED_MENTION_TYPES, true)) {
continue;
}
if (in_array($allowedMention, $allowedMentions, true)) {
continue;
}
$allowedMentions[] = $allowedMention;
}
return $allowedMentions;
}
private function sendWebhookRequest(NotificationAction $notificationAction): Response
{
return Http::acceptJson()