Add Discord allowed mentions configuration
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user