pull/3326/merge
Jaden Grossman 2 weeks ago committed by GitHub
commit 3d8fa892b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -6,6 +6,7 @@ Overseerr currently supports the following notification agents:
- [Email](./email.md)
- [Web Push](./webpush.md)
- [Apprise](./apprise.md)
- [Discord](./discord.md)
- [Gotify](./gotify.md)
- [LunaSea](./lunasea.md)

@ -0,0 +1,7 @@
# Apprise
## Configuration
### Server URL
Set this to the URL of your Apprise server and configuration key. Usually something like http://localhost:8000/notify/apprise.

@ -1349,6 +1349,21 @@ components:
allowSelfSigned:
type: boolean
example: false
AppriseSettings:
type: object
properties:
enabled:
type: boolean
example: false
types:
type: number
example: 2
options:
type: object
properties:
url:
type: string
example: http://localhost:8000/notify/apprise
Job:
type: object
properties:
@ -3123,6 +3138,52 @@ paths:
responses:
'204':
description: Test notification attempted
/settings/notifications/apprise:
get:
summary: Get Apprise notification settings
description: Returns current Apprise notification settings in a JSON object.
tags:
- settings
responses:
'200':
description: Returned Apprise settings
content:
application/json:
schema:
$ref: '#/components/schemas/AppriseSettings'
post:
summary: Update Apprise notification settings
description: Update Apprise notification settings with the provided values.
tags:
- settings
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/AppriseSettings'
responses:
'200':
description: 'Values were sucessfully updated'
content:
application/json:
schema:
$ref: '#/components/schemas/AppriseSettings'
/settings/notifications/apprise/test:
post:
summary: Test Apprise settings
description: Sends a test notification to the Apprise agent.
tags:
- settings
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/AppriseSettings'
responses:
'204':
description: Test notification attempted
/settings/discover:
get:
summary: Get all discover sliders

