diff --git a/overseerr-api.yml b/overseerr-api.yml index fc96da70b..0de788e0b 100644 --- a/overseerr-api.yml +++ b/overseerr-api.yml @@ -1102,6 +1102,10 @@ components: options: type: object properties: + botUsername: + type: string + botAvatarUrl: + type: string webhookUrl: type: string SlackSettings: @@ -1146,10 +1150,14 @@ components: options: type: object properties: + botUsername: + type: string botAPI: type: string chatId: type: string + sendSilently: + type: boolean PushbulletSettings: type: object properties: diff --git a/server/lib/notifications/agents/discord.ts b/server/lib/notifications/agents/discord.ts index fc6e5bbbf..0e695ebc7 100644 --- a/server/lib/notifications/agents/discord.ts +++ b/server/lib/notifications/agents/discord.ts @@ -71,7 +71,7 @@ interface DiscordRichEmbed { interface DiscordWebhookPayload { embeds: DiscordRichEmbed[]; - username: string; + username?: string; avatar_url?: string; tts: boolean; content?: string; @@ -203,8 +203,11 @@ class DiscordAgent ): Promise { logger.debug('Sending discord notification', { label: 'Notifications' }); try { - const settings = getSettings(); - const webhookUrl = this.getSettings().options.webhookUrl; + const { + botUsername, + botAvatarUrl, + webhookUrl, + } = this.getSettings().options; if (!webhookUrl) { return false; @@ -222,7 +225,8 @@ class DiscordAgent } await axios.post(webhookUrl, { - username: settings.main.applicationTitle, + username: botUsername, + avatar_url: botAvatarUrl, embeds: [this.buildEmbed(type, payload)], content, allowed_mentions: { diff --git a/server/lib/settings.ts b/server/lib/settings.ts index 6d3e9536b..9566f2124 100644 --- a/server/lib/settings.ts +++ b/server/lib/settings.ts @@ -95,6 +95,8 @@ export interface NotificationAgentConfig { } export interface NotificationAgentDiscord extends NotificationAgentConfig { options: { + botUsername?: string; + botAvatarUrl?: string; webhookUrl: string; }; } @@ -120,7 +122,7 @@ export interface NotificationAgentEmail extends NotificationAgentConfig { export interface NotificationAgentTelegram extends NotificationAgentConfig { options: { - botUsername: string; + botUsername?: string; botAPI: string; chatId: string; sendSilently: boolean; @@ -229,6 +231,8 @@ class Settings { enabled: false, types: 0, options: { + botUsername: '', + botAvatarUrl: '', webhookUrl: '', }, }, diff --git a/src/components/Settings/Notifications/NotificationsDiscord.tsx b/src/components/Settings/Notifications/NotificationsDiscord.tsx index fcd67943b..da80f1c5d 100644 --- a/src/components/Settings/Notifications/NotificationsDiscord.tsx +++ b/src/components/Settings/Notifications/NotificationsDiscord.tsx @@ -13,6 +13,8 @@ const messages = defineMessages({ save: 'Save Changes', saving: 'Saving…', agentenabled: 'Enable Agent', + botUsername: 'Bot Username', + botAvatarUrl: 'Bot Avatar URL', webhookUrl: 'Webhook URL', webhookUrlPlaceholder: 'Server Settings → Integrations → Webhooks', discordsettingssaved: 'Discord notification settings saved successfully!', @@ -20,7 +22,7 @@ const messages = defineMessages({ testsent: 'Test notification sent!', test: 'Test', notificationtypes: 'Notification Types', - validationWebhookUrl: 'You must provide a valid URL', + validationUrl: 'You must provide a valid URL', }); const NotificationsDiscord: React.FC = () => { @@ -31,9 +33,12 @@ const NotificationsDiscord: React.FC = () => { ); const NotificationsDiscordSchema = Yup.object().shape({ + botAvatarUrl: Yup.string() + .nullable() + .url(intl.formatMessage(messages.validationUrl)), webhookUrl: Yup.string() - .required(intl.formatMessage(messages.validationWebhookUrl)) - .url(intl.formatMessage(messages.validationWebhookUrl)), + .required(intl.formatMessage(messages.validationUrl)) + .url(intl.formatMessage(messages.validationUrl)), }); if (!data && !error) { @@ -45,6 +50,8 @@ const NotificationsDiscord: React.FC = () => { initialValues={{ enabled: data.enabled, types: data.types, + botUsername: data?.options.botUsername, + botAvatarUrl: data?.options.botAvatarUrl, webhookUrl: data.options.webhookUrl, }} validationSchema={NotificationsDiscordSchema} @@ -54,6 +61,8 @@ const NotificationsDiscord: React.FC = () => { enabled: values.enabled, types: values.types, options: { + botUsername: values.botUsername, + botAvatarUrl: values.botAvatarUrl, webhookUrl: values.webhookUrl, }, }); @@ -77,6 +86,8 @@ const NotificationsDiscord: React.FC = () => { enabled: true, types: values.types, options: { + botUsername: values.botUsername, + botAvatarUrl: values.botAvatarUrl, webhookUrl: values.webhookUrl, }, }); @@ -97,6 +108,42 @@ const NotificationsDiscord: React.FC = () => { +
+ +
+
+ +
+ {errors.botUsername && touched.botUsername && ( +
{errors.botUsername}
+ )} +
+
+
+ +
+
+ +
+ {errors.botAvatarUrl && touched.botAvatarUrl && ( +
{errors.botAvatarUrl}
+ )} +
+