diff --git a/cypress/config/settings.cypress.json b/cypress/config/settings.cypress.json index 45e38a29e..ff763ac7e 100644 --- a/cypress/config/settings.cypress.json +++ b/cypress/config/settings.cypress.json @@ -75,6 +75,7 @@ "types": 0, "options": { "webhookUrl": "", + "webhookRoleId": "", "enableMentions": true } }, diff --git a/docs/using-jellyseerr/notifications/discord.md b/docs/using-jellyseerr/notifications/discord.md index 016de30e2..b39e283a8 100644 --- a/docs/using-jellyseerr/notifications/discord.md +++ b/docs/using-jellyseerr/notifications/discord.md @@ -18,6 +18,10 @@ Users can optionally opt-in to being mentioned in Discord notifications by confi You can find the webhook URL in the Discord application, at **Server Settings → Integrations → Webhooks**. +### Notification Role ID (optional) + +If a role ID is specified, it will be included in the webhook message. See [Discord role ID](https://support.discord.com/hc/en-us/articles/206346498-Where-can-I-find-my-User-Server-Message-ID). + ### Bot Username (optional) If you would like to override the name you configured for your bot in Discord, you may set this value to whatever you like! diff --git a/overseerr-api.yml b/overseerr-api.yml index 9e2505f48..dfbbfd084 100644 --- a/overseerr-api.yml +++ b/overseerr-api.yml @@ -1273,6 +1273,8 @@ components: type: string webhookUrl: type: string + webhookRoleId: + type: string enableMentions: type: boolean SlackSettings: diff --git a/server/lib/notifications/agents/discord.ts b/server/lib/notifications/agents/discord.ts index e949e3e18..8eb1d99d3 100644 --- a/server/lib/notifications/agents/discord.ts +++ b/server/lib/notifications/agents/discord.ts @@ -291,6 +291,10 @@ class DiscordAgent } } + if (settings.options.webhookRoleId) { + userMentions.push(`<@&${settings.options.webhookRoleId}>`); + } + const response = await fetch(settings.options.webhookUrl, { method: 'POST', headers: { diff --git a/server/lib/settings/index.ts b/server/lib/settings/index.ts index 29447f534..425fc1389 100644 --- a/server/lib/settings/index.ts +++ b/server/lib/settings/index.ts @@ -170,6 +170,7 @@ export interface NotificationAgentDiscord extends NotificationAgentConfig { botUsername?: string; botAvatarUrl?: string; webhookUrl: string; + webhookRoleId?: string; enableMentions: boolean; }; } @@ -394,6 +395,7 @@ class Settings { types: 0, options: { webhookUrl: '', + webhookRoleId: '', enableMentions: true, }, }, diff --git a/src/components/Settings/Notifications/NotificationsDiscord.tsx b/src/components/Settings/Notifications/NotificationsDiscord.tsx index b62263fbc..82ac68403 100644 --- a/src/components/Settings/Notifications/NotificationsDiscord.tsx +++ b/src/components/Settings/Notifications/NotificationsDiscord.tsx @@ -19,12 +19,16 @@ const messages = defineMessages('components.Settings.Notifications', { webhookUrl: 'Webhook URL', webhookUrlTip: 'Create a webhook integration in your server', + webhookRoleId: 'Notification Role ID', + webhookRoleIdTip: + 'The role ID to mention in the webhook message. Leave empty to disable mentions', discordsettingssaved: 'Discord notification settings saved successfully!', discordsettingsfailed: 'Discord notification settings failed to save.', toastDiscordTestSending: 'Sending Discord test notification…', toastDiscordTestSuccess: 'Discord test notification sent!', toastDiscordTestFailed: 'Discord test notification failed to send.', validationUrl: 'You must provide a valid URL', + validationWebhookRoleId: 'You must provide a valid Discord Role ID', validationTypes: 'You must select at least one notification type', enableMentions: 'Enable Mentions', }); @@ -53,6 +57,12 @@ const NotificationsDiscord = () => { otherwise: Yup.string().nullable(), }) .url(intl.formatMessage(messages.validationUrl)), + webhookRoleId: Yup.string() + .nullable() + .matches( + /^\d{17,19}$/, + intl.formatMessage(messages.validationWebhookRoleId) + ), }); if (!data && !error) { @@ -67,6 +77,7 @@ const NotificationsDiscord = () => { botUsername: data?.options.botUsername, botAvatarUrl: data?.options.botAvatarUrl, webhookUrl: data.options.webhookUrl, + webhookRoleId: data?.options.webhookRoleId, enableMentions: data?.options.enableMentions, }} validationSchema={NotificationsDiscordSchema} @@ -84,6 +95,7 @@ const NotificationsDiscord = () => { botUsername: values.botUsername, botAvatarUrl: values.botAvatarUrl, webhookUrl: values.webhookUrl, + webhookRoleId: values.webhookRoleId, enableMentions: values.enableMentions, }, }), @@ -141,6 +153,7 @@ const NotificationsDiscord = () => { botUsername: values.botUsername, botAvatarUrl: values.botAvatarUrl, webhookUrl: values.webhookUrl, + webhookRoleId: values.webhookRoleId, enableMentions: values.enableMentions, }, }), @@ -254,6 +267,21 @@ const NotificationsDiscord = () => { )} +
+ +
+
+ +
+ {errors.webhookRoleId && + touched.webhookRoleId && + typeof errors.webhookRoleId === 'string' && ( +
{errors.webhookRoleId}
+ )} +
+