@ -5,6 +5,7 @@ import { Session } from '@server/entity/Session';
import { User } from '@server/entity/User';
import { startJobs } from '@server/job/schedule';
import notificationManager from '@server/lib/notifications';
import AppriseAgent from '@server/lib/notifications/agents/apprise';
import DiscordAgent from '@server/lib/notifications/agents/discord';
import EmailAgent from '@server/lib/notifications/agents/email';
import GotifyAgent from '@server/lib/notifications/agents/gotify';
@ -82,6 +83,7 @@ app
// Register Notification Agents
notificationManager.registerAgents([
new AppriseAgent(),
new DiscordAgent(),
new EmailAgent(),
new GotifyAgent(),

@ -0,0 +1,147 @@
import { IssueStatus, IssueTypeName } from '@server/constants/issue';
import type { NotificationAgentApprise } from '@server/lib/settings';
import { getSettings } from '@server/lib/settings';
import logger from '@server/logger';
import axios from 'axios';
import { hasNotificationType, Notification } from '..';
import type { NotificationAgent, NotificationPayload } from './agent';
import { BaseAgent } from './agent';
interface ApprisePayload {
title: string;
body: string;
type: string;
}
class AppriseAgent
extends BaseAgent<NotificationAgentApprise>
implements NotificationAgent
{
protected getSettings(): NotificationAgentApprise {
if (this.settings) {
return this.settings;
}
const settings = getSettings();
return settings.notifications.agents.apprise;
}
public shouldSend(): boolean {
const settings = this.getSettings();
if (settings.enabled && settings.options.url) {
return true;
}
return false;
}
private getNotificationPayload(
type: Notification,
payload: NotificationPayload
): ApprisePayload {
const { applicationUrl, applicationTitle } = getSettings().main;
let notificationType = 'info';
const title = payload.event
? `${payload.event} - ${payload.subject}`
: payload.subject;
let body = payload.message ?? '';
if (payload.request) {
body += `\n\nRequested By: ${payload.request.requestedBy.displayName}`;
let status = '';
switch (type) {
case Notification.MEDIA_PENDING:
status = 'Pending Approval';
break;
case Notification.MEDIA_APPROVED:
case Notification.MEDIA_AUTO_APPROVED:
status = 'Processing';
break;
case Notification.MEDIA_AVAILABLE:
status = 'Available';
break;
case Notification.MEDIA_DECLINED:
status = 'Declined';
break;
case Notification.MEDIA_FAILED:
status = 'Failed';
break;
}
if (status) {
body += `\nRequest Status: ${status}`;
}
} else if (payload.comment) {
body += `\nComment from ${payload.comment.user.displayName}:\n${payload.comment.message}`;
} else if (payload.issue) {
body += `\n\nReported By: ${payload.issue.createdBy.displayName}`;
body += `\nIssue Type: ${IssueTypeName[payload.issue.issueType]}`;
body += `\nIssue Status: ${
payload.issue.status === IssueStatus.OPEN ? 'Open' : 'Resolved'
}`;
if (type == Notification.ISSUE_CREATED) {
notificationType = 'failure';
}
}
for (const extra of payload.extra ?? []) {
body += `\n\n**${extra.name}**\n${extra.value}`;
}
if (applicationUrl && payload.media) {
const actionUrl = `${applicationUrl}/${payload.media.mediaType}/${payload.media.tmdbId}`;
body += `\n\nOpen in ${applicationTitle}(${actionUrl})`;
}
return {
title,
body,
type: notificationType,
};
}
public async send(
type: Notification,
payload: NotificationPayload
): Promise<boolean> {
const settings = this.getSettings();
if (
!payload.notifySystem ||
!hasNotificationType(type, settings.types ?? 0)
) {
return true;
}
logger.debug('Sending Apprise notification', {
label: 'Notifications',
type: Notification[type],
subject: payload.subject,
});
try {
const endpoint = `${settings.options.url}`;
const notificationPayload = this.getNotificationPayload(type, payload);
await axios.post(endpoint, notificationPayload);
return true;
} catch (e) {
logger.error('Error sending Apprise notification', {
label: 'Notifications',
type: Notification[type],
subject: payload.subject,
errorMessage: e.message,
response: e.response?.data,
});
return false;
}
}
}
export default AppriseAgent;

@ -211,7 +211,14 @@ export interface NotificationAgentGotify extends NotificationAgentConfig {
};
}
export interface NotificationAgentApprise extends NotificationAgentConfig {
options: {
url: string;
};
}
export enum NotificationAgentKey {
APPRISE = 'apprise',
DISCORD = 'discord',
EMAIL = 'email',
GOTIFY = 'gotify',
@ -224,6 +231,7 @@ export enum NotificationAgentKey {
}
interface NotificationAgents {
apprise: NotificationAgentApprise;
discord: NotificationAgentDiscord;
email: NotificationAgentEmail;
gotify: NotificationAgentGotify;
@ -397,6 +405,13 @@ class Settings {
token: '',
},
},
apprise: {
enabled: false,
types: 0,
options: {
url: '',
},
},
},
},
jobs: {

@ -1,6 +1,7 @@
import type { User } from '@server/entity/User';
import { Notification } from '@server/lib/notifications';
import type { NotificationAgent } from '@server/lib/notifications/agents/agent';
import AppriseAgent from '@server/lib/notifications/agents/apprise';
import DiscordAgent from '@server/lib/notifications/agents/discord';
import EmailAgent from '@server/lib/notifications/agents/email';
import GotifyAgent from '@server/lib/notifications/agents/gotify';
@ -413,4 +414,38 @@ notificationRoutes.post('/gotify/test', async (req, res, next) => {
}
});
notificationRoutes.get('/apprise', (_req, res) => {
const settings = getSettings();
res.status(200).json(settings.notifications.agents.apprise);
});
notificationRoutes.post('/apprise', (req, res) => {
const settings = getSettings();
settings.notifications.agents.apprise = req.body;
settings.save();
res.status(200).json(settings.notifications.agents.apprise);
});
notificationRoutes.post('/apprise/test', async (req, res, next) => {
if (!req.user) {
return next({
status: 500,
message: 'User information is missing from the request.',
});
}
const appriseAgent = new AppriseAgent(req.body);
if (await sendTestNotification(appriseAgent, req.user)) {
return res.status(204).send();
} else {
return next({
status: 500,
message: 'Failed to send Apprise notification.',
});
}
});
export default notificationRoutes;

