feat(notifications): improve discord notifications (#1102)

* feat: improve discord notifications

Added a field in the general notification settings to allow a role to be mentioned in the webhook
message via discord notification agent

* feat: add discord role id notification - locales
This commit is contained in:
Guillaume ARNOUX
2024-11-15 18:38:23 +01:00
committed by GitHub
parent ba84212e68
commit 5c24e79b1d
7 changed files with 45 additions and 1 deletions

View File

@@ -75,6 +75,7 @@
"types": 0, "types": 0,
"options": { "options": {
"webhookUrl": "", "webhookUrl": "",
"webhookRoleId": "",
"enableMentions": true "enableMentions": true
} }
}, },

View File

@@ -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**. 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) ### 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! If you would like to override the name you configured for your bot in Discord, you may set this value to whatever you like!

View File

@@ -1273,6 +1273,8 @@ components:
type: string type: string
webhookUrl: webhookUrl:
type: string type: string
webhookRoleId:
type: string
enableMentions: enableMentions:
type: boolean type: boolean
SlackSettings: SlackSettings:

View File

@@ -291,6 +291,10 @@ class DiscordAgent
} }
} }
if (settings.options.webhookRoleId) {
userMentions.push(`<@&${settings.options.webhookRoleId}>`);
}
const response = await fetch(settings.options.webhookUrl, { const response = await fetch(settings.options.webhookUrl, {
method: 'POST', method: 'POST',
headers: { headers: {

View File

@@ -170,6 +170,7 @@ export interface NotificationAgentDiscord extends NotificationAgentConfig {
botUsername?: string; botUsername?: string;
botAvatarUrl?: string; botAvatarUrl?: string;
webhookUrl: string; webhookUrl: string;
webhookRoleId?: string;
enableMentions: boolean; enableMentions: boolean;
}; };
} }
@@ -394,6 +395,7 @@ class Settings {
types: 0, types: 0,
options: { options: {
webhookUrl: '', webhookUrl: '',
webhookRoleId: '',
enableMentions: true, enableMentions: true,
}, },
}, },

View File

@@ -19,12 +19,16 @@ const messages = defineMessages('components.Settings.Notifications', {
webhookUrl: 'Webhook URL', webhookUrl: 'Webhook URL',
webhookUrlTip: webhookUrlTip:
'Create a <DiscordWebhookLink>webhook integration</DiscordWebhookLink> in your server', 'Create a <DiscordWebhookLink>webhook integration</DiscordWebhookLink> 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!', discordsettingssaved: 'Discord notification settings saved successfully!',
discordsettingsfailed: 'Discord notification settings failed to save.', discordsettingsfailed: 'Discord notification settings failed to save.',
toastDiscordTestSending: 'Sending Discord test notification…', toastDiscordTestSending: 'Sending Discord test notification…',
toastDiscordTestSuccess: 'Discord test notification sent!', toastDiscordTestSuccess: 'Discord test notification sent!',
toastDiscordTestFailed: 'Discord test notification failed to send.', toastDiscordTestFailed: 'Discord test notification failed to send.',
validationUrl: 'You must provide a valid URL', 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', validationTypes: 'You must select at least one notification type',
enableMentions: 'Enable Mentions', enableMentions: 'Enable Mentions',
}); });
@@ -53,6 +57,12 @@ const NotificationsDiscord = () => {
otherwise: Yup.string().nullable(), otherwise: Yup.string().nullable(),
}) })
.url(intl.formatMessage(messages.validationUrl)), .url(intl.formatMessage(messages.validationUrl)),
webhookRoleId: Yup.string()
.nullable()
.matches(
/^\d{17,19}$/,
intl.formatMessage(messages.validationWebhookRoleId)
),
}); });
if (!data && !error) { if (!data && !error) {
@@ -67,6 +77,7 @@ const NotificationsDiscord = () => {
botUsername: data?.options.botUsername, botUsername: data?.options.botUsername,
botAvatarUrl: data?.options.botAvatarUrl, botAvatarUrl: data?.options.botAvatarUrl,
webhookUrl: data.options.webhookUrl, webhookUrl: data.options.webhookUrl,
webhookRoleId: data?.options.webhookRoleId,
enableMentions: data?.options.enableMentions, enableMentions: data?.options.enableMentions,
}} }}
validationSchema={NotificationsDiscordSchema} validationSchema={NotificationsDiscordSchema}
@@ -84,6 +95,7 @@ const NotificationsDiscord = () => {
botUsername: values.botUsername, botUsername: values.botUsername,
botAvatarUrl: values.botAvatarUrl, botAvatarUrl: values.botAvatarUrl,
webhookUrl: values.webhookUrl, webhookUrl: values.webhookUrl,
webhookRoleId: values.webhookRoleId,
enableMentions: values.enableMentions, enableMentions: values.enableMentions,
}, },
}), }),
@@ -141,6 +153,7 @@ const NotificationsDiscord = () => {
botUsername: values.botUsername, botUsername: values.botUsername,
botAvatarUrl: values.botAvatarUrl, botAvatarUrl: values.botAvatarUrl,
webhookUrl: values.webhookUrl, webhookUrl: values.webhookUrl,
webhookRoleId: values.webhookRoleId,
enableMentions: values.enableMentions, enableMentions: values.enableMentions,
}, },
}), }),
@@ -254,6 +267,21 @@ const NotificationsDiscord = () => {
)} )}
</div> </div>
</div> </div>
<div className="form-row">
<label htmlFor="webhookRoleId" className="text-label">
{intl.formatMessage(messages.webhookRoleId)}
</label>
<div className="form-input-area">
<div className="form-input-field">
<Field id="webhookRoleId" name="webhookRoleId" type="text" />
</div>
{errors.webhookRoleId &&
touched.webhookRoleId &&
typeof errors.webhookRoleId === 'string' && (
<div className="error">{errors.webhookRoleId}</div>
)}
</div>
</div>
<div className="form-row"> <div className="form-row">
<label htmlFor="enableMentions" className="checkbox-label"> <label htmlFor="enableMentions" className="checkbox-label">
{intl.formatMessage(messages.enableMentions)} {intl.formatMessage(messages.enableMentions)}