@ -0,0 +1 @@
<svg fill="#000000" viewBox="-192 -192 2304.00 2304.00" xmlns="http://www.w3.org/2000/svg" stroke="#000000"><g id="SVGRepo_bgCarrier" stroke-width="0"><rect x="-192" y="-192" width="2304.00" height="2304.00" rx="1152" fill="#ffffff" strokewidth="0"></rect></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <path d="M1587.162 31.278c11.52-23.491 37.27-35.689 63.473-29.816 25.525 6.099 43.483 28.8 43.483 55.002V570.46C1822.87 596.662 1920 710.733 1920 847.053c0 136.32-97.13 250.503-225.882 276.705v513.883c0 26.202-17.958 49.016-43.483 55.002a57.279 57.279 0 0 1-12.988 1.468c-21.12 0-40.772-11.745-50.485-31.171C1379.238 1247.203 964.18 1242.347 960 1242.347H564.706v564.706h87.755c-11.859-90.127-17.506-247.003 63.473-350.683 52.405-67.087 129.657-101.082 229.948-101.082v112.941c-64.49 0-110.57 18.861-140.837 57.487-68.781 87.868-45.064 263.83-30.269 324.254 4.18 16.828.34 34.673-10.277 48.34-10.73 13.665-27.219 21.684-44.499 21.684H508.235c-31.171 0-56.47-25.186-56.47-56.47v-621.177h-56.47c-155.747 0-282.354-126.607-282.354-282.353v-56.47h-56.47C25.299 903.523 0 878.336 0 847.052c0-31.172 25.299-56.471 56.47-56.471h56.471v-56.47c0-155.634 126.607-282.354 282.353-282.354h564.593c16.941-.112 420.48-7.002 627.275-420.48Zm-5.986 218.429c-194.71 242.371-452.216 298.164-564.705 311.04v572.724c112.489 12.876 369.995 68.556 564.705 311.04ZM903.53 564.7H395.294c-93.402 0-169.412 76.01-169.412 169.411v225.883c0 93.402 76.01 169.412 169.412 169.412H903.53V564.7Zm790.589 123.444v317.93c65.618-23.379 112.94-85.497 112.94-159.021 0-73.525-47.322-135.53-112.94-158.909Z" fill-rule="evenodd"></path> </g></svg>

After

Width:  |  Height:  |  Size: 1.6 KiB

@ -0,0 +1,234 @@
import Button from '@app/components/Common/Button';
import LoadingSpinner from '@app/components/Common/LoadingSpinner';
import NotificationTypeSelector from '@app/components/NotificationTypeSelector';
import globalMessages from '@app/i18n/globalMessages';
import { ArrowDownOnSquareIcon, BeakerIcon } from '@heroicons/react/24/solid';
import axios from 'axios';
import { Field, Form, Formik } from 'formik';
import { useState } from 'react';
import { defineMessages, useIntl } from 'react-intl';
import { useToasts } from 'react-toast-notifications';
import useSWR from 'swr';
import * as Yup from 'yup';
const messages = defineMessages({
agentenabled: 'Enable Agent',
url: 'Server URL',
validationUrlRequired: 'You must provide a valid URL',
validationUrlTrailingSlash: 'URL must not end in a trailing slash',
apprisesettingssaved: 'Apprise notification settings saved successfully!',
apprisesettingsfailed: 'Apprise notification settings failed to save.',
toastAppriseTestSending: 'Sending Apprise test notification…',
toastAppriseTestSuccess: 'Apprise test notification sent!',
toastAppriseTestFailed: 'Apprise test notification failed to send.',
validationTypes: 'You must select at least one notification type',
});
const NotificationsApprise = () => {
const intl = useIntl();
const { addToast, removeToast } = useToasts();
const [isTesting, setIsTesting] = useState(false);
const {
data,
error,
mutate: revalidate,
} = useSWR('/api/v1/settings/notifications/apprise');
const NotificationsAppriseSchema = Yup.object().shape({
url: Yup.string()
.when('enabled', {
is: true,
then: Yup.string()
.nullable()
.required(intl.formatMessage(messages.validationUrlRequired)),
otherwise: Yup.string().nullable(),
})
.matches(
// eslint-disable-next-line no-useless-escape
/^(https?:)?\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*)?([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i,
intl.formatMessage(messages.validationUrlRequired)
)
.test(
'no-trailing-slash',
intl.formatMessage(messages.validationUrlTrailingSlash),
(value) => !value || !value.endsWith('/')
),
});
if (!data && !error) {
return <LoadingSpinner />;
}
return (
<Formik
initialValues={{
enabled: data?.enabled,
types: data?.types,
url: data?.options.url,
}}
validationSchema={NotificationsAppriseSchema}
onSubmit={async (values) => {
try {
await axios.post('/api/v1/settings/notifications/apprise', {
enabled: values.enabled,
types: values.types,
options: {
url: values.url,
},
});
addToast(intl.formatMessage(messages.apprisesettingssaved), {
appearance: 'success',
autoDismiss: true,
});
} catch (e) {
addToast(intl.formatMessage(messages.apprisesettingsfailed), {
appearance: 'error',
autoDismiss: true,
});
} finally {
revalidate();
}
}}
>
{({
errors,
touched,
isSubmitting,
values,
isValid,
setFieldValue,
setFieldTouched,
}) => {
const testSettings = async () => {
setIsTesting(true);
let toastId: string | undefined;
try {
addToast(
intl.formatMessage(messages.toastAppriseTestSending),
{
autoDsmiss: false,
appearance: 'info',
},
(id) => {
toastId = id;
}
);
await axios.post('/api/v1/settings/notifications/apprise/test', {
enabled: true,
types: values.types,
options: {
url: values.url,
},
});
if (toastId) {
removeToast(toastId);
}
addToast(intl.formatMessage(messages.toastAppriseTestSuccess), {
autoDismiss: true,
appearance: 'success',
});
} catch (e) {
if (toastId) {
removeToast(toastId);
}
addToast(intl.formatMessage(messages.toastAppriseTestFailed), {
autoDismiss: true,
appearance: 'error',
});
} finally {
setIsTesting(false);
}
};
return (
<Form className="section">
<div className="form-row">
<label htmlFor="enabled" className="checkbox-label">
{intl.formatMessage(messages.agentenabled)}
<span className="label-required">*</span>
</label>
<div className="form-input-area">
<Field type="checkbox" id="enabled" name="enabled" />
</div>
</div>
<div className="form-row">
<label htmlFor="url" className="text-label">
{intl.formatMessage(messages.url)}
<span className="label-required">*</span>
</label>
<div className="form-input-area">
<div className="form-input-field">
<Field id="url" name="url" type="text" />
</div>
{errors.url &&
touched.url &&
typeof errors.url === 'string' && (
<div className="error">{errors.url}</div>
)}
</div>
</div>
<NotificationTypeSelector
currentTypes={values.enabled ? values.types : 0}
onUpdate={(newTypes) => {
setFieldValue('types', newTypes);
setFieldTouched('types');
if (newTypes) {
setFieldValue('enabled', true);
}
}}
error={
values.enabled && !values.types && touched.types
? intl.formatMessage(messages.validationTypes)
: undefined
}
/>
<div className="actions">
<div className="flex justify-end">
<span className="ml-3 inline-flex rounded-md shadow-sm">
<Button
buttonType="warning"
disabled={isSubmitting || !isValid || isTesting}
onClick={(e) => {
e.preventDefault();
testSettings();
}}
>
<BeakerIcon />
<span>
{isTesting
? intl.formatMessage(globalMessages.testing)
: intl.formatMessage(globalMessages.test)}
</span>
</Button>
</span>
<span className="ml-3 inline-flex rounded-md shadow-sm">
<Button
buttonType="primary"
type="submit"
disabled={
isSubmitting ||
!isValid ||
isTesting ||
(values.enabled && !values.types)
}
>
<ArrowDownOnSquareIcon />
<span>
{isSubmitting
? intl.formatMessage(globalMessages.saving)
: intl.formatMessage(globalMessages.save)}
</span>
</Button>
</span>
</div>
</div>
</Form>
);
}}
</Formik>
);
};
export default NotificationsApprise;

@ -1,3 +1,4 @@
import AppriseLogo from '@app/assets/extlogos/apprise.svg';
import DiscordLogo from '@app/assets/extlogos/discord.svg';
import GotifyLogo from '@app/assets/extlogos/gotify.svg';
import LunaSeaLogo from '@app/assets/extlogos/lunasea.svg';
@ -129,6 +130,17 @@ const SettingsNotifications = ({ children }: SettingsNotificationsProps) => {
route: '/settings/notifications/telegram',
regex: /^\/settings\/notifications\/telegram/,
},
{
text: 'Apprise',
content: (
<span className="flex items-center">
<AppriseLogo className="mr-2 h-4" />
Apprise
</span>
),
route: '/settings/notifications/apprise',
regex: /^\/settings\/notifications\/apprise/,
},
{
text: intl.formatMessage(messages.webhook),
content: (

@ -520,6 +520,16 @@
"components.Selector.showless": "Show Less",
"components.Selector.showmore": "Show More",
"components.Selector.starttyping": "Starting typing to search.",
"components.Settings.Notifications.NotificationsApprise.agentenabled": "Enable Agent",
"components.Settings.Notifications.NotificationsApprise.apprisesettingsfailed": "Apprise notification settings failed to save.",
"components.Settings.Notifications.NotificationsApprise.apprisesettingssaved": "Apprise notification settings saved successfully!",
"components.Settings.Notifications.NotificationsApprise.toastAppriseTestFailed": "Apprise test notification failed to send.",
"components.Settings.Notifications.NotificationsApprise.toastAppriseTestSending": "Sending Apprise test notification…",
"components.Settings.Notifications.NotificationsApprise.toastAppriseTestSuccess": "Apprise test notification sent!",
"components.Settings.Notifications.NotificationsApprise.url": "Server URL",
"components.Settings.Notifications.NotificationsApprise.validationTypes": "You must select at least one notification type",
"components.Settings.Notifications.NotificationsApprise.validationUrlRequired": "You must provide a valid URL",
"components.Settings.Notifications.NotificationsApprise.validationUrlTrailingSlash": "URL must not end in a trailing slash",
"components.Settings.Notifications.NotificationsGotify.agentenabled": "Enable Agent",
"components.Settings.Notifications.NotificationsGotify.gotifysettingsfailed": "Gotify notification settings failed to save.",
"components.Settings.Notifications.NotificationsGotify.gotifysettingssaved": "Gotify notification settings saved successfully!",

@ -0,0 +1,19 @@
import NotificationsApprise from '@app/components/Settings/Notifications/NotificationsApprise';
import SettingsLayout from '@app/components/Settings/SettingsLayout';
import SettingsNotifications from '@app/components/Settings/SettingsNotifications';
import useRouteGuard from '@app/hooks/useRouteGuard';
import { Permission } from '@app/hooks/useUser';
import type { NextPage } from 'next';
const NotificationsPage: NextPage = () => {
useRouteGuard(Permission.ADMIN);
return (
<SettingsLayout>
<SettingsNotifications>
<NotificationsApprise />
</SettingsNotifications>
</SettingsLayout>
);
};
export default NotificationsPage;
Loading…
Cancel
Save