View File

@@ -727,6 +727,9 @@
"components.Settings.Notifications.validationSmtpPortRequired": "You must provide a valid port number", "components.Settings.Notifications.validationSmtpPortRequired": "You must provide a valid port number",
"components.Settings.Notifications.validationTypes": "You must select at least one notification type", "components.Settings.Notifications.validationTypes": "You must select at least one notification type",
"components.Settings.Notifications.validationUrl": "You must provide a valid URL", "components.Settings.Notifications.validationUrl": "You must provide a valid URL",
"components.Settings.Notifications.validationWebhookRoleId": "You must provide a valid Discord Role ID",
"components.Settings.Notifications.webhookRoleId": "Notification Role ID",
"components.Settings.Notifications.webhookRoleIdTip": "The role ID to mention in the webhook message. Leave empty to disable mentions",
"components.Settings.Notifications.webhookUrl": "Webhook URL", "components.Settings.Notifications.webhookUrl": "Webhook URL",
"components.Settings.Notifications.webhookUrlTip": "Create a <DiscordWebhookLink>webhook integration</DiscordWebhookLink> in your server", "components.Settings.Notifications.webhookUrlTip": "Create a <DiscordWebhookLink>webhook integration</DiscordWebhookLink> in your server",
"components.Settings.RadarrModal.add": "Add Server", "components.Settings.RadarrModal.add": "Add Server",
@@ -1094,7 +1097,7 @@
"components.Setup.finishing": "Finishing…", "components.Setup.finishing": "Finishing…",
"components.Setup.servertype": "Choose Server Type", "components.Setup.servertype": "Choose Server Type",
"components.Setup.setup": "Setup", "components.Setup.setup": "Setup",
"components.Setup.signin": "Sign in to your account", "components.Setup.signin": "Sign In",
"components.Setup.signinMessage": "Get started by signing in", "components.Setup.signinMessage": "Get started by signing in",
"components.Setup.signinWithEmby": "Enter your Emby details", "components.Setup.signinWithEmby": "Enter your Emby details",
"components.Setup.signinWithJellyfin": "Enter your Jellyfin details", "components.Setup.signinWithJellyfin": "Enter your Jellyfin